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 PostgresDb23db = PostgresDb(4 db_url="postgresql://user:password@localhost:5432/mydb",5 session_table="my_agent_sessions",6)78agent = Agent(db=db)Use separate tables for different agents or environments.
What Gets Stored
Each session record contains:
| Field | Type | Description |
|---|---|---|
session_id | str | Unique session identifier |
session_type | str | Type of session (agent, team, or workflow) |
agent_id | str | The agent ID (if agent session) |
team_id | str | The team ID (if team session) |
workflow_id | str | The workflow ID (if workflow session) |
user_id | str | The user this session belongs to |
session_data | dict | Session-specific data and state |
agent_data | dict | Agent configuration and metadata |
team_data | dict | Team configuration and metadata |
workflow_data | dict | Workflow configuration and metadata |
metadata | dict | Additional custom metadata |
runs | list | All the runs (interactions) in this session |
summary | dict | The session summary (if enabled) |
created_at | int | Unix timestamp when session was created |
updated_at | int | Unix timestamp of last update |
Retrieve Sessions
Use get_session() to retrieve a stored session:
1from kern.agent import Agent2from kern.db.sqlite import SqliteDb34agent = Agent(db=SqliteDb(db_file="agent.db"))56agent.print_response("What is the capital of France?", session_id="session_123")78# Retrieve the session9session = agent.get_session(session_id="session_123")1011# Access session data12print(session.session_id)13print(session.runs) # List of runs with messages and responsesWorks With Teams and Workflows
Session storage works identically for Teams and Workflows:
1from kern.team import Team2from kern.workflow import Workflow3from kern.db.sqlite import SqliteDb45db = SqliteDb(db_file="kern.db")67team = Team(db=db, ...)8workflow = Workflow(db=db, ...)910# Retrieve sessions the same way11team_session = team.get_session(session_id="team_session_123")12workflow_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
Session Summaries
Condense long conversations to save tokens.
Storage Control
Choose what gets persisted to your database.