> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

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

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

```python theme={null}
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)
```

> [!TIP]
>
> Use separate tables when you need database-level isolation between 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:

```python theme={null}
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:

```python theme={null}
from agno.team import Team
from agno.workflow import Workflow
from agno.db.sqlite import SqliteDb

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

team = Team(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")
```

> [!NOTE]
>
> Workflow sessions store complete pipeline runs rather than conversation messages. See [Workflow Sessions](https://agno-v2.mintlify.site/sessions/workflow-sessions.md) for details.

## Next Steps

> **[Session Summaries](https://agno-v2.mintlify.site/sessions/session-summaries.md)**
>
> Condense long conversations to save tokens.

> **[Storage Control](https://agno-v2.mintlify.site/sessions/persisting-sessions/storage-control.md)**
>
> Choose what gets persisted to your database.

## Developer Resources

* [AgentSession reference](https://agno-v2.mintlify.site/reference/agents/session.md)
* [TeamSession reference](https://agno-v2.mintlify.site/reference/teams/session.md)
* [WorkflowSession reference](https://agno-v2.mintlify.site/reference/workflows/session.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.