# Async SQLite for Agent (/database/providers/async-sqlite/usage/async-sqlite-for-agent)



`AsyncSqliteDb` stores an Agent's sessions and run history asynchronously in SQLite. Use async Agent methods such as `arun()` and `aprint_response()`.

## Usage [#usage]

Install the `sqlalchemy` asyncio extra, `aiosqlite`, `openai`, and `ddgs`:

```shell
uv pip install "sqlalchemy[asyncio]" aiosqlite openai ddgs
```

`AsyncSqliteDb` uses an async `db_engine`, then `db_url`, then `db_file`. A `db_url` must use an async driver such as `sqlite+aiosqlite`. If none is provided, it creates `agno.db` in the current directory.

```python async_sqlite_for_agent.py
import asyncio

from agno.agent import Agent
from agno.db.sqlite import AsyncSqliteDb
from agno.tools.websearch import WebSearchTools

db = AsyncSqliteDb(db_file="tmp/data.db")

agent = Agent(
    db=db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
    add_datetime_to_context=True,
)


async def main():
    try:
        await agent.aprint_response("How many people live in Canada?")
        await agent.aprint_response("What is their national anthem called?")
    finally:
        await db.close()


if __name__ == "__main__":
    asyncio.run(main())
```

## Parameters [#parameters]

| Parameter                | Type                    | Default | Description                                                                                                                                     |
| ------------------------ | ----------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                     | `Optional[str]`         | -       | The ID of the database instance. UUID by default.                                                                                               |
| `db_engine`              | `Optional[AsyncEngine]` | -       | The SQLAlchemy async database engine to use.                                                                                                    |
| `db_url`                 | `Optional[str]`         | -       | The database URL to connect to.                                                                                                                 |
| `db_file`                | `Optional[str]`         | -       | The database file to connect to.                                                                                                                |
| `session_table`          | `Optional[str]`         | -       | Name of the table to store Agent, Team and Workflow sessions.                                                                                   |
| `runs_table`             | `Optional[str]`         | `None`  | Storage name for individual runs. Defaults to `agno_runs`, or `<session_table>_runs` when a custom session name is supplied.                    |
| `memory_table`           | `Optional[str]`         | -       | Name of the table to store user memories.                                                                                                       |
| `metrics_table`          | `Optional[str]`         | -       | Name of the table to store metrics.                                                                                                             |
| `eval_table`             | `Optional[str]`         | -       | Name of the table to store evaluation runs data.                                                                                                |
| `knowledge_table`        | `Optional[str]`         | -       | Name of the table to store knowledge documents data.                                                                                            |
| `traces_table`           | `Optional[str]`         | -       | Name of the table to store traces.                                                                                                              |
| `spans_table`            | `Optional[str]`         | -       | Name of the table to store spans.                                                                                                               |
| `versions_table`         | `Optional[str]`         | -       | Name of the table to store schema versions.                                                                                                     |
| `components_table`       | `Optional[str]`         | `None`  | Components table name for migration compatibility (defaults to `agno_components`). Async adapters do not yet support component reads or writes. |
| `learnings_table`        | `Optional[str]`         | -       | Name of the table to store learnings.                                                                                                           |
| `schedules_table`        | `Optional[str]`         | -       | Name of the table to store cron schedules.                                                                                                      |
| `schedule_runs_table`    | `Optional[str]`         | -       | Name of the table to store schedule run history.                                                                                                |
| `approvals_table`        | `Optional[str]`         | -       | Name of the table to store human approval requests.                                                                                             |
| `auth_tokens_table`      | `Optional[str]`         | -       | Name of the table to store OAuth tokens for external services.                                                                                  |
| `service_accounts_table` | `Optional[str]`         | -       | Name of the table to store service accounts.                                                                                                    |
