Team.run()
, it creates a stateless, singular Team run.
But what if we want to continue this conversation i.e. have a multi-turn conversation? That’s where “Sessions” come in. A session is collection of consecutive runs.
In practice, a session in the context of a Team is a multi-turn conversation between a user and the Team. Using a session_id
, we can connect the conversation history and state across multiple runs.
See more details in the Agent Sessions documentation.
Multi-user, multi-session Teams
Each user that is interacting with a Team gets a unique set of sessions and you can have multiple users interacting with the same Team at the same time. Set auser_id
to connect a user to their sessions with the Team.
In the example below, we set a session_id
to demo how to have multi-turn conversations with multiple users at the same time.
1
Multi-user, multi-session example
2
Run the example
Install librariesExport your keyRun the example
Session Summaries
The Team can store a condensed representations of the session, useful when chat histories gets too long. This is called a “Session Summary” in Agno. To enable session summaries, setenable_session_summaries=True
on the Team
.
1
Session summary example
session_summary.py
2
Run the example
Install librariesExport your keyRun the example
Customize Session Summaries
You can adjust the session summaries by providing a customsession_summary_prompt
to the Team
.
The SessionSummaryManager
class is responsible for handling the model used to create and update session summaries.
You can adjust it to personalize how summaries are created and updated:
1
Customize session summaries example
customize_session_summary.py
2
Run the example
Install librariesExport your keyRun the example
Session history
Teams with storage enabled automatically have access to the message and run history of the session. You can access these messages using:agent.get_messages_for_session()
-> Gets access to all the messages for the session, for the current agent.agent.get_chat_history()
-> Gets access to all the unique messages for the session.
- We can set
add_history_to_context=True
andnum_history_runs=5
to add the messages from the last 5 runs automatically to every message sent to the agent. - We can set
read_chat_history=True
to provide aget_chat_history()
tool to your agent allowing it to read any message in the entire chat history. - We recommend setting all 3:
add_history_to_context=True
,num_history_runs=3
andread_chat_history=True
for the best experience. - We can also set
read_tool_call_history=True
to provide aget_tool_call_history()
tool to your agent allowing it to read tool calls in reverse chronological order.
1
Session history example
session_history.py
2
Run the example
Install librariesExport your keyRun the example
Search the session history
In some scenarios, you might want to fetch messages from across multiple sessions to provide context or continuity in conversations. To enable fetching messages from the last N sessions, you need to use the following flags:search_session_history
: Set this toTrue
to allow searching through previous sessions.num_history_sessions
: Specify the number of past sessions to include in the search. In the example below, it is set to2
to include only the last 2 sessions.
1
Session history search example
session_history_search.py
2
Run the example
Install librariesExport your keyRun the example
Control what gets stored in the session
As your sessions grow, you may want to decide what data exactly is persisted. Agno provides three flags to optimize storage while maintaining full functionality during execution:store_media
- Controls storage of images, videos, audio, and filesstore_tool_results
- Controls storage of tool calls and their resultsstore_history_messages
- Controls storage of history messages
How it works
These flags only affect what gets persisted to the database. During execution, all data remains available to your team - media, tool results, and history are still accessible in theRunOutput
object. The data is scrubbed right before saving to the database.This means:- Your team functionality remains unchanged
- Tools can access all data they need during execution
- Only the database storage is optimized
Developer Resources
- View the Team schema
- View the Session schema
- View Cookbook