RunTree#
- class langsmith.run_trees.RunTree[source]#
Bases:
RunBase
Run Schema with back-references for posting runs.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- param attachments: Attachments [Optional]#
Attachments associated with the run. Each entry is a tuple of (mime_type, bytes).
- param dotted_order: str = ''#
The order of the run in the tree.
- param end_time: datetime | None = None#
End time of the run, if applicable.
- param error: str | None = None#
Error message, if the run encountered any issues.
- param events: List[Dict] [Optional]#
List of events associated with the run, like start and end events.
- param extra: Dict [Optional]#
Additional metadata or settings related to the run.
- param id: UUID [Optional]#
Unique identifier for the run.
- param inputs: dict [Optional]#
Inputs used for the run.
- param ls_client: Any | None = None#
- param name: str [Required]#
Human-readable name for the run.
- param outputs: dict | None = None#
Outputs generated by the run, if any.
- param parent_run_id: UUID | None = None#
Identifier for a parent run, if this run is a sub-run.
- param reference_example_id: UUID | None = None#
Reference to an example that this run may be based on.
- param run_type: str = 'chain'#
The type of run, such as tool, chain, llm, retriever, embedding, prompt, parser.
- param serialized: dict | None = None#
Serialized object that executed the run for potential reuse.
- param session_id: UUID | None = None (alias 'project_id')#
- param session_name: str [Optional] (alias 'project_name')#
- param start_time: datetime [Optional]#
Start time of the run.
- param tags: List[str] | None [Optional]#
Tags for categorizing or annotating the run.
- param trace_id: UUID = ''#
The trace id of the run.
- add_event(events: RunEvent | Sequence[RunEvent] | Sequence[dict] | dict | str) None [source]#
Add an event to the list of events.
- Parameters:
(Union[ls_schemas.RunEvent (events) β Sequence[dict], dict, str]): The event(s) to be added. It can be a single event, a sequence of events, a sequence of dictionaries, a dictionary, or a string.
Sequence[ls_schemas.RunEvent] β Sequence[dict], dict, str]): The event(s) to be added. It can be a single event, a sequence of events, a sequence of dictionaries, a dictionary, or a string.
events (RunEvent | Sequence[RunEvent] | Sequence[dict] | dict | str) β
- Return type:
None
- :paramSequence[dict], dict, str]):
The event(s) to be added. It can be a single event, a sequence of events, a sequence of dictionaries, a dictionary, or a string.
- add_metadata(metadata: Dict[str, Any]) None [source]#
Add metadata to the run.
- Parameters:
metadata (Dict[str, Any]) β
- Return type:
None
- add_outputs(outputs: Dict[str, Any]) None [source]#
Upsert the given outputs into the run.
- Parameters:
outputs (Dict[str, Any]) β A dictionary containing the outputs to be added.
- Returns:
None
- Return type:
None
- add_tags(tags: Sequence[str] | str) None [source]#
Add tags to the run.
- Parameters:
tags (Sequence[str] | str) β
- Return type:
None
- create_child(name: str, run_type: Literal['tool', 'chain', 'llm', 'retriever', 'embedding', 'prompt', 'parser'] = 'chain', *, run_id: UUID | str | None = None, serialized: Dict | None = None, inputs: Dict | None = None, outputs: Dict | None = None, error: str | None = None, reference_example_id: UUID | None = None, start_time: datetime | None = None, end_time: datetime | None = None, tags: List[str] | None = None, extra: Dict | None = None, attachments: Dict[str, Tuple[str, bytes] | Attachment] | None = None) RunTree [source]#
Add a child run to the run tree.
- Parameters:
name (str) β
run_type (Literal['tool', 'chain', 'llm', 'retriever', 'embedding', 'prompt', 'parser']) β
run_id (UUID | str | None) β
serialized (Dict | None) β
inputs (Dict | None) β
outputs (Dict | None) β
error (str | None) β
reference_example_id (UUID | None) β
start_time (datetime | None) β
end_time (datetime | None) β
tags (List[str] | None) β
extra (Dict | None) β
attachments (Dict[str, Tuple[str, bytes] | Attachment] | None) β
- Return type:
- end(*, outputs: Dict | None = None, error: str | None = None, end_time: datetime | None = None, events: Sequence[RunEvent] | None = None, metadata: Dict[str, Any] | None = None) None [source]#
Set the end time of the run and all child runs.
- Parameters:
outputs (Dict | None) β
error (str | None) β
end_time (datetime | None) β
events (Sequence[RunEvent] | None) β
metadata (Dict[str, Any] | None) β
- Return type:
None
- classmethod from_dotted_order(dotted_order: str, **kwargs: Any) RunTree [source]#
Create a new βchildβ span from the provided dotted order.
- Returns:
The new span.
- Return type:
- Parameters:
dotted_order (str) β
kwargs (Any) β
- classmethod from_headers(headers: Mapping[str | bytes, str | bytes], **kwargs: Any) RunTree | None [source]#
Create a new βparentβ span from the provided headers.
Extracts parent span information from the headers and creates a new span. Metadata and tags are extracted from the baggage header. The dotted order and trace id are extracted from the trace header.
- Returns:
- The new span or None if
no parent span information is found.
- Return type:
Optional[RunTree]
- Parameters:
headers (Mapping[str | bytes, str | bytes]) β
kwargs (Any) β
- classmethod from_runnable_config(config: dict | None, **kwargs: Any) RunTree | None [source]#
Create a new βchildβ span from the provided runnable config.
Requires langchain to be installed.
- Returns:
- The new span or None if
no parent span information is found.
- Return type:
Optional[RunTree]
- Parameters:
config (dict | None) β
kwargs (Any) β
- post(exclude_child_runs: bool = True) None [source]#
Post the run tree to the API asynchronously.
- Parameters:
exclude_child_runs (bool) β
- Return type:
None
- to_headers() Dict[str, str] [source]#
Return the RunTree as a dictionary of headers.
- Return type:
Dict[str, str]
- property metadata: dict[str, Any]#
Retrieve the metadata (if any).
- property revision_id: UUID | None#
Retrieve the revision ID (if any).