Agentic Session State
Required so the agent is aware of the session state.
Agentic Session State.
1"""2Agentic Session State3=============================45Agentic Session State.6"""78from kern.agent import Agent9from kern.db.sqlite import SqliteDb10from kern.models.openai import OpenAIResponses1112db = SqliteDb(db_file="tmp/agents.db")13# ---------------------------------------------------------------------------14# Create Agent15# ---------------------------------------------------------------------------16agent = Agent(17 model=OpenAIResponses(id="gpt-5-mini"),18 db=db,19 session_state={"shopping_list": []},20 add_session_state_to_context=True, # Required so the agent is aware of the session state21 enable_agentic_state=True,22)2324# ---------------------------------------------------------------------------25# Run Agent26# ---------------------------------------------------------------------------27if __name__ == "__main__":28 agent.print_response("Add milk, eggs, and bread to the shopping list")2930 agent.print_response("I picked up the eggs, now what's on my list?")3132 print(f"Session state: {agent.get_session_state()}")Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/05_state_and_session45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python agentic_session_state.py