Agentic Session State

Let the agent update its own session_state shopping list with enable_agentic_state.

Agentic Session State.

agentic_session_state.py
"""
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()}")

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai sqlalchemy

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as agentic_session_state.py, then run:

python agentic_session_state.py

Full source: cookbook/02_agents/05_state_and_session/agentic_session_state.py