Enable your Agents to store session history, memories, and more.
Storage adds persistence to your Agents, allowing them to remember previous messages, user memories, and more.It works by equipping your Agents with a database that they will use to store and retrieve:
In addition this DB is used to store knowledge and evals.
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 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.
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 Agentfrom agno.db.sqlite import SQLiteDb# Setup your databasedb = SQLiteDb(db_file="agno.db")# Setup your Agent with the database and add the session history to the contextagent = 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)
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 Agentfrom agno.db.postgres import PostgresDb# Setup your databasedb = 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 databaseagent = 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?")
You can manually retrieve stored sessions using the get_session method. This also works for Teams and Workflows:
from agno.agent import Agentfrom agno.db.sqlite import SQLiteDb# Setup your databasedb = SQLiteDb(db_file="agno.db")# Setup your Agent with the databaseagent = Agent(db=db)# Run the Agent, effectively creating and persisting a sessionagent.print_response("What is the capital of France?", session_id="123")# Retrieve our freshly created sessionsession_history = agent.get_session(session_id="123")
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 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 Teamfrom agno.workflow import Workflowfrom agno.db.sqlite import SQLiteDb# Setup your databasedb = SQLiteDb(db_file="agno.db")# Setup your Teamteam = Team(db=db, ...)# Setup your Workflowworkflow = Workflow(db=db, ...)
Learn more about Teams and
Workflows, Agno abstractions to build
multi-agent systems.