Using Storage, you can enable your Agents to remember previous messages. It works by equipping your Agents with a database that they will use to store and retrieve their sessions from.
When should I use Storage?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 us to pick up where we 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.

Usage

To provide your Agents with Storage, just setup a database and provide it to the Agent:
from agno.agent import Agent
from agno.db.sqlite import SQLiteDb

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

# Initialize your Agent passing the database
agent = Agent(db=db)
Agents with a db will persist their sessions in the database. You can also automatically add the persisted history to the context, effectively enabling Agents to persist 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 Storage

When building production-ready agentic applications, storage will often be a very important feature. This is because it enables 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

# Setup 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

This is the list of the databases we currently support: We also support using an In-Memory database. This is not recommended for production, but perfect for demos and testing. You can see a detailed list of examples for all supported databases.