viruPVS/langchain-docs huggingface dataset:
include_run(run: Run) → bool[source]¶
on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent action.
on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent end.
on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → Run¶
End a trace for a chain run.
on_chain_error(error: BaseException, *, inputs: Optional[Dict[str, Any]] = None, run_id: UUID, **kwargs: Any) → Run¶
Handle an error for a chain run.
on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, run_type: Optional[str] = None, name: Optional[str] = None, **kwargs: Any) → Run¶
Start a trace for a chain run.
on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶
Run when a chat model starts running.
on_llm_end(response: LLMResult, *, run_id: UUID, **kwargs: Any) → Run¶
End a trace for an LLM run.
Run on a retry event.
on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on arbitrary text.
on_tool_end(output: str, *, run_id: UUID, **kwargs: Any) → Run¶
End a trace for a tool run.
on_tool_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶
Handle an error for a tool run.
on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶
Start a trace for a tool run.
langchain_core.tracers.run_collector.RunCollectorCallbackHandler¶
class langchain_core.tracers.run_collector.RunCollectorCallbackHandler(example_id: Optional[Union[UUID, str]] = None, **kwargs: Any)[source]¶
A tracer that collects all nested runs in a list.
This tracer is useful for inspection and evaluation purposes.
Parameters
example_id (Optional[Union[UUID, str]], default=None) – The ID of the example being traced. It can be either a UUID or a string.
Initialize the RunCollectorCallbackHandler.
Parameters
example_id (Optional[Union[UUID, str]], default=None) – The ID of the example being traced. It can be either a UUID or a string.
Attributes
ignore_agent
Whether to ignore agent callbacks.
ignore_chain
Whether to ignore chain callbacks.
ignore_chat_model
Whether to ignore chat model callbacks.
ignore_llm
Whether to ignore LLM callbacks.
ignore_retriever
Whether to ignore retriever callbacks.
ignore_retry
Whether to ignore retry callbacks.
name
raise_error
run_inline
Methods
__init__([example_id])
Initialize the RunCollectorCallbackHandler.
on_agent_action(action, *, run_id[, ...])
Run on agent action.
on_agent_finish(finish, *, run_id[, ...])
Run on agent end.
on_chain_end(outputs, *, run_id[, inputs])
End a trace for a chain run.
on_chain_error(error, *[, inputs])
Handle an error for a chain run.
on_chain_start(serialized, inputs, *, run_id)
Start a trace for a chain run.
on_chat_model_start(serialized, messages, *, ...)
Run when a chat model starts running.
Run when a chat model starts running.
on_llm_end(response, *, run_id, **kwargs)
End a trace for an LLM run.
on_llm_error(error, *, run_id, **kwargs)
Handle an error for an LLM run.
on_llm_new_token(token, *[, chunk, ...])
Run on new LLM token.
on_llm_start(serialized, prompts, *, run_id)
Start a trace for an LLM run.
on_retriever_end(documents, *, run_id, **kwargs)
Run when Retriever ends running.
on_retriever_error(error, *, run_id, **kwargs)
Run when Retriever errors.
on_retriever_start(serialized, query, *, run_id)
Run when Retriever starts running.
on_retry(retry_state, *, run_id, **kwargs)
Run on a retry event.
on_text(text, *, run_id[, parent_run_id])
Run on arbitrary text.
on_tool_end(output, *, run_id, **kwargs)
End a trace for a tool run.
on_tool_error(error, *, run_id, **kwargs)
Handle an error for a tool run.
on_tool_start(serialized, input_str, *, run_id)
Start a trace for a tool run.
__init__(example_id: Optional[Union[UUID, str]] = None, **kwargs: Any) → None[source]¶
Initialize the RunCollectorCallbackHandler.
Parameters
example_id (Optional[Union[UUID, str]], default=None) – The ID of the example being traced. It can be either a UUID or a string.
on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent action.
on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent end.
on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) → Run¶
End a trace for a chain run.
on_chain_error(error: BaseException, *, inputs: Optional[Dict[str, Any]] = None, run_id: UUID, **kwargs: Any) → Run¶
Handle an error for a chain run.
on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, run_type: Optional[str] = None, name: Optional[str] = None, **kwargs: Any) → Run¶
Start a trace for a chain run.
on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → Any¶
Run when a chat model starts running.
on_llm_end(response: LLMResult, *, run_id: UUID, **kwargs: Any) → Run¶
End a trace for an LLM run.
on_llm_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶
langchain_core.tracers.context.collect_runs¶
langchain_core.tracers.context.collect_runs() → Generator[RunCollectorCallbackHandler, None, None][source]¶
Collect all run traces in context.
Returns
The run collector callback handler.
Return type
run_collector.RunCollectorCallbackHandler
Example
>>> with collect_runs() as runs_cb:
        chain.invoke("foo")
        run_id = runs_cb.traced_runs[0].id
