Skip to main content
Conversation lets agents carry message history across turns — user messages, assistant replies, and tool results — so multi-step chats stay coherent without resending the full thread. Without conversation, each Run call is stateless — the agent has no memory of previous turns. Use it for chat UIs, support bots, or any agent where the user sends several prompts in one session.

Enable

Pass WithConversation with a conversation.Config:
Use conversation.DefaultConfig(conv) for SDK defaults with no overrides.
Conversation history is prepended to every LLM call. Token usage grows with each turn — keep Size as low as your task allows and call Clear at session end.

Conversation ID

When conversation is enabled, pass the same session ID on every call to share history:
Different IDs are isolated sessions. Sub-agents always run without a conversation ID — they do not inherit the parent session history.

Backends

Redis setup (local dev):
In-memory conversation fails at build time when DisableLocalWorker is set — the SDK detects the mismatch between a non-distributed backend and a split agent/worker deployment. Use Redis (or another distributed backend) on both the agent and worker processes.

Remote workers

Use Redis on both the agent and worker processes. Pass the same conversation.Config to NewAgent and NewAgentWorker. Set SaveOnIteration: true on the worker if external consumers need live history mid-run. See Distributed Execution for the full setup.

Lifecycle

You own the conversation store. Call Clear(ctx, id) when ending a session — the agent never clears history for you.
With SaveOnIteration: true on the worker, history is written after each tool round so external consumers can read it mid-run. Without it, history is written only when the run completes. Set it on the worker, not the agent.

Custom backend

Implement interfaces.Conversation:
Set IsDistributed() to true for any backend that can be shared across processes. The SDK uses this to validate compatibility with remote-worker deployments. Pass the implementation in conversation.Config.Conversation.

Example

Conversation

Redis-backed multi-turn history

Stream + Conversation

Streaming with persisted history

Memory

Long-term facts across separate runs

Distributed Execution

Redis conversation with remote workers