RunTree#
- class langsmith.run_trees.RunTree(*, id: UUID = None, name: str, start_time: datetime = None, run_type: str = 'chain', end_time: datetime | None = None, extra: Dict = None, error: str | None = None, serialized: dict | None = None, events: List[Dict] = None, inputs: dict = None, outputs: dict | None = None, reference_example_id: UUID | None = None, parent_run_id: UUID | None = None, tags: List[str] | None = None, attachments: Dict[str, Tuple[str, bytes] | Attachment | Tuple[str, Path]] | Dict[str, AttachmentInfo] = None, parent_run: RunTree | None = None, child_runs: List[RunTree] = None, project_name: str = None, project_id: UUID | None = None, ls_client: Any | None = None, dotted_order: str = '', trace_id: UUID = '', dangerously_allow_filesystem: bool | None = False)[source]#
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.
Attributes
client
Return the client.
metadata
Retrieve the metadata (if any).
revision_id
Retrieve the revision ID (if any).
Methods
__init__
(**data)Create a new model by parsing and validating input data from keyword arguments.
add_event
(events)Add an event to the list of events.
add_inputs
(inputs)Upsert the given outputs into the run.
add_metadata
(metadata)Add metadata to the run.
add_outputs
(outputs)Upsert the given outputs into the run.
add_tags
(tags)Add tags to the run.
construct
([_fields_set])Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data.
copy
(*[, include, exclude, update, deep])Duplicate a model, optionally choose which fields to include, exclude and change.
create_child
(name[, run_type, run_id, ...])Add a child run to the run tree.
dict
(*[, include, exclude, by_alias, ...])Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
end
(*[, outputs, error, end_time, events, ...])Set the end time of the run and all child runs.
ensure_dotted_order
(values)Ensure the dotted order of the run.
from_dotted_order
(dotted_order, **kwargs)Create a new 'child' span from the provided dotted order.
from_headers
(headers, **kwargs)Create a new 'parent' span from the provided headers.
from_orm
(obj)from_runnable_config
(config, **kwargs)Create a new 'child' span from the provided runnable config.
get_url
()Return the URL of the run.
infer_defaults
(values)Assign name to the run.
json
(*[, include, exclude, by_alias, ...])Generate a JSON representation of the model, include and exclude arguments as per dict().
parse_file
(path, *[, content_type, ...])parse_obj
(obj)parse_raw
(b, *[, content_type, encoding, ...])patch
()Patch the run tree to the API in a background thread.
post
([exclude_child_runs])Post the run tree to the API asynchronously.
schema
([by_alias, ref_template])schema_json
(*[, by_alias, ref_template])Return the RunTree as a dictionary of headers.
update_forward_refs
(**localns)Try to update ForwardRefs on fields based on this Model, globalns and localns.
validate
(value)wait
()Wait for all _futures to complete.
- Parameters:
id (UUID)
name (str)
start_time (datetime)
run_type (str)
end_time (datetime | None)
extra (Dict)
error (str | None)
serialized (dict | None)
events (List[Dict])
inputs (dict)
outputs (dict | None)
reference_example_id (UUID | None)
parent_run_id (UUID | None)
tags (List[str] | None)
attachments (Dict[str, Tuple[str, bytes] | Attachment | Tuple[str, Path]] | Dict[str, AttachmentInfo])
parent_run (RunTree | None)
child_runs (List[RunTree])
project_name (str)
project_id (UUID | None)
ls_client (Any | None)
dotted_order (str)
trace_id (UUID)
dangerously_allow_filesystem (bool | None)
- __init__(**data: Any) None #
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.
- Parameters:
data (Any)
- Return type:
None
- 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_inputs(inputs: 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.
inputs (Dict[str, Any])
- Returns:
None
- Return type:
None
- 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
- classmethod construct(_fields_set: SetStr | None = None, **values: Any) Model #
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- Parameters:
_fields_set (SetStr | None)
values (Any)
- Return type:
Model
- copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: DictStrAny | None = None, deep: bool = False) Model #
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – fields to include in new model
exclude (AbstractSetIntStr | MappingIntStrAny | None) – fields to exclude from new model, as with values this takes precedence over include
update (DictStrAny | None) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model)
- Returns:
new model instance
- Return type:
Model
- 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 | Tuple[str, Path]] | 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 | Tuple[str, Path]] | None)
- Return type:
- dict(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny #
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None)
exclude (AbstractSetIntStr | MappingIntStrAny | None)
by_alias (bool)
skip_defaults (bool | None)
exclude_unset (bool)
exclude_defaults (bool)
exclude_none (bool)
- Return type:
DictStrAny
- 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 ensure_dotted_order(values: dict) dict [source]#
Ensure the dotted order of the run.
- Parameters:
values (dict)
- Return type:
dict
- 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_orm(obj: Any) Model #
- Parameters:
obj (Any)
- Return type:
Model
- 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)
- classmethod infer_defaults(values: dict) dict [source]#
Assign name to the run.
- Parameters:
values (dict)
- Return type:
dict
- json(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, by_alias: bool = False, skip_defaults: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = None, models_as_dict: bool = True, **dumps_kwargs: Any) str #
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None)
exclude (AbstractSetIntStr | MappingIntStrAny | None)
by_alias (bool)
skip_defaults (bool | None)
exclude_unset (bool)
exclude_defaults (bool)
exclude_none (bool)
encoder (Callable[[Any], Any] | None)
models_as_dict (bool)
dumps_kwargs (Any)
- Return type:
str
- classmethod parse_file(path: str | Path, *, content_type: str = None, encoding: str = 'utf8', proto: Protocol = None, allow_pickle: bool = False) Model #
- Parameters:
path (str | Path)
content_type (str)
encoding (str)
proto (Protocol)
allow_pickle (bool)
- Return type:
Model
- classmethod parse_obj(obj: Any) Model #
- Parameters:
obj (Any)
- Return type:
Model
- classmethod parse_raw(b: str | bytes, *, content_type: str = None, encoding: str = 'utf8', proto: Protocol = None, allow_pickle: bool = False) Model #
- Parameters:
b (str | bytes)
content_type (str)
encoding (str)
proto (Protocol)
allow_pickle (bool)
- Return type:
Model
- post(exclude_child_runs: bool = True) None [source]#
Post the run tree to the API asynchronously.
- Parameters:
exclude_child_runs (bool)
- Return type:
None
- classmethod schema(by_alias: bool = True, ref_template: str = '#/definitions/{model}') DictStrAny #
- Parameters:
by_alias (bool)
ref_template (str)
- Return type:
DictStrAny
- classmethod schema_json(*, by_alias: bool = True, ref_template: str = '#/definitions/{model}', **dumps_kwargs: Any) str #
- Parameters:
by_alias (bool)
ref_template (str)
dumps_kwargs (Any)
- Return type:
str
- to_headers() Dict[str, str] [source]#
Return the RunTree as a dictionary of headers.
- Return type:
Dict[str, str]
- classmethod update_forward_refs(**localns: Any) None #
Try to update ForwardRefs on fields based on this Model, globalns and localns.
- Parameters:
localns (Any)
- Return type:
None
- classmethod validate(value: Any) Model #
- Parameters:
value (Any)
- Return type:
Model