langchain_core.tracers.log_stream.RunState¶
class langchain_core.tracers.log_stream.RunState[source]¶
State of the run.
id: str¶
ID of the run.
streamed_output: List[Any]¶
List of output chunks streamed by Runnable.stream()
final_output: Optional[Any]¶
Final output of the run, usually the result of aggregating (+) streamed_output.
Updated throughout the run when supported by the Runnable.
logs: Dict[str, langchain_core.tracers.log_stream.LogEntry]¶
Map of run names to sub-runs. If filters were supplied, this list will
contain only the runs that matched the filters.
langchain_core.tracers.schemas.ToolRun¶
class langchain_core.tracers.schemas.ToolRun[source]¶
Bases: BaseRun
Class for ToolRun.
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 action: str [Required]¶
param child_chain_runs: List[langchain_core.tracers.schemas.ChainRun] [Optional]¶
param child_execution_order: int [Required]¶
param child_llm_runs: List[langchain_core.tracers.schemas.LLMRun] [Optional]¶
param child_tool_runs: List[langchain_core.tracers.schemas.ToolRun] [Optional]¶
param end_time: datetime.datetime [Optional]¶
param error: Optional[str] = None¶
param execution_order: int [Required]¶
param extra: Optional[Dict[str, Any]] = None¶
param output: Optional[str] = None¶
param parent_uuid: Optional[str] = None¶
param serialized: Dict[str, Any] [Required]¶
param session_id: int [Required]¶
param start_time: datetime.datetime [Optional]¶
param tool_input: str [Required]¶
param uuid: str [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
langchain_core.tracers.context.tracing_v2_enabled¶
langchain_core.tracers.context.tracing_v2_enabled(project_name: Optional[str] = None, *, example_id: Optional[Union[str, UUID]] = None, tags: Optional[List[str]] = None, client: Optional[LangSmithClient] = None) → Generator[LangChainTracer, None, None][source]¶
Instruct LangChain to log all runs in context to LangSmith.
Parameters
project_name (str, optional) – The name of the project.
Defaults to “default”.
example_id (str or UUID, optional) – The ID of the example.
Defaults to None.
tags (List[str], optional) – The tags to add to the run.
Defaults to None.
Returns
None
Example
>>> with tracing_v2_enabled():
...     # LangChain code will automatically be traced
You can use this to fetch the LangSmith run URL:
>>> with tracing_v2_enabled() as cb:
...     chain.invoke("foo")
...     run_url = cb.get_run_url()
Examples using tracing_v2_enabled¶
LangSmith Walkthrough
langchain_core.tracers.schemas.TracerSession¶
class langchain_core.tracers.schemas.TracerSession[source]¶
Bases: TracerSessionBase
TracerSessionV1 schema for the V2 API.
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 extra: Optional[Dict[str, Any]] = None¶
param id: uuid.UUID [Required]¶
param name: Optional[str] = None¶
param start_time: datetime.datetime [Optional]¶
param tenant_id: uuid.UUID [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – 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 – set to True to make a deep copy of the model
Returns
new model instance
langchain_core.tracers.schemas.TracerSessionV1¶
class langchain_core.tracers.schemas.TracerSessionV1[source]¶
Bases: TracerSessionV1Base
TracerSessionV1 schema.
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 extra: Optional[Dict[str, Any]] = None¶
param id: int [Required]¶
param name: Optional[str] = None¶
param start_time: datetime.datetime [Optional]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – 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 – set to True to make a deep copy of the model
Returns
new model instance
langchain_core.tracers.schemas.TracerSessionV1Base¶
class langchain_core.tracers.schemas.TracerSessionV1Base[source]¶
Bases: BaseModel
Base class for TracerSessionV1.
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 extra: Optional[Dict[str, Any]] = None¶
param name: Optional[str] = None¶
param start_time: datetime.datetime [Optional]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – 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 – set to True to make a deep copy of the model
Returns
new model instance
langchain_core.tracers.log_stream.RunLogPatch¶
class langchain_core.tracers.log_stream.RunLogPatch(*ops: Dict[str, Any])[source]¶
A patch to the run log.
Attributes
ops
List of jsonpatch operations, which describe how to create the run state from an empty dict.
Methods
__init__(*ops)
__init__(*ops: Dict[str, Any]) → None[source]¶
langchain_core.tracers.schemas.TracerSessionV1Create¶
class langchain_core.tracers.schemas.TracerSessionV1Create[source]¶
Bases: TracerSessionV1Base
Create class for TracerSessionV1.
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 extra: Optional[Dict[str, Any]] = None¶
param name: Optional[str] = None¶
param start_time: datetime.datetime [Optional]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – 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 – set to True to make a deep copy of the model
Returns
new model instance
langchain_core.tracers.log_stream.LogEntry¶
class langchain_core.tracers.log_stream.LogEntry[source]¶
A single entry in the run log.
id: str¶
ID of the sub-run.
name: str¶
Name of the object being run.
type: str¶
Type of the object being run, eg. prompt, chain, llm, etc.
tags: List[str]¶
List of tags for the run.
metadata: Dict[str, Any]¶
Key-value pairs of metadata for the run.
start_time: str¶
ISO-8601 timestamp of when the run started.
streamed_output_str: List[str]¶
List of LLM tokens streamed by this run, if applicable.
final_output: Optional[Any]¶
Final output of this run.
Only available after the run has finished successfully.
end_time: Optional[str]¶
ISO-8601 timestamp of when the run ended.
Only available after the run has finished.
langchain_core.tracers.schemas.BaseRun¶
class langchain_core.tracers.schemas.BaseRun[source]¶
Bases: BaseModel
Base class for Run.
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 child_execution_order: int [Required]¶
param end_time: datetime.datetime [Optional]¶
param error: Optional[str] = None¶
param execution_order: int [Required]¶
param extra: Optional[Dict[str, Any]] = None¶
param parent_uuid: Optional[str] = None¶
param serialized: Dict[str, Any] [Required]¶
param session_id: int [Required]¶
param start_time: datetime.datetime [Optional]¶
param uuid: str [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating
the new model: you should trust this data
langchain_core.tracers.langchain_v1.LangChainTracerV1¶
class langchain_core.tracers.langchain_v1.LangChainTracerV1(**kwargs: Any)[source]¶
An implementation of the SharedTracer that POSTS to the langchain endpoint.
Initialize the LangChain tracer.
Attributes
ignore_agent
Whether to ignore agent callbacks.
ignore_chain
Whether to ignore chain callbacks.
ignore_chat_model
Whether to ignore chat model callbacks.
ignore_llm
Whether to ignore LLM callbacks.
ignore_retriever
Whether to ignore retriever callbacks.
ignore_retry
Whether to ignore retry callbacks.
raise_error
run_inline
Methods
__init__(**kwargs)
Initialize the LangChain tracer.
load_default_session()
Load the default tracing session and set it as the Tracer's session.
load_session(session_name)
Load a session with the given name from the tracer.
on_agent_action(action, *, run_id[, ...])
Run on agent action.
on_agent_finish(finish, *, run_id[, ...])
Run on agent end.
on_chain_end(outputs, *, run_id[, inputs])
End a trace for a chain run.
on_chain_error(error, *[, inputs])
Handle an error for a chain run.
on_chain_start(serialized, inputs, *, run_id)
Start a trace for a chain run.
on_chat_model_start(serialized, messages, *, ...)
Run when a chat model starts running.
on_llm_end(response, *, run_id, **kwargs)
End a trace for an LLM run.
on_llm_error(error, *, run_id, **kwargs)
Handle an error for an LLM run.
Handle an error for an LLM run.
on_llm_new_token(token, *[, chunk, ...])
Run on new LLM token.
on_llm_start(serialized, prompts, *, run_id)
Start a trace for an LLM run.
on_retriever_end(documents, *, run_id, **kwargs)
Run when Retriever ends running.
on_retriever_error(error, *, run_id, **kwargs)
Run when Retriever errors.
on_retriever_start(serialized, query, *, run_id)
Run when Retriever starts running.
on_retry(retry_state, *, run_id, **kwargs)
Run on a retry event.
on_text(text, *, run_id[, parent_run_id])
Run on arbitrary text.
on_tool_end(output, *, run_id, **kwargs)
End a trace for a tool run.
on_tool_error(error, *, run_id, **kwargs)
Handle an error for a tool run.
on_tool_start(serialized, input_str, *, run_id)
Start a trace for a tool run.
__init__(**kwargs: Any) → None[source]¶
Initialize the LangChain tracer.
load_default_session() → Union[TracerSessionV1, TracerSession][source]¶
Load the default tracing session and set it as the Tracer’s session.
load_session(session_name: str) → Union[TracerSessionV1, TracerSession][source]¶
Load a session with the given name from the tracer.
on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
Run on agent action.
langchain_core.tracers.schemas.TracerSessionBase¶
class langchain_core.tracers.schemas.TracerSessionBase[source]¶
Bases: TracerSessionV1Base
Base class for TracerSession.
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 extra: Optional[Dict[str, Any]] = None¶
param name: Optional[str] = None¶
param start_time: datetime.datetime [Optional]¶
param tenant_id: uuid.UUID [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) → Model¶
Duplicate a model, optionally choose which fields to include, exclude and change.
Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – 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 – set to True to make a deep copy of the model
Returns
new model instance
langchain_core.tracers.schemas.ChainRun¶
class langchain_core.tracers.schemas.ChainRun[source]¶
Bases: BaseRun
Class for ChainRun.
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 child_chain_runs: List[langchain_core.tracers.schemas.ChainRun] [Optional]¶
param child_execution_order: int [Required]¶
param child_llm_runs: List[langchain_core.tracers.schemas.LLMRun] [Optional]¶
param child_tool_runs: List[langchain_core.tracers.schemas.ToolRun] [Optional]¶
param end_time: datetime.datetime [Optional]¶
param error: Optional[str] = None¶
param execution_order: int [Required]¶
param extra: Optional[Dict[str, Any]] = None¶
param inputs: Dict[str, Any] [Required]¶
param outputs: Optional[Dict[str, Any]] = None¶
param parent_uuid: Optional[str] = None¶
param serialized: Dict[str, Any] [Required]¶
param session_id: int [Required]¶
param start_time: datetime.datetime [Optional]¶
param uuid: str [Required]¶
classmethod construct(_fields_set: Optional[SetStr] = 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
langchain_core.tracers.log_stream.RunLog¶
class langchain_core.tracers.log_stream.RunLog(*ops: Dict[str, Any], state: RunState)[source]¶
A run log.
Attributes
state
Current state of the log, obtained from applying all ops in sequence.
Methods
__init__(*ops, state)
__init__(*ops: Dict[str, Any], state: RunState) → None[source]¶