Skip to main content
Adding a database to your Agents adds persistence, allowing them to remember previous messages, user memories, and more. It works by equipping your Agents and Teams with a database that is used to store and retrieve:
Culture is an experimental feature.
Team structure

Adding a database to your Agent

To enable session persistence on your Agent, create a database and provide it to the Agent:
from agno.agent import Agent
from agno.db.sqlite import SQLiteDb

# Set up your database
db = SQLiteDb(id="my_agent_db", db_file="agno.db")

# Initialize your Agent passing the database
agent = Agent(db=db)
It’s recommended to add an id for better management and easier identification of your database. You can add it to your database configuration like this:
When should I use Storage on my Agents?Agents are ephemeral by default. They won’t remember previous conversations.But in production environments, you will often need to continue the same session across multiple requests. Storage is the way to persist the session history and state in a database, enabling you and your users to pick up where you left off.Storage also lets us inspect and evaluate Agent sessions, extract few-shot examples and build internal monitoring tools. In general, it lets you keep track of the data, to build better Agents.

Adding session history to the context

Agents backed by a database persist their sessions to it. You can then load this persisted history into the context to maintain continuity across sessions.
from agno.agent import Agent
from agno.db.sqlite import SQLiteDb

# Setup your database
db = SQLiteDb(db_file="agno.db")

# Setup your Agent with the database and add the session history to the context
agent = Agent(
    db=db,
    add_history_to_context=True, # Automatically add the persisted session history to the context
    num_history_runs=3, # Specify how many messages to add to the context
)

Where are sessions stored?

By default, sessions are stored in the agno_sessions table of the database. If the table or collection doesn’t exist, it is created automatically when first storing a session. You can specify where the sessions are stored exactly using the session_table parameter:
from agno.agent import Agent
from agno.db.postgres import PostgresDb

# Setup your database
db = PostgresDb(
    db_url="postgresql://user:password@localhost:5432/my_database",
    session_table="my_session_table", # Specify the table to store sessions
)

# Setup your Agent with the database
agent = Agent(db=db)

# Run the Agent. This will store a session in our "my_session_table"
agent.print_response("What is the capital of France?")

Retrieving sessions

You can manually retrieve stored sessions using the get_session method. This also works for Teams and Workflows:
from agno.agent import Agent
from agno.db.sqlite import SQLiteDb

# Setup your database
db = SQLiteDb(db_file="agno.db")

# Setup your Agent with the database
agent = Agent(db=db)

# Run the Agent, effectively creating and persisting a session
agent.print_response("What is the capital of France?", session_id="123")

# Retrieve our freshly created session
session_history = agent.get_session(session_id="123")

Benefits of using session storage

Storage is often an important feature when building production-ready agentic applications. It enables the system to:
  • Continue a session: retrieve previous messages and enable users to pick up a conversation where they left off.
  • Keep a record of sessions: enable users to inspect their past conversations.
  • Data ownership: keeping sessions in your own database gives you full control over the data.
Storage is a critical part of your Agentic infrastructure. We recommend to never offload it to a third-party service. You should almost always use your own storage layer for your Agents.

Storage for Teams and Workflows

Storage also works with Teams and Workflows, providing persistent memory for your more complex agentic applications. Similarly to Agents, you simply need to provide your Team or Workflow with a database for sessions to be persisted:
from agno.team import Team
from agno.workflow import Workflow
from agno.db.sqlite import SQLiteDb

# Set up your database
db = SQLiteDb(db_file="agno.db")

# Setup your Team
team = Team(db=db, ...)

# Setup your Workflow
workflow = Workflow(db=db, ...)
Learn more about Teams and Workflows, Agno abstractions to build multi-agent systems.

Supported databases

Databases currently supported for storage:
In-Memory databases are also supported. This is not recommended for production, but perfect for demos and testing.
You can see a detailed list of examples for all supported databases.