> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# State And Session

> Examples for session state management, chat history, and session persistence.

| Example                                                                                         | Description                                                                                                               |
| ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| [Agentic Session State](/examples/agents/state-and-session/agentic-session-state)               | Let the agent update its own session\_state shopping list with enable\_agentic\_state.                                    |
| [Chat History](/examples/agents/state-and-session/chat-history)                                 | Persist chat history in Postgres and read it back with get\_chat\_history() between turns.                                |
| [Dynamic Session State](/examples/agents/state-and-session/dynamic-session-state)               | Update session state inside a tool hook during an agent run.                                                              |
| [Last N Session Messages](/examples/agents/state-and-session/last-n-session-messages)           | Search a user's previous sessions with search\_past\_sessions, capped at the last two by num\_past\_sessions\_to\_search. |
| [Persistent Session](/examples/agents/state-and-session/persistent-session)                     | Persist agent sessions in Postgres with a fixed session\_id so history carries across runs.                               |
| [Session Options](/examples/agents/state-and-session/session-options)                           | Simple example demonstrating store\_history\_messages option.                                                             |
| [Session State Advanced](/examples/agents/state-and-session/session-state-advanced)             | Manage a shopping list in session\_state with tools that add, remove, and list items through RunContext.                  |
| [Session State Basic](/examples/agents/state-and-session/session-state-basic)                   | Maintain a shopping list in session state and update it from a tool through RunContext.                                   |
| [Session State Events](/examples/agents/state-and-session/session-state-events)                 | Stream an agent run and read the final session state from RunCompletedEvent.                                              |
| [Session State Manual Update](/examples/agents/state-and-session/session-state-manual-update)   | Modify session state between runs with get\_session\_state() and update\_session\_state().                                |
| [Session State Multiple Users](/examples/agents/state-and-session/session-state-multiple-users) | Maintain state for each user in a multi-user environment.                                                                 |
| [Session Summary](/examples/agents/state-and-session/session-summary)                           | Use the session summary to store the conversation summary.                                                                |
| [Search Session History](/examples/agents/state-and-session/search-session-history)             | Demonstrates the two-step list-then-read pattern for accessing previous sessions.                                         |
