Skip to main content
Conversation memory enables agents to maintain context across multiple interactions. Agents remember previous messages and use them to provide coherent, context-aware responses in multi-turn conversations.

Enabling conversation memory

Set conversation_history to specify how many previous messages to retain:
The agent automatically manages conversation history - no manual bookkeeping required. Defaults to conversation_history=10 when you don’t specify anything.

Using conversation IDs

Group related messages using conversation_id. Works with agent.run():
and agent.stream():
How it works:
  1. Agent retrieves past messages for this conversation_id
  2. Includes them in the LLM context
  3. Stores the new message after generating a response

Example

History limits

The conversation_history parameter controls the maximum number of messages retained:
What happens when the limit is exceeded:
  • Oldest messages are dropped
  • Most recent messages (in this example, 20 messages) are kept
  • Agent always has the latest context