Skip to main content
Chat history gives each run messages from earlier runs in the same session. Configure a database and set add_history_to_context=True to add those messages to the model context.

Enable Chat History

Set add_history_to_context=True to include previous messages in every run:
Chat history requires a database that stores the session runs.

Control History Size

More history means more tokens. Use these parameters to control what gets included:
Set num_history_runs or num_history_messages, not both. If both are set, num_history_runs is used.
Start with num_history_runs=3. Increase only if your agent needs more context. For long conversations, combine limited history with session summaries.

On-Demand History Access

Instead of always including history, let the agent decide when to look it up:
The agent can call 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:
The agent gets search_past_sessions and read_past_session tools to look up previous conversations.
Keep num_past_sessions_to_search low (2-3). Cross-session history can quickly fill your context window.

Programmatic Access

Retrieve history directly in your code:
Use this for building custom UIs, debugging, or exporting transcripts.

Team History

Teams support additional history sharing between members:
With add_team_history_to_members=True, member agents see the full team conversation rather than only their own interactions.

Workflow History

Workflows use add_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

Developer Resources