Skip to main content
fork_session deep-copies every run from the source session into a brand-new session with a fresh session_id and fresh run_ids. The source is untouched. Useful for spinning up an independent conversation that starts from a known-good state.
fork_session.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Run the example

Save the code above as fork_session.py, then run:
Full source: cookbook/02_agents/21_fork_session/01_fork_session.py