> For the complete documentation index, see [llms.txt](https://aita-1.gitbook.io/aita/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aita-1.gitbook.io/aita/reference/agent/sql.md).

# SqlAgent

The SqlAgent can be used to ask questions in natural language and interact with SQL databases.

## Example

Pass Data Source to SqlAgent and analyze the data.

{% code title="python" %}

```
```

{% endcode %}

```python
from aita.agent.sql import SqlAgent
from aita.datasource.postgresql import PostgreSqlDataSource
from aita.prompt.base import BasicContextPromptTemplate

postgres_datasource = PostgreSqlDataSource("postgresql://localhost:5432/db")
sql_agent = SqlAgent("gpt-3.5-turbo")
.set_context_prompt(BasicContextPromptTemplate)
.add_datasource(postgres_datasource)
sql_agent.stream("Get the top 10 customers by purchase amount")
```

{% endcode}
