Skip to main content
branch_session clones an entire session into a new session with a fresh session_id. Every run, plus session state and metadata, is copied. Use it to spin off an independent conversation thread from a known starting state.

Basic Usage

The new session contains deep copies of every run. The original session is untouched.

Branch vs Fork

Use branch when you want a whole new conversation thread that starts from the current state of an existing one. Use fork when you want to try an alternative path that lives next to the original.

When to Use

What Gets Copied

  • All RunOutput rows in the source session
  • session_data (including session_state)
  • session_name and metadata
What does NOT carry over:
  • Live runs in flight on the source (only persisted runs are copied)
  • Cross-session memory (memory is keyed by user_id, shared across sessions of that user by design)

User Scoping

branch_session reads the source session with the caller’s user_id. A user cannot branch another user’s session. Pass user_id explicitly if you’re calling outside an authenticated request context:

Teams

Team.branch_session works the same way:
All team runs and any nested member runs from the source are deep-copied. The new team session is independent.

HTTP

Returns the new session_id. See API Reference.

Lineage Tracking

The branched session carries branched_from = <source session_id>. Each copied run carries forked_from_session_id = <source session_id> so you can render the lineage in a UI.

Examples

Agents

Teams

Next Steps