Understand threads
A thread is a persistent conversation container that maintains state across multiple runs. Each time you execute a run on a thread, the graph processes the input with the thread’s current state and updates that state with new information. Threads enable stateful interactions by preserving conversation history and context between runs. Without threads, each run would be stateless, with no memory of previous interactions. Threads are particularly useful for:- Multi-turn conversations where the assistant needs to remember what was discussed.
- Long-running tasks that require maintaining context across multiple steps.
- User-specific state management where each user has their own conversation history.
- A thread maintains a persistent conversation with a unique thread ID.
- Each run applies the assistant’s configuration to the graph execution.
- State is updated after each run and persists for subsequent runs.
- Later runs have access to the full conversation history.
- Assistants define the configuration (model, prompts, tools) for how your graph executes. When creating a run, you can specify either a graph name (e.g.,
"agent") to use the default assistant, or an assistant ID (UUID) to use a specific configuration. - Threads maintain the state and conversation history.
- Runs combine an assistant and thread to execute your graph with a specific configuration and state.
Create a thread
To run your graph with state persistence, you must first create a thread:- SDK
- UI
Empty thread
To create a new thread, use one of:Copy thread
Alternatively, if you already have a thread in your application whose state you wish to copy, you can use thecopy method. This will create an independent thread whose history is identical to the original thread at the time of the operation:Prepopulated State
You can create a thread with an arbitrary pre-defined state by providing a list ofsupersteps into the create method. The supersteps describe a sequence of state updates that establish the initial state of the thread. This is useful when you want to:- Create a thread with existing conversation history.
- Migrate conversations from another system.
- Set up test scenarios with specific initial states.
- Resume conversations from a previous session.
List threads
- SDK
- UI
To list threads, use the For more information, refer to the Python and JS SDK docs, or the REST API reference.Output:Output:
search method. This will list the threads in the application that match the provided filters:Filter by thread status
Use thestatus field to filter threads based on their status. Supported values are idle, busy, interrupted, and error. For example, to view idle threads:Filter by metadata
Thesearch method allows you to filter on metadata. This is useful for finding threads associated with specific graphs, users, or custom metadata you’ve added to threads:Sorting
The SDK also supports sorting threads bythread_id, status, created_at, and updated_at using the sort_by and sort_order parameters.Inspect threads
- SDK
- UI
Get Thread
To view a specific thread given itsthread_id, use the get method:Inspect thread state
To view the current state of a given thread, use theget_state method. This returns the current values, next nodes to execute, and checkpoint information:Inspect full thread history
To view a thread’s history, use theget_history method. This returns a list of every state the thread experienced, allowing you to trace the full execution path:- Debugging execution flow by seeing how state evolved.
- Understanding decision points in your graph’s execution.
- Auditing conversation history and state changes.
- Replaying or analyzing past interactions.