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
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
RunOutputrows in the source session session_data(includingsession_state)session_nameand metadata
- 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:
HTTP
session_id. See API Reference.
Lineage Tracking
The branched session carriesbranched_from = <source session_id>. Each copied run carries forked_from_session_id = <source session_id> so you can render the lineage in a UI.