RunTree class provides a low-level API for creating and managing trace trees. While traceable() is recommended for most use cases, RunTree gives you fine-grained control over trace creation.
Constructor
Configuration for the run tree
RunTreeConfig properties
RunTreeConfig properties
A human-readable name for the run.
The type of run (e.g., “llm”, “chain”, “tool”, “retriever”).
The inputs that were used to initiate the run.
Unique identifier for the run. Auto-generated if not provided.
The name of the project/session.
Parent run tree if this is a child run.
Custom LangSmith client instance.
Whether tracing is enabled.
Tags for categorizing the run.
Metadata to attach to the run.
ID of an example that might be related to this run.
Properties
Unique identifier for the run.
The name of the run.
The type of run.
The run’s inputs.
The run’s outputs.
Error message if the run failed.
The ID of the root trace.
The dotted order for the run (used for sorting).
Methods
postRun()
Post the run to LangSmith (send the initial run creation).end()
End the run and send the final update to LangSmith.The outputs to attach to the run.
Error message if the run failed.
patchRun()
Update the run in LangSmith.createChild()
Create a child run.Configuration for the child run.
The child run tree.
addEvent()
Add an event to the run (e.g., for streaming tokens).addMetadata()
Add metadata to the run.addTags()
Add tags to the run.Example usage
Basic usage
Nested runs
With streaming
Static methods
fromRunnableConfig()
Create a RunTree from a LangChain RunnableConfig.When to use RunTree vs traceable()
UseRunTree when you need:
- Fine-grained control over when runs are posted/updated
- To manually manage the trace tree structure
- To integrate with non-async code
- To add events during streaming
traceable() when:
- You want automatic trace management
- You’re wrapping functions
- You want cleaner code with decorators
- AsyncLocalStorage works in your environment