Shared state propagates through nested team structures as well
How to use Shared State
You can set thesession_state parameter on Team to set initial session state data.
This state data will be shared between the team leader and its members.
This state will be available to all team members and is synchronized between them.
For example:
run_context.session_state in tools.
For example:
The
run_context object is automatically passed to the tool as an argument. Use it to access the session state.
Any updates to run_context.session_state will be automatically persisted in the database and reflected in the shared state.
See the RunContext schema for more information.Example
Here’s a simple example of a team managing a shared shopping list:team_session_state.py
Agentic Session State
Agno provides a way to allow the team and team members to automatically update the shared session state. Simply set theenable_agentic_state parameter to True.
agentic_session_state.py
Using state in instructions
You can reference variables from the session state in your instructions.state_in_instructions.py
Changing state on run
When you passsession_id to the team on team.run(), it will switch to the session with the given session_id and load any state that was set on that session.
This is useful when you want to continue a session for a specific user.
changing_state_on_run.py
Overwriting the state in the db
By default, if you passsession_state to the run methods, this new state will be merged with the session_state in the db.
You can change that behavior if you want to overwrite the session_state in the db:
overwriting_session_state_in_db.py
Team Member Interactions
Agent Teams can share interactions between members, allowing agents to learn from each other’s outputs:Developer Resources
- View the Team schema
- View the RunContext schema