agentic_session_state.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
agentic_session_state.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Let the agent update its own session_state shopping list with enable_agentic_state.
"""
Agentic Session State
=============================
Agentic Session State.
"""
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
db = SqliteDb(db_file="tmp/agents.db")
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIResponses(id="gpt-5-mini"),
db=db,
session_state={"shopping_list": []},
add_session_state_to_context=True, # Required so the agent is aware of the session state
enable_agentic_state=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response("Add milk, eggs, and bread to the shopping list")
agent.print_response("I picked up the eggs, now what's on my list?")
print(f"Session state: {agent.get_session_state()}")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai sqlalchemy
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
agentic_session_state.py, then run:python agentic_session_state.py
Was this page helpful?