Common Patterns
Automatic History (Most Common)
Enableadd_history_to_context=True to automatically include recent messages in every run:
On-Demand History Access
Enableread_chat_history=True to let the model decide when to look up history:
Programmatic Access
Retrieve history directly in your code:Choosing a Pattern
- Short chats: Leave defaults (history off) or enable
add_history_to_contextwithnum_history_runs=3 - Long-lived threads: Combine limited history (
num_history_runs=2) with session summaries to keep tokens manageable - Tool-heavy agents: Use
max_tool_calls_from_historyto limit tool call noise in context - Audit/debug flows: Enable
read_chat_history=Trueso the model looks things up only when needed - Cross-session recall: Use
search_session_history=Truewithnum_history_sessions=2(keep low to avoid context limits) - Programmatic workflows: Call
get_session_messages()/get_chat_history()directly in your code
Learn More
For comprehensive guides, detailed examples, and advanced patterns:Chat History in Agents
Complete guide to agent history management with detailed examples and advanced patterns.
Chat History in Teams
Team-specific history features, member coordination, and shared context patterns.
Chat History Overview
Overview of all history capabilities across agents, teams, and workflows.