add_history_to_context=True, previous messages are automatically included in every request.
Enable Chat History
Setadd_history_to_context=True to include previous messages in every run:
Chat history requires a database. Without one, there’s nothing to retrieve.
Control History Size
More history means more tokens. Use these parameters to control what gets included:| Parameter | Description |
|---|---|
num_history_runs | Number of previous runs to include (default: 3) |
num_history_messages | Maximum messages to include across all runs |
max_tool_calls_from_history | Limit tool call messages in history |
On-Demand History Access
Instead of always including history, let the agent decide when to look it up:get_chat_history() when it needs context, rather than having history in every request. Useful for analytics, auditing, or when most queries don’t need prior context.
Cross-Session History
Search across multiple sessions for context that spans conversations:Programmatic Access
Retrieve history directly in your code:Team History
Teams support additional history sharing between members:add_team_history_to_members=True, member agents see the full team conversation, not just their own interactions.
Workflow History
Workflows useadd_workflow_history_to_steps to pass previous run results to steps:
Workflow history passes previous workflow outputs to steps, not conversation messages. See Workflow Sessions for details.
Choosing a Pattern
| Scenario | Configuration |
|---|---|
| Chat-style products | add_history_to_context=True, num_history_runs=3 |
| Long conversations | Limited history + session summaries |
| Tool-heavy agents | Add max_tool_calls_from_history to reduce noise |
| Cross-session recall | search_session_history=True, num_history_sessions=2 |
| Selective lookup | read_chat_history=True (agent decides when to look up) |
| Custom UIs | Use get_chat_history() programmatically |
Developer Resources
- Session Storage - What gets stored and how to retrieve it.
- AgentSession reference
- TeamSession reference