Session Summaries

Automatically condense long conversations into concise summaries

Session summaries add a model-generated description of earlier interactions to the next run's context. They can omit details or contain mistakes, so retain the original history when exact wording matters.

History is off by default. When enabled, it normally includes the last three runs. Summaries do not automatically replace that history: both are added when both context flags are enabled. Use add_history_to_context=False for summary-only context, or combine a summary with a small recent-history window.

Generating a summary makes an additional model request. By default that request reads all eligible session messages; use SessionSummaryManager(last_n_runs=..., conversation_limit=...) to bound its own input. A smaller main-model prompt does not guarantee lower total cost once summary generation is included.

Setup

Create and activate a virtual environment, then install the dependencies and set your key:

uv pip install agno openai sqlalchemy "psycopg[binary]"
export OPENAI_API_KEY="your-api-key"

Start Docker and the local PostgreSQL server below, or use an existing server and update the connection URL. Check readiness with docker exec pgvector pg_isready -U ai -d ai before running Python.

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql \
  -v pgvolume:/var/lib/postgresql \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18

How It Works

Session summaries follow a simple three-step pattern:

Enable Summary Generation

Set enable_session_summaries=True on your agent or team. Summaries are automatically created and updated after runs when there are meaningful messages to summarize, then stored in your database.

Use Summaries in Context

Set add_session_summary_to_context=True to include the summary in your messages (this is enabled by default if you enable session summary generation). The summary is added alongside any enabled raw history. Set add_history_to_context=False to send the summary without those historical messages.

Customize (Optional)

Use SessionSummaryManager to control summary generation - use a cheaper model, customize prompts, or change the summary format. This lets you optimize costs by using a lightweight model for summaries while your main agent keeps a more capable one.

Enable Session Summaries

Turn on enable_session_summaries=True to have Agno maintain a rolling summary for each session. Summaries sit alongside the stored history and can be reused later to save tokens.

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
    enable_session_summaries=True,
    add_history_to_context=False,
)

agent.print_response("Hi my name is John and I live in New York", session_id="conversation_123")

# Retrieve the summary
summary = agent.get_session_summary(session_id="conversation_123")
if summary:
    print(summary.summary, summary.topics)

Customizing Generation

  • Provide a SessionSummaryManager to specify a cheaper model or custom prompt
  • Limit what the summary model sees with last_n_runs or conversation_limit on the manager

Use Summary in Context

add_session_summary_to_context=True is enabled by default if you enable session summary generation. To reuse an existing stored summary without updating it, set only add_session_summary_to_context=True. The snippets below reuse conversation_123 created in the matching Agent or Team example above; a new session has no summary to load. Alternatively, if you don't want to use summaries in context, you can set add_session_summary_to_context=False.

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses

db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    add_session_summary_to_context=True,
)

agent.print_response("Hi my name is John and I live in New York", session_id="conversation_123")

Agno loads the stored summary when it loads the session. You can still mix in recent history:

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    add_session_summary_to_context=True,
    add_history_to_context=True,
    num_history_runs=2,  # Summary for long-term memory, last 2 runs for detail
)

When to Use Session Summaries

✅ Best for:

  • Long-running customer support conversations
  • Multi-day or multi-week interactions
  • Conversations with 10+ turns
  • Production systems where cost matters

⚠️ Consider alternatives for:

  • Short conversations (fewer than 5 turns)
  • When full detail is critical
  • Real-time chat with recent context only

Developer Resources