Skip to main content
Databases are a foundational part of agent engineering. Add a database to your agent and you get persistent storage for sessions, context, memory, learnings, and evaluation datasets.
  • Chat history. Include previous messages in context for multi-turn conversations.
  • Session persistence. Store session information and conversation history across requests.
  • State management. Store internal agent state across runs. Critical for planning agents.
  • Context control. Summarize, compress, enrich, and prune context for better responses.
  • Memory and knowledge. Store user-level facts, searchable knowledge, decision traces, and learned insights.
  • Tracing and evaluation. Store detailed traces for debugging, monitoring, and building evaluation datasets.
  • Data ownership. No third-party dependencies. Query your own database. Build evaluation datasets, extract few-shot examples, flag low-quality responses for review.
This is how good software is built. Agents are no different.

Quick Start

from agno.agent import Agent
from agno.db.sqlite import SqliteDb

agent = Agent(
    db=SqliteDb(db_file="agent.db"),
    add_history_to_context=True,
    num_history_runs=3,
)

# First message
agent.print_response("I'm working on a Python API project", session_id="dev_session")

# Later — agent remembers the context
agent.print_response("What testing framework should I use?", session_id="dev_session")
The agent now persists sessions and includes the last 3 runs in every request. Database storage overview

Guides

Works With Teams and Workflows

Storage works identically across Agents, Teams, and Workflows:
from agno.team import Team
from agno.workflow import Workflow
from agno.db.postgres import PostgresDb

db = PostgresDb(db_url="postgresql://user:pass@localhost:5432/mydb")

team = Team(db=db, ...)
workflow = Workflow(db=db, ...)

Supported Databases

Agno supports 13+ databases for session storage. Use SQLite for development, PostgreSQL for production. View all supported databases.

Async Support

For async applications, use the async database classes:
from agno.agent import Agent
from agno.db.postgres import AsyncPostgresDb

agent = Agent(
    db=AsyncPostgresDb(db_url="postgresql+psycopg_async://..."),
)

Troubleshooting

You’re using a synchronous engine with an async database class. Use create_async_engine from sqlalchemy.ext.asyncio.
You’re using an async engine with a synchronous database class. Use create_engine from sqlalchemy.