Session Storage

Store and retrieve agent sessions from your database.

When you add a database to your agent, sessions are stored automatically. A session groups related runs into a conversation thread - every message, response, and piece of metadata is persisted under a session_id. This page covers how to access and configure that storage.

Configure the Session Table

By default, sessions are stored in the agno_sessions table. The table is created automatically if it doesn't exist.

Use session_table to store sessions in a custom table:

1from kern.db.postgres import PostgresDb
2
3db = PostgresDb(
4 db_url="postgresql://user:password@localhost:5432/mydb",
5 session_table="my_agent_sessions",
6)
7
8agent = Agent(db=db)
Tip

Use separate tables for different agents or environments.

What Gets Stored

Each session record contains:

FieldTypeDescription
session_idstrUnique session identifier
session_typestrType of session (agent, team, or workflow)
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
summarydictThe session summary (if enabled)
created_atintUnix timestamp when session was created
updated_atintUnix timestamp of last update

Retrieve Sessions

Use get_session() to retrieve a stored session:

1from kern.agent import Agent
2from kern.db.sqlite import SqliteDb
3
4agent = Agent(db=SqliteDb(db_file="agent.db"))
5
6agent.print_response("What is the capital of France?", session_id="session_123")
7
8# Retrieve the session
9session = agent.get_session(session_id="session_123")
10
11# Access session data
12print(session.session_id)
13print(session.runs) # List of runs with messages and responses

Works With Teams and Workflows

Session storage works identically for Teams and Workflows:

1from kern.team import Team
2from kern.workflow import Workflow
3from kern.db.sqlite import SqliteDb
4
5db = SqliteDb(db_file="kern.db")
6
7team = Team(db=db, ...)
8workflow = Workflow(db=db, ...)
9
10# Retrieve sessions the same way
11team_session = team.get_session(session_id="team_session_123")
12workflow_session = workflow.get_session(session_id="workflow_session_456")
Note

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

Next Steps

Developer Resources