Skip to main content
A ready-to-run example is available here!

Overview

Conversation.fork() deep-copies a conversation — events, agent config, workspace metadata — into a new conversation with its own ID. The fork starts in idle status and retains the full event memory of the source, so calling run() picks up right where the original left off. Use cases:
  • CI debugging — an agent produced a wrong patch; fork to debug without losing the original run’s audit trail
  • A/B testing — fork at a given turn, change one variable, compare downstream outcomes
  • Tool-change — fork and swap in a different agent with new tools mid-conversation

Basic Usage

Create a fork

Source stays immutable

Forking deep-copies events and state. Anything you do on the fork never touches the source:

Fork with a different agent

Swap the agent on fork — useful for A/B testing models or adding/removing tools:

Tags and metadata

Forks support title and arbitrary tags for organization:

Metrics reset

By default, cost/token stats start fresh on the fork. Pass reset_metrics=False to preserve them:

API Reference

Returns: A new Conversation with the same event history but independent state.

What Gets Copied

Agent-Server REST Endpoint

When using the agent-server, forks are available via REST:
Request body (all fields optional):
Response: Standard ConversationInfo for the newly created fork. When you call fork() on a RemoteConversation, the SDK sends this request for you and returns a new RemoteConversation pointing at the server-side copy. Remote forks always reuse the server-managed agent configuration, so RemoteConversation.fork(agent=...) is intentionally unsupported.

Agent-Server Example

This example is available on GitHub: examples/02_remote_agent_server/11_conversation_fork.py
examples/02_remote_agent_server/11_conversation_fork.py

Ready-to-run Example

This example is available on GitHub: examples/01_standalone_sdk/48_conversation_fork.py
examples/01_standalone_sdk/48_conversation_fork.py
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o). The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.

Next Steps