session_state
. The Agent updates the session_state
in tool calls and exposes them to the Model in the description
and instructions
.Agent
has a session_state
parameter.session_state
dictionary.session_state
dictionary in tool calls or other functions.session_state
with the Model in the description
and instructions
.session_state
is stored with Agent sessions and is persisted in a database. Meaning, it is available across execution cycles. This also means when switching sessions between calls to agent.run()
, the state is loaded and available.session_state
to the agent on agent.run()
, effectively overriding any state that was set on Agent initialization.add_state_in_messages=True
, the keys of the session_state
dictionary are available in the description
and instructions
as variables.Use this pattern to add the shopping_list to the instructions directly.add_state_in_messages=True
.
{key}
syntax, Agno substitutes the values for you.session_id
to the agent on agent.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.
session_state
is part of the Agent session and is saved to the database after each run if a storage
driver is provided.
Here’s an example of an Agent that maintains a shopping list and persists the state in a database. Run this script multiple times to see the state being persisted.