Skip to main content
Chat history enables multi-turn conversations. Without it, each run is isolated—the agent has no idea what was said before. With a database and add_history_to_context=True, previous messages are automatically included in every request.

Enable Chat History

Set add_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:
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:
Keep num_history_sessions 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, not just 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