Session Storage

Store and retrieve agent, team, and workflow sessions from a database.

Adding a database persists runs under a session_id. Agent and team sessions contain conversation runs. Workflow sessions contain workflow runs.

Prerequisites

For the SQLite/OpenAI examples:

uv pip install -U "agno[openai,sqlite]"
export OPENAI_API_KEY="your_openai_api_key"

Configure the Session Table

SQL adapters default to agno_sessions for session metadata and agno_runs for runs. Supported adapters create a required table on the first relevant operation when it does not exist. Set runs_table as well as session_table when separating environments.

Use session_table to store sessions in a custom table:

The PostgreSQL fragment requires a running PostgreSQL database and its connection URL. Install the driver with uv pip install -U "psycopg[binary]", then replace the sample credentials below.

from agno.agent import Agent
from agno.db.postgres import PostgresDb

db = PostgresDb(
    db_url="postgresql+psycopg://user:password@localhost:5432/mydb",
    session_table="my_agent_sessions",
)

agent = Agent(db=db)

Use separate tables when you need database-level isolation between environments.

What Gets Stored

The following describes a hydrated session object returned by get_session(). SQL adapters store run records separately in runs_table and load them into session.runs; runs is not a column in the physical session table. Fields depend on the owner type and may be absent or None. The physical SQL row also stores a session_type discriminator; it is not a session-object attribute.

FieldTypeDescription
session_idstrUnique session identifier
agent_idstrThe agent ID (if agent session)
team_idstrThe team ID (if team session)
workflow_idstrThe workflow ID (if workflow session)
user_idstrThe user this session belongs to
session_datadictSession-specific data and state
agent_datadictAgent configuration and metadata
team_datadictTeam configuration and metadata
workflow_datadictWorkflow configuration and metadata
metadatadictAdditional custom metadata
runslistAll the runs (interactions) in this session
summarySessionSummaryAgent/team summary when enabled; not a WorkflowSession field
created_atintUnix timestamp when session was created
updated_atintUnix timestamp of last update

Retrieve Sessions

Use get_session() to retrieve a stored session:

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

agent = Agent(db=SqliteDb(db_file="agent.db"))

agent.print_response("What is the capital of France?", session_id="session_123")

# Retrieve the session
session = agent.get_session(session_id="session_123")

# Access session data
print(session.session_id)
print(session.runs)  # List of runs with messages and responses

Works With Teams and Workflows

Teams and workflows expose the same get_session() interface:

from agno.agent import Agent
from agno.team import Team
from agno.workflow import Workflow
from agno.db.sqlite import SqliteDb

db = SqliteDb(db_file="agno.db")

team = Team(members=[Agent(name="Assistant")], db=db)
workflow = Workflow(db=db)

# Retrieve sessions the same way
team_session = team.get_session(session_id="team_session_123")
workflow_session = workflow.get_session(session_id="workflow_session_456")

Workflow sessions store complete pipeline runs rather than conversation messages. See Workflow Sessions for details.

Next Steps

Developer Resources