Documentation Index
Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
This example demonstrates how to manage session state across different runs for different users. It shows how session state persists within the same session but is isolated between different sessions and users.
Code
from agno.agent import Agent
from agno.db.in_memory import InMemoryDb
from agno.models.openai import OpenAIChat
agent = Agent(
db=InMemoryDb(),
model=OpenAIChat(id="gpt-5-mini"),
instructions="Users name is {user_name} and age is {age}",
debug_mode=True,
)
# Sets the session state for the session with the id "user_1_session_1"
agent.print_response(
"What is my name?",
session_id="user_1_session_1",
user_id="user_1",
session_state={"user_name": "John", "age": 30},
)
# Will load the session state from the session with the id "user_1_session_1"
agent.print_response("How old am I?", session_id="user_1_session_1", user_id="user_1")
# Sets the session state for the session with the id "user_2_session_1"
agent.print_response(
"What is my name?",
session_id="user_2_session_1",
user_id="user_2",
session_state={"user_name": "Jane", "age": 25},
)
# Will load the session state from the session with the id "user_2_session_1"
agent.print_response("How old am I?", session_id="user_2_session_1", user_id="user_2")
Usage
Create a virtual environment
Open the Terminal and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U agno openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
Create a Python file
Create a Python file and add the above code.touch change_state_on_run.py
Run Agent
python change_state_on_run.py
Find All Cookbooks
Explore all the available cookbooks in the Agno repository. Click the link below to view the code on GitHub:Agno Cookbooks on GitHub