05_state_and_session
Examples for session state management, chat history, and session persistence.
Content
05_state_and_session
Examples for session state management, chat history, and session persistence.
Files
agentic_session_state.py- Agent-managed session state updates.chat_history.py- Access and manage chat history.dynamic_session_state.py- Dynamic session state with computed values.last_n_session_messages.py- Limit context to the last N messages.persistent_session.py- Persist sessions across restarts with a database.session_options.py- Configure session options.session_state_advanced.py- Advanced session state patterns.session_state_basic.py- Basic session state usage.session_state_events.py- Session state change events.session_state_manual_update.py- Manually update session state.session_state_multiple_users.py- Session state with multiple users.search_chat_history.py- Find something said in an earlier turn that is out of the history window.search_chat_history_corrections.py- A value corrected mid-session: the search shows both turns and the agent uses the later one.search_past_sessions.py- Search and read previous sessions (two-step pattern).session_summary.py- Enable session summaries for context compression.
Prerequisites
- Load environment variables with
direnv allow(includingOPENAI_API_KEY). - Create the demo environment with
./scripts/demo_setup.sh, then run cookbooks with.venvs/demo/bin/python. - Some examples require PostgreSQL:
./cookbook/scripts/run_pgvector.sh
Run
.venvs/demo/bin/python cookbook/02_agents/05_state_and_session/<file>.py
Source and license
- Source
- Agno
- Original
- agno-agi/agno/cookbook/02_agents/05_state_and_session
- License
- Apache-2.0