id
stringlengths
14
15
text
stringlengths
44
2.47k
source
stringlengths
61
181
dd3d3b58bd05-0
langchain.callbacks.labelstudio_callback.get_default_label_configs¶ langchain.callbacks.labelstudio_callback.get_default_label_configs(mode: Union[str, LabelStudioMode]) → Tuple[str, LabelStudioMode][source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.labelstudio_callback.get_default_label_configs.html
a46930af6bf4-0
langchain.callbacks.tracers.log_stream.RunLog¶ class langchain.callbacks.tracers.log_stream.RunLog(*ops: Dict[str, Any], state: RunState)[source]¶ 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]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.log_stream.RunLog.html
5600d6c5007e-0
langchain.callbacks.tracers.langchain.wait_for_all_tracers¶ langchain.callbacks.tracers.langchain.wait_for_all_tracers() → None[source]¶ Wait for all tracers to finish. Examples using wait_for_all_tracers¶ LangSmith Walkthrough
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.wait_for_all_tracers.html
74cc398353af-0
langchain.callbacks.tracers.wandb.WandbTracer¶ class langchain.callbacks.tracers.wandb.WandbTracer(run_args: Optional[WandbRunArgs] = None, **kwargs: Any)[source]¶ Callback Handler that logs to Weights and Biases. This handler will log the model architecture and run traces to Weights and Biases. This will ensure that all LangChain activity is logged to W&B. Initializes the WandbTracer. Parameters run_args – (dict, optional) Arguments to pass to wandb.init(). If not provided, wandb.init() will be called with no arguments. Please refer to the wandb.init for more details. To use W&B to monitor all LangChain activity, add this tracer like any other LangChain callback: ``` from wandb.integration.langchain import WandbTracer tracer = WandbTracer() chain = LLMChain(llm, callbacks=[tracer]) # …end of notebook / script: tracer.finish() ``` 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__([run_args]) Initializes the WandbTracer. finish() Waits for all asynchronous processes to finish and data to upload. 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])
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.wandb.WandbTracer.html
74cc398353af-1
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. 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)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.wandb.WandbTracer.html
74cc398353af-2
on_tool_start(serialized, input_str, *, run_id) Start a trace for a tool run. __init__(run_args: Optional[WandbRunArgs] = None, **kwargs: Any) → None[source]¶ Initializes the WandbTracer. Parameters run_args – (dict, optional) Arguments to pass to wandb.init(). If not provided, wandb.init() will be called with no arguments. Please refer to the wandb.init for more details. To use W&B to monitor all LangChain activity, add this tracer like any other LangChain callback: ``` from wandb.integration.langchain import WandbTracer tracer = WandbTracer() chain = LLMChain(llm, callbacks=[tracer]) # …end of notebook / script: tracer.finish() ``` finish() → None[source]¶ Waits for all asynchronous processes to finish and data to upload. Proxy for wandb.finish(). 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.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.wandb.WandbTracer.html
74cc398353af-3
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¶ Handle an error for an LLM run. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Run¶ Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[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 an LLM run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.wandb.WandbTracer.html
74cc398353af-4
Start a trace for an LLM run. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, **kwargs: Any) → 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.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.wandb.WandbTracer.html
c5df85f3e68e-0
langchain.callbacks.manager.CallbackManagerForChainGroup¶ class langchain.callbacks.manager.CallbackManagerForChainGroup(handlers: List[BaseCallbackHandler], inheritable_handlers: Optional[List[BaseCallbackHandler]] = None, parent_run_id: uuid.UUID | None = None, *, parent_run_manager: CallbackManagerForChainRun, **kwargs: Any)[source]¶ Initialize callback manager. Attributes is_async Whether the callback manager is async. Methods __init__(handlers[, inheritable_handlers, ...]) Initialize callback manager. add_handler(handler[, inherit]) Add a handler to the callback manager. add_metadata(metadata[, inherit]) add_tags(tags[, inherit]) configure([inheritable_callbacks, ...]) Configure the callback manager. copy() Copy the callback manager. on_chain_end(outputs, **kwargs) Run when traced chain group ends. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs[, run_id]) Run when chain starts running. on_chat_model_start(serialized, messages, ...) Run when LLM starts running. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts running. on_retriever_start(serialized, query[, ...]) Run when retriever starts running. on_tool_start(serialized, input_str[, ...]) Run when tool starts running. remove_handler(handler) Remove a handler from the callback manager. remove_metadata(keys) remove_tags(tags) set_handler(handler[, inherit]) Set handler as the only handler on the callback manager. set_handlers(handlers[, inherit]) Set handlers as the only handlers on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainGroup.html
c5df85f3e68e-1
Set handlers as the only handlers on the callback manager. __init__(handlers: List[BaseCallbackHandler], inheritable_handlers: Optional[List[BaseCallbackHandler]] = None, parent_run_id: uuid.UUID | None = None, *, parent_run_manager: CallbackManagerForChainRun, **kwargs: Any) → None[source]¶ Initialize callback manager. add_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶ Add a handler to the callback manager. add_metadata(metadata: Dict[str, Any], inherit: bool = True) → None¶ add_tags(tags: List[str], inherit: bool = True) → None¶ classmethod configure(inheritable_callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, local_callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, verbose: bool = False, inheritable_tags: Optional[List[str]] = None, local_tags: Optional[List[str]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None, local_metadata: Optional[Dict[str, Any]] = None) → CallbackManager¶ Configure the callback manager. Parameters inheritable_callbacks (Optional[Callbacks], optional) – The inheritable callbacks. Defaults to None. local_callbacks (Optional[Callbacks], optional) – The local callbacks. Defaults to None. verbose (bool, optional) – Whether to enable verbose mode. Defaults to False. inheritable_tags (Optional[List[str]], optional) – The inheritable tags. Defaults to None. local_tags (Optional[List[str]], optional) – The local tags. Defaults to None. inheritable_metadata (Optional[Dict[str, Any]], optional) – The inheritable metadata. Defaults to None. local_metadata (Optional[Dict[str, Any]], optional) – The local metadata. Defaults to None. Returns
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainGroup.html
c5df85f3e68e-2
Defaults to None. Returns The configured callback manager. Return type CallbackManager copy() → T¶ Copy the callback manager. on_chain_end(outputs: Union[Dict[str, Any], Any], **kwargs: Any) → None[source]¶ Run when traced chain group ends. Parameters outputs (Union[Dict[str, Any], Any]) – The outputs of the chain. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. Parameters error (Exception or KeyboardInterrupt) – The error. on_chain_start(serialized: Dict[str, Any], inputs: Union[Dict[str, Any], Any], run_id: Optional[UUID] = None, **kwargs: Any) → CallbackManagerForChainRun¶ Run when chain starts running. Parameters serialized (Dict[str, Any]) – The serialized chain. inputs (Union[Dict[str, Any], Any]) – The inputs to the chain. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The callback manager for the chain run. Return type CallbackManagerForChainRun on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs: Any) → List[CallbackManagerForLLMRun]¶ Run when LLM starts running. Parameters serialized (Dict[str, Any]) – The serialized LLM. messages (List[List[BaseMessage]]) – The list of messages. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns A callback manager for eachlist of messages as an LLM run. Return type List[CallbackManagerForLLMRun]
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainGroup.html
c5df85f3e68e-3
Return type List[CallbackManagerForLLMRun] on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → List[CallbackManagerForLLMRun]¶ Run when LLM starts running. Parameters serialized (Dict[str, Any]) – The serialized LLM. prompts (List[str]) – The list of prompts. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns A callback manager for eachprompt as an LLM run. Return type List[CallbackManagerForLLMRun] on_retriever_start(serialized: Dict[str, Any], query: str, run_id: Optional[UUID] = None, parent_run_id: Optional[UUID] = None, **kwargs: Any) → CallbackManagerForRetrieverRun¶ Run when retriever starts running. on_tool_start(serialized: Dict[str, Any], input_str: str, run_id: Optional[UUID] = None, parent_run_id: Optional[UUID] = None, **kwargs: Any) → CallbackManagerForToolRun¶ Run when tool starts running. Parameters serialized (Dict[str, Any]) – The serialized tool. input_str (str) – The input to the tool. run_id (UUID, optional) – The ID of the run. Defaults to None. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. Returns The callback manager for the tool run. Return type CallbackManagerForToolRun remove_handler(handler: BaseCallbackHandler) → None¶ Remove a handler from the callback manager. remove_metadata(keys: List[str]) → None¶ remove_tags(tags: List[str]) → None¶ set_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainGroup.html
c5df85f3e68e-4
set_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶ Set handler as the only handler on the callback manager. set_handlers(handlers: List[BaseCallbackHandler], inherit: bool = True) → None¶ Set handlers as the only handlers on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForChainGroup.html
4d2f85f15cb9-0
langchain.callbacks.arthur_callback.ArthurCallbackHandler¶ class langchain.callbacks.arthur_callback.ArthurCallbackHandler(arthur_model: ArthurModel)[source]¶ Callback Handler that logs to Arthur platform. Arthur helps enterprise teams optimize model operations and performance at scale. The Arthur API tracks model performance, explainability, and fairness across tabular, NLP, and CV models. Our API is model- and platform-agnostic, and continuously scales with complex and dynamic enterprise needs. To learn more about Arthur, visit our website at https://www.arthur.ai/ or read the Arthur docs at https://docs.arthur.ai/ Initialize callback handler. 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__(arthur_model) Initialize callback handler. from_credentials(model_id[, arthur_url, ...]) Initialize callback handler from Arthur credentials. on_agent_action(action, **kwargs) Do nothing when agent takes a specific action. on_agent_finish(finish, **kwargs) Do nothing on_chain_end(outputs, **kwargs) On chain end, do nothing. on_chain_error(error, **kwargs) Do nothing when LLM chain outputs an error. on_chain_start(serialized, inputs, **kwargs) On chain start, do nothing. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) On LLM end, send data to Arthur.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.arthur_callback.ArthurCallbackHandler.html
4d2f85f15cb9-1
On LLM end, send data to Arthur. on_llm_error(error, **kwargs) Do nothing when LLM outputs an error. on_llm_new_token(token, **kwargs) On new token, pass. on_llm_start(serialized, prompts, **kwargs) On LLM start, save the input prompts on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Do nothing on_tool_end(output[, observation_prefix, ...]) Do nothing when tool ends. on_tool_error(error, **kwargs) Do nothing when tool outputs an error. on_tool_start(serialized, input_str, **kwargs) Do nothing when tool starts. __init__(arthur_model: ArthurModel) → None[source]¶ Initialize callback handler. classmethod from_credentials(model_id: str, arthur_url: Optional[str] = 'https://app.arthur.ai', arthur_login: Optional[str] = None, arthur_password: Optional[str] = None) → ArthurCallbackHandler[source]¶ Initialize callback handler from Arthur credentials. Parameters model_id (str) – The ID of the arthur model to log to. arthur_url (str, optional) – The URL of the Arthur instance to log to. Defaults to “https://app.arthur.ai”.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.arthur_callback.ArthurCallbackHandler.html
4d2f85f15cb9-2
Defaults to “https://app.arthur.ai”. arthur_login (str, optional) – The login to use to connect to Arthur. Defaults to None. arthur_password (str, optional) – The password to use to connect to Arthur. Defaults to None. Returns The initialized callback handler. Return type ArthurCallbackHandler on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Do nothing when agent takes a specific action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Do nothing on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ On chain end, do nothing. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when LLM chain outputs an error. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ On chain start, do nothing. 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, **kwargs: Any) → None[source]¶ On LLM end, send data to Arthur. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when LLM outputs an error. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ On new token, pass.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.arthur_callback.ArthurCallbackHandler.html
4d2f85f15cb9-3
On new token, pass. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ On LLM start, save the input prompts on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Do nothing on_tool_end(output: str, observation_prefix: Optional[str] = None, llm_prefix: Optional[str] = None, **kwargs: Any) → None[source]¶ Do nothing when tool ends. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Do nothing when tool outputs an error. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Do nothing when tool starts. Examples using ArthurCallbackHandler¶ Arthur
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.arthur_callback.ArthurCallbackHandler.html
6c40dc04e971-0
langchain.callbacks.base.ToolManagerMixin¶ class langchain.callbacks.base.ToolManagerMixin[source]¶ Mixin for tool callbacks. Methods __init__() on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. __init__()¶ on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when tool errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.ToolManagerMixin.html
64c332b6ff77-0
langchain.callbacks.streamlit.streamlit_callback_handler.LLMThoughtLabeler¶ class langchain.callbacks.streamlit.streamlit_callback_handler.LLMThoughtLabeler[source]¶ Generates markdown labels for LLMThought containers. Pass a custom subclass of this to StreamlitCallbackHandler to override its default labeling logic. Methods __init__() get_final_agent_thought_label() Return the markdown label for the agent's final thought - the "Now I have the answer" thought, that doesn't involve a tool. get_history_label() Return a markdown label for the special 'history' container that contains overflow thoughts. get_initial_label() Return the markdown label for a new LLMThought that doesn't have an associated tool yet. get_tool_label(tool, is_complete) Return the label for an LLMThought that has an associated tool. __init__()¶ get_final_agent_thought_label() → str[source]¶ Return the markdown label for the agent’s final thought - the “Now I have the answer” thought, that doesn’t involve a tool. get_history_label() → str[source]¶ Return a markdown label for the special ‘history’ container that contains overflow thoughts. get_initial_label() → str[source]¶ Return the markdown label for a new LLMThought that doesn’t have an associated tool yet. get_tool_label(tool: ToolRecord, is_complete: bool) → str[source]¶ Return the label for an LLMThought that has an associated tool. Parameters tool – The tool’s ToolRecord is_complete – True if the thought is complete; False if the thought is still receiving input. Return type The markdown label for the thought’s container.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.LLMThoughtLabeler.html
f824dd30a2fb-0
langchain.callbacks.manager.AsyncCallbackManager¶ class langchain.callbacks.manager.AsyncCallbackManager(handlers: List[BaseCallbackHandler], inheritable_handlers: Optional[List[BaseCallbackHandler]] = None, parent_run_id: Optional[UUID] = None, *, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Async callback manager that handles callbacks from LangChain. Initialize callback manager. Attributes is_async Return whether the handler is async. Methods __init__(handlers[, inheritable_handlers, ...]) Initialize callback manager. add_handler(handler[, inherit]) Add a handler to the callback manager. add_metadata(metadata[, inherit]) add_tags(tags[, inherit]) configure([inheritable_callbacks, ...]) Configure the async callback manager. copy() Copy the callback manager. on_chain_start(serialized, inputs[, run_id]) Run when chain starts running. on_chat_model_start(serialized, messages, ...) Run when LLM starts running. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts running. on_retriever_start(serialized, query[, ...]) Run when retriever starts running. on_tool_start(serialized, input_str[, ...]) Run when tool starts running. remove_handler(handler) Remove a handler from the callback manager. remove_metadata(keys) remove_tags(tags) set_handler(handler[, inherit]) Set handler as the only handler on the callback manager. set_handlers(handlers[, inherit]) Set handlers as the only handlers on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManager.html
f824dd30a2fb-1
Set handlers as the only handlers on the callback manager. __init__(handlers: List[BaseCallbackHandler], inheritable_handlers: Optional[List[BaseCallbackHandler]] = None, parent_run_id: Optional[UUID] = None, *, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize callback manager. add_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶ Add a handler to the callback manager. add_metadata(metadata: Dict[str, Any], inherit: bool = True) → None¶ add_tags(tags: List[str], inherit: bool = True) → None¶ classmethod configure(inheritable_callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, local_callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, verbose: bool = False, inheritable_tags: Optional[List[str]] = None, local_tags: Optional[List[str]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None, local_metadata: Optional[Dict[str, Any]] = None) → AsyncCallbackManager[source]¶ Configure the async callback manager. Parameters inheritable_callbacks (Optional[Callbacks], optional) – The inheritable callbacks. Defaults to None. local_callbacks (Optional[Callbacks], optional) – The local callbacks. Defaults to None. verbose (bool, optional) – Whether to enable verbose mode. Defaults to False. inheritable_tags (Optional[List[str]], optional) – The inheritable tags. Defaults to None. local_tags (Optional[List[str]], optional) – The local tags. Defaults to None. inheritable_metadata (Optional[Dict[str, Any]], optional) – The inheritable
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManager.html
f824dd30a2fb-2
inheritable_metadata (Optional[Dict[str, Any]], optional) – The inheritable metadata. Defaults to None. local_metadata (Optional[Dict[str, Any]], optional) – The local metadata. Defaults to None. Returns The configured async callback manager. Return type AsyncCallbackManager copy() → T¶ Copy the callback manager. async on_chain_start(serialized: Dict[str, Any], inputs: Union[Dict[str, Any], Any], run_id: Optional[UUID] = None, **kwargs: Any) → AsyncCallbackManagerForChainRun[source]¶ Run when chain starts running. Parameters serialized (Dict[str, Any]) – The serialized chain. inputs (Union[Dict[str, Any], Any]) – The inputs to the chain. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The async callback managerfor the chain run. Return type AsyncCallbackManagerForChainRun async on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs: Any) → List[AsyncCallbackManagerForLLMRun][source]¶ Run when LLM starts running. Parameters serialized (Dict[str, Any]) – The serialized LLM. messages (List[List[BaseMessage]]) – The list of messages. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The list ofasync callback managers, one for each LLM Run corresponding to each inner message list. Return type List[AsyncCallbackManagerForLLMRun] async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → List[AsyncCallbackManagerForLLMRun][source]¶ Run when LLM starts running. Parameters
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManager.html
f824dd30a2fb-3
Run when LLM starts running. Parameters serialized (Dict[str, Any]) – The serialized LLM. prompts (List[str]) – The list of prompts. run_id (UUID, optional) – The ID of the run. Defaults to None. Returns The list of asynccallback managers, one for each LLM Run corresponding to each prompt. Return type List[AsyncCallbackManagerForLLMRun] async on_retriever_start(serialized: Dict[str, Any], query: str, run_id: Optional[UUID] = None, parent_run_id: Optional[UUID] = None, **kwargs: Any) → AsyncCallbackManagerForRetrieverRun[source]¶ Run when retriever starts running. async on_tool_start(serialized: Dict[str, Any], input_str: str, run_id: Optional[UUID] = None, parent_run_id: Optional[UUID] = None, **kwargs: Any) → AsyncCallbackManagerForToolRun[source]¶ Run when tool starts running. Parameters serialized (Dict[str, Any]) – The serialized tool. input_str (str) – The input to the tool. run_id (UUID, optional) – The ID of the run. Defaults to None. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. Returns The async callback managerfor the tool run. Return type AsyncCallbackManagerForToolRun remove_handler(handler: BaseCallbackHandler) → None¶ Remove a handler from the callback manager. remove_metadata(keys: List[str]) → None¶ remove_tags(tags: List[str]) → None¶ set_handler(handler: BaseCallbackHandler, inherit: bool = True) → None¶ Set handler as the only handler on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManager.html
f824dd30a2fb-4
Set handler as the only handler on the callback manager. set_handlers(handlers: List[BaseCallbackHandler], inherit: bool = True) → None¶ Set handlers as the only handlers on the callback manager.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManager.html
b3f5001aad0e-0
langchain.callbacks.tracers.schemas.LLMRun¶ class langchain.callbacks.tracers.schemas.LLMRun[source]¶ Bases: BaseRun Class for LLMRun. 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 prompts: List[str] [Required]¶ param response: Optional[langchain.schema.output.LLMResult] = 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
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.LLMRun.html
b3f5001aad0e-1
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 dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = 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. classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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(). classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.LLMRun.html
b3f5001aad0e-2
classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.LLMRun.html
03c2feb325c8-0
langchain.callbacks.context_callback.import_context¶ langchain.callbacks.context_callback.import_context() → Any[source]¶ Import the getcontext package.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.context_callback.import_context.html
c16012084ac7-0
langchain.callbacks.streaming_stdout_final_only.FinalStreamingStdOutCallbackHandler¶ class langchain.callbacks.streaming_stdout_final_only.FinalStreamingStdOutCallbackHandler(*, answer_prefix_tokens: Optional[List[str]] = None, strip_tokens: bool = True, stream_prefix: bool = False)[source]¶ Callback handler for streaming in agents. Only works with agents using LLMs that support streaming. Only the final output of the agent will be streamed. Instantiate FinalStreamingStdOutCallbackHandler. Parameters answer_prefix_tokens – Token sequence that prefixes the answer. Default is [“Final”, “Answer”, “:”] strip_tokens – Ignore white spaces and new lines when comparing answer_prefix_tokens to last tokens? (to determine if answer has been reached) stream_prefix – Should answer prefix itself also be streamed? 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__(*[, answer_prefix_tokens, ...]) Instantiate FinalStreamingStdOutCallbackHandler. append_to_last_tokens(token) check_if_answer_reached() on_agent_action(action, **kwargs) Run on agent action. on_agent_finish(finish, **kwargs) Run on agent end. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, ...) Run when LLM starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout_final_only.FinalStreamingStdOutCallbackHandler.html
c16012084ac7-1
Run when LLM starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run on new LLM token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Run on arbitrary text. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running. __init__(*, answer_prefix_tokens: Optional[List[str]] = None, strip_tokens: bool = True, stream_prefix: bool = False) → None[source]¶ Instantiate FinalStreamingStdOutCallbackHandler. Parameters answer_prefix_tokens – Token sequence that prefixes the answer. Default is [“Final”, “Answer”, “:”] strip_tokens – Ignore white spaces and new lines when comparing answer_prefix_tokens to last tokens? (to determine if answer has been reached) stream_prefix – Should answer prefix itself also be streamed? append_to_last_tokens(token: str) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout_final_only.FinalStreamingStdOutCallbackHandler.html
c16012084ac7-2
append_to_last_tokens(token: str) → None[source]¶ check_if_answer_reached() → bool[source]¶ on_agent_action(action: AgentAction, **kwargs: Any) → Any¶ Run on agent action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None¶ Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs: Any) → None¶ Run when LLM starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout_final_only.FinalStreamingStdOutCallbackHandler.html
c16012084ac7-3
Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None¶ Run on arbitrary text. on_tool_end(output: str, **kwargs: Any) → None¶ Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None¶ Run when tool starts running. Examples using FinalStreamingStdOutCallbackHandler¶ Streaming final agent output
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout_final_only.FinalStreamingStdOutCallbackHandler.html
d479d9ab30b9-0
langchain.callbacks.manager.get_openai_callback¶ langchain.callbacks.manager.get_openai_callback() → Generator[OpenAICallbackHandler, None, None][source]¶ Get the OpenAI callback handler in a context manager. which conveniently exposes token and cost information. Returns The OpenAI callback handler. Return type OpenAICallbackHandler Example >>> with get_openai_callback() as cb: ... # Use the OpenAI callback handler Examples using get_openai_callback¶ Azure Token counting Tracking token usage Run arbitrary functions
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.get_openai_callback.html
74dd0232dfac-0
langchain.callbacks.sagemaker_callback.SageMakerCallbackHandler¶ class langchain.callbacks.sagemaker_callback.SageMakerCallbackHandler(run: Any)[source]¶ Callback Handler that logs prompt artifacts and metrics to SageMaker Experiments. Parameters run (sagemaker.experiments.run.Run) – Run object where the experiment is logged. Initialize callback handler. 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__(run) Initialize callback handler. flush_tracker() Reset the steps and delete the temporary local directory. jsonf(data, data_dir, filename[, is_output]) To log the input data as json file artifact. on_agent_action(action, **kwargs) Run on agent action. on_agent_finish(finish, **kwargs) Run when agent ends running. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run when LLM generates a new token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.sagemaker_callback.SageMakerCallbackHandler.html
74dd0232dfac-1
Run when LLM starts. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Run when agent is ending. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running. __init__(run: Any) → None[source]¶ Initialize callback handler. flush_tracker() → None[source]¶ Reset the steps and delete the temporary local directory. jsonf(data: Dict[str, Any], data_dir: str, filename: str, is_output: Optional[bool] = True) → None[source]¶ To log the input data as json file artifact. on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Run when agent ends running. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.sagemaker_callback.SageMakerCallbackHandler.html
74dd0232dfac-2
Run when chain starts running. 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, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run when LLM generates a new token. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.sagemaker_callback.SageMakerCallbackHandler.html
74dd0232dfac-3
Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Run when agent is ending. on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Run when tool starts running. Examples using SageMakerCallbackHandler¶ SageMaker Tracking
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.sagemaker_callback.SageMakerCallbackHandler.html
5bcc21662fe9-0
langchain.callbacks.manager.tracing_v2_enabled¶ langchain.callbacks.manager.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[None, 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 Examples using tracing_v2_enabled¶ LangSmith Walkthrough
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.tracing_v2_enabled.html
24ba2d3086b5-0
langchain.callbacks.human.HumanApprovalCallbackHandler¶ class langchain.callbacks.human.HumanApprovalCallbackHandler(approve: ~typing.Callable[[~typing.Any], bool] = <function _default_approve>, should_check: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], bool] = <function _default_true>)[source]¶ Callback for manually validating values. 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__([approve, should_check]) 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[, parent_run_id]) Run when chain ends running. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. on_chain_start(serialized, inputs, *, run_id) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id[, parent_run_id]) Run when LLM ends running. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.human.HumanApprovalCallbackHandler.html
24ba2d3086b5-1
Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__(approve: ~typing.Callable[[~typing.Any], bool] = <function _default_approve>, should_check: ~typing.Callable[[~typing.Dict[str, ~typing.Any]], bool] = <function _default_true>)[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.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.human.HumanApprovalCallbackHandler.html
24ba2d3086b5-2
Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain ends running. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, 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 chain starts running. 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, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM ends running. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM errors. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on new LLM token. Only available when streaming is enabled. Parameters
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.human.HumanApprovalCallbackHandler.html
24ba2d3086b5-3
Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) – on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, 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 LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ 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.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.human.HumanApprovalCallbackHandler.html
24ba2d3086b5-4
Run on arbitrary text. on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when tool starts running. Examples using HumanApprovalCallbackHandler¶ Human-in-the-loop Tool Validation
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.human.HumanApprovalCallbackHandler.html
3099f09ade08-0
langchain.callbacks.manager.AsyncCallbackManagerForLLMRun¶ class langchain.callbacks.manager.AsyncCallbackManagerForLLMRun(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Async callback manager for LLM run. Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Methods __init__(*, run_id, handlers, ...[, ...]) Initialize the run manager. get_noop_manager() Return a manager that doesn't perform any operations. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, *[, chunk]) Run when LLM generates a new token. on_retry(retry_state, **kwargs) Run on a retry event. on_text(text, **kwargs) Run when text is received.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForLLMRun.html
3099f09ade08-1
on_text(text, **kwargs) Run when text is received. __init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. classmethod get_noop_manager() → BRM¶ Return a manager that doesn’t perform any operations. Returns The noop manager. Return type BaseRunManager async on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends running. Parameters response (LLMResult) – The LLM result. async on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. Parameters error (Exception or KeyboardInterrupt) – The error.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForLLMRun.html
3099f09ade08-2
Run when LLM errors. Parameters error (Exception or KeyboardInterrupt) – The error. async on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, **kwargs: Any) → None[source]¶ Run when LLM generates a new token. Parameters token (str) – The new token. async on_retry(retry_state: RetryCallState, **kwargs: Any) → None¶ Run on a retry event. async on_text(text: str, **kwargs: Any) → Any¶ Run when text is received. Parameters text (str) – The received text. Returns The result of the callback. Return type Any
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.AsyncCallbackManagerForLLMRun.html
cfe2f9e844c0-0
langchain.callbacks.manager.CallbackManagerForToolRun¶ class langchain.callbacks.manager.CallbackManagerForToolRun(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None)[source]¶ Callback manager for tool run. Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Methods __init__(*, run_id, handlers, ...[, ...]) Initialize the run manager. get_child([tag]) Get a child callback manager. get_noop_manager() Return a manager that doesn't perform any operations. on_retry(retry_state, **kwargs) Run on a retry event. on_text(text, **kwargs) Run when text is received. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForToolRun.html
cfe2f9e844c0-1
on_tool_error(error, **kwargs) Run when tool errors. __init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, inheritable_tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inheritable_metadata: Optional[Dict[str, Any]] = None) → None¶ Initialize the run manager. Parameters run_id (UUID) – The ID of the run. handlers (List[BaseCallbackHandler]) – The list of handlers. inheritable_handlers (List[BaseCallbackHandler]) – The list of inheritable handlers. parent_run_id (UUID, optional) – The ID of the parent run. Defaults to None. tags (Optional[List[str]]) – The list of tags. inheritable_tags (Optional[List[str]]) – The list of inheritable tags. metadata (Optional[Dict[str, Any]]) – The metadata. inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. get_child(tag: Optional[str] = None) → CallbackManager¶ Get a child callback manager. Parameters tag (str, optional) – The tag for the child callback manager. Defaults to None. Returns The child callback manager. Return type CallbackManager classmethod get_noop_manager() → BRM¶ Return a manager that doesn’t perform any operations. Returns The noop manager. Return type BaseRunManager on_retry(retry_state: RetryCallState, **kwargs: Any) → None¶ Run on a retry event. on_text(text: str, **kwargs: Any) → Any¶ Run when text is received. Parameters text (str) – The received text. Returns
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForToolRun.html
cfe2f9e844c0-2
Parameters text (str) – The received text. Returns The result of the callback. Return type Any on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running. Parameters output (str) – The output of the tool. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. Parameters error (Exception or KeyboardInterrupt) – The error. Examples using CallbackManagerForToolRun¶ Defining Custom Tools
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.CallbackManagerForToolRun.html
b64457ab762e-0
langchain.callbacks.base.LLMManagerMixin¶ class langchain.callbacks.base.LLMManagerMixin[source]¶ Mixin for LLM callbacks. Methods __init__() on_llm_end(response, *, run_id[, parent_run_id]) Run when LLM ends running. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. __init__()¶ on_llm_end(response: LLMResult, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when LLM errors. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) –
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.LLMManagerMixin.html
7bc8678ca13e-0
langchain.callbacks.mlflow_callback.import_mlflow¶ langchain.callbacks.mlflow_callback.import_mlflow() → Any[source]¶ Import the mlflow python package and raise an error if it is not installed.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.mlflow_callback.import_mlflow.html
6366b1cff13a-0
langchain.callbacks.tracers.base.BaseTracer¶ class langchain.callbacks.tracers.base.BaseTracer(**kwargs: Any)[source]¶ Base interface for tracers. 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) 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. 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.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.base.BaseTracer.html
6366b1cff13a-1
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]¶ 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[source]¶ End a trace for a chain run. on_chain_error(error: BaseException, *, inputs: Optional[Dict[str, Any]] = None, run_id: UUID, **kwargs: Any) → Run[source]¶ Handle an error for a chain run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.base.BaseTracer.html
6366b1cff13a-2
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[source]¶ 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[source]¶ End a trace for an LLM run. on_llm_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run[source]¶ Handle an error for an LLM run. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Run[source]¶ Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[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[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.base.BaseTracer.html
6366b1cff13a-3
Start a trace for an LLM run. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, **kwargs: Any) → Run[source]¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run[source]¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run[source]¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, **kwargs: Any) → Run[source]¶ 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[source]¶ End a trace for a tool run. on_tool_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run[source]¶ 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[source]¶ Start a trace for a tool run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.base.BaseTracer.html
98b5e8b23b97-0
langchain.callbacks.streamlit.streamlit_callback_handler.LLMThoughtState¶ class langchain.callbacks.streamlit.streamlit_callback_handler.LLMThoughtState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶ Enumerator of the LLMThought state. THINKING = 'THINKING'¶ RUNNING_TOOL = 'RUNNING_TOOL'¶ COMPLETE = 'COMPLETE'¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streamlit.streamlit_callback_handler.LLMThoughtState.html
9256af6e1b66-0
langchain.callbacks.tracers.schemas.BaseRun¶ class langchain.callbacks.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
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.BaseRun.html
9256af6e1b66-1
the new model: you should trust this data deep – set to True to make a deep copy of the model Returns new model instance dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = 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. classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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(). classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.BaseRun.html
9256af6e1b66-2
classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.BaseRun.html
447e816770b1-0
langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler¶ class langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler(pl_id_callback: Optional[Callable[[...], Any]] = None, pl_tags: Optional[List[str]] = None)[source]¶ Callback handler for promptlayer. Initialize the PromptLayerCallbackHandler. 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__([pl_id_callback, pl_tags]) Initialize the PromptLayerCallbackHandler. 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[, parent_run_id]) Run when chain ends running. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. on_chain_start(serialized, inputs, *, run_id) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id[, parent_run_id]) Run when LLM ends running. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler.html
447e816770b1-1
on_llm_start(serialized, prompts, *, run_id) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__(pl_id_callback: Optional[Callable[[...], Any]] = None, pl_tags: Optional[List[str]] = None) → None[source]¶ Initialize the PromptLayerCallbackHandler. 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, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler.html
447e816770b1-2
Run when chain ends running. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, 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 chain starts running. 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, **kwargs: Any) → Any[source]¶ Run when a chat model starts running. on_llm_end(response: LLMResult, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM errors. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) –
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler.html
447e816770b1-3
information. (containing content and other) – on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → Any[source]¶ Run when LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ 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, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler.html
447e816770b1-4
Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, *, 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 tool starts running. Examples using PromptLayerCallbackHandler¶ PromptLayer
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.promptlayer_callback.PromptLayerCallbackHandler.html
0e098d323ae6-0
langchain.callbacks.wandb_callback.WandbCallbackHandler¶ class langchain.callbacks.wandb_callback.WandbCallbackHandler(job_type: Optional[str] = None, project: Optional[str] = 'langchain_callback_demo', entity: Optional[str] = None, tags: Optional[Sequence] = None, group: Optional[str] = None, name: Optional[str] = None, notes: Optional[str] = None, visualize: bool = False, complexity_metrics: bool = False, stream_logs: bool = False)[source]¶ Callback Handler that logs to Weights and Biases. Parameters job_type (str) – The type of job. project (str) – The project to log to. entity (str) – The entity to log to. tags (list) – The tags to log. group (str) – The group to log to. name (str) – The name of the run. notes (str) – The notes to log. visualize (bool) – Whether to visualize the run. complexity_metrics (bool) – Whether to log complexity metrics. stream_logs (bool) – Whether to stream callback actions to W&B This handler will utilize the associated callback method called and formats the input of each callback function with metadata regarding the state of LLM run, and adds the response to the list of records for both the {method}_records and action. It then logs the response using the run.log() method to Weights and Biases. Initialize callback handler. Attributes always_verbose Whether to call verbose callbacks even if verbose is False. 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
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.wandb_callback.WandbCallbackHandler.html
0e098d323ae6-1
ignore_retriever Whether to ignore retriever callbacks. ignore_retry Whether to ignore retry callbacks. raise_error run_inline Methods __init__([job_type, project, entity, tags, ...]) Initialize callback handler. flush_tracker([langchain_asset, reset, ...]) Flush the tracker and reset the session. get_custom_callback_meta() on_agent_action(action, **kwargs) Run on agent action. on_agent_finish(finish, **kwargs) Run when agent ends running. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run when LLM generates a new token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Run when agent is ending.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.wandb_callback.WandbCallbackHandler.html
0e098d323ae6-2
on_text(text, **kwargs) Run when agent is ending. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running. reset_callback_meta() Reset the callback metadata. __init__(job_type: Optional[str] = None, project: Optional[str] = 'langchain_callback_demo', entity: Optional[str] = None, tags: Optional[Sequence] = None, group: Optional[str] = None, name: Optional[str] = None, notes: Optional[str] = None, visualize: bool = False, complexity_metrics: bool = False, stream_logs: bool = False) → None[source]¶ Initialize callback handler. flush_tracker(langchain_asset: Any = None, reset: bool = True, finish: bool = False, job_type: Optional[str] = None, project: Optional[str] = None, entity: Optional[str] = None, tags: Optional[Sequence] = None, group: Optional[str] = None, name: Optional[str] = None, notes: Optional[str] = None, visualize: Optional[bool] = None, complexity_metrics: Optional[bool] = None) → None[source]¶ Flush the tracker and reset the session. Parameters langchain_asset – The langchain asset to save. reset – Whether to reset the session. finish – Whether to finish the run. job_type – The job type. project – The project. entity – The entity. tags – The tags. group – The group. name – The name. notes – The notes. visualize – Whether to visualize. complexity_metrics – Whether to compute complexity metrics. Returns – None
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.wandb_callback.WandbCallbackHandler.html
0e098d323ae6-3
complexity_metrics – Whether to compute complexity metrics. Returns – None get_custom_callback_meta() → Dict[str, Any]¶ on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Run when agent ends running. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain starts running. 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, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run when LLM generates a new token. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.wandb_callback.WandbCallbackHandler.html
0e098d323ae6-4
Run when LLM starts. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Run when agent is ending. on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Run when tool starts running. reset_callback_meta() → None¶ Reset the callback metadata. Examples using WandbCallbackHandler¶ Weights & Biases
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.wandb_callback.WandbCallbackHandler.html
305467f9d8c4-0
langchain.callbacks.base.AsyncCallbackHandler¶ class langchain.callbacks.base.AsyncCallbackHandler[source]¶ Async callback handler that can be used to handle callbacks from langchain. 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__() 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[, ...]) Run when chain ends running. on_chain_error(error, *, run_id[, ...]) Run when chain errors. on_chain_start(serialized, inputs, *, run_id) Run when chain starts running. on_chat_model_start(serialized, messages, *, ...) Run when a chat model starts running. on_llm_end(response, *, run_id[, ...]) Run when LLM ends running. on_llm_error(error, *, run_id[, ...]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run on retriever end. on_retriever_error(error, *, run_id[, ...]) Run on retriever error.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.AsyncCallbackHandler.html
305467f9d8c4-1
Run on retriever error. on_retriever_start(serialized, query, *, run_id) Run on retriever start. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id, tags]) Run on arbitrary text. on_tool_end(output, *, run_id[, ...]) Run when tool ends running. on_tool_error(error, *, run_id[, ...]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__()¶ async on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run on agent action. async on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run on agent end. async on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run when chain ends running. async on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run when chain errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.AsyncCallbackHandler.html
305467f9d8c4-2
Run when chain errors. async on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None[source]¶ Run when chain starts running. async 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[source]¶ Run when a chat model starts running. async on_llm_end(response: LLMResult, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run when LLM ends running. async on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run when LLM errors. async on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run on new LLM token. Only available when streaming is enabled.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.AsyncCallbackHandler.html
305467f9d8c4-3
Run on new LLM token. Only available when streaming is enabled. async on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None[source]¶ Run when LLM starts running. async on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run on retriever end. async on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run on retriever error. async on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None[source]¶ Run on retriever start. async on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run on a retry event. async on_text(text: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run on arbitrary text.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.AsyncCallbackHandler.html
305467f9d8c4-4
Run on arbitrary text. async on_tool_end(output: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run when tool ends running. async on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, **kwargs: Any) → None[source]¶ Run when tool errors. async on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) → None[source]¶ Run when tool starts running. Examples using AsyncCallbackHandler¶ Async callbacks
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.AsyncCallbackHandler.html
6be37d193bb4-0
langchain.callbacks.infino_callback.import_infino¶ langchain.callbacks.infino_callback.import_infino() → Any[source]¶ Import the infino client.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.infino_callback.import_infino.html
e8c7f8a79b57-0
langchain.callbacks.tracers.schemas.ChainRun¶ class langchain.callbacks.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.callbacks.tracers.schemas.ChainRun] [Optional]¶ param child_execution_order: int [Required]¶ param child_llm_runs: List[langchain.callbacks.tracers.schemas.LLMRun] [Optional]¶ param child_tool_runs: List[langchain.callbacks.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
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.ChainRun.html
e8c7f8a79b57-1
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 dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = 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. classmethod from_orm(obj: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.ChainRun.html
e8c7f8a79b57-2
classmethod from_orm(obj: Any) → Model¶ json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) → unicode¶ 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(). classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod parse_obj(obj: Any) → Model¶ classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) → Model¶ classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') → DictStrAny¶ classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) → unicode¶ classmethod update_forward_refs(**localns: Any) → None¶ Try to update ForwardRefs on fields based on this Model, globalns and localns. classmethod validate(value: Any) → Model¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.schemas.ChainRun.html
94ee1baae4c9-0
langchain.callbacks.base.ChainManagerMixin¶ class langchain.callbacks.base.ChainManagerMixin[source]¶ Mixin for chain callbacks. Methods __init__() 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[, parent_run_id]) Run when chain ends running. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. __init__()¶ on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when chain ends running. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when chain errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.ChainManagerMixin.html
e4624a723d4e-0
langchain.callbacks.streaming_stdout.StreamingStdOutCallbackHandler¶ class langchain.callbacks.streaming_stdout.StreamingStdOutCallbackHandler[source]¶ Callback handler for streaming. Only works with LLMs that support streaming. 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__() on_agent_action(action, **kwargs) Run on agent action. on_agent_finish(finish, **kwargs) Run on agent end. on_chain_end(outputs, **kwargs) Run when chain ends running. on_chain_error(error, **kwargs) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts running. on_chat_model_start(serialized, messages, ...) Run when LLM starts running. on_llm_end(response, **kwargs) Run when LLM ends running. on_llm_error(error, **kwargs) Run when LLM errors. on_llm_new_token(token, **kwargs) Run on new LLM token. on_llm_start(serialized, prompts, **kwargs) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout.StreamingStdOutCallbackHandler.html
e4624a723d4e-1
Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, **kwargs) Run on arbitrary text. on_tool_end(output, **kwargs) Run when tool ends running. on_tool_error(error, **kwargs) Run when tool errors. on_tool_start(serialized, input_str, **kwargs) Run when tool starts running. __init__()¶ on_agent_action(action: AgentAction, **kwargs: Any) → Any[source]¶ Run on agent action. on_agent_finish(finish: AgentFinish, **kwargs: Any) → None[source]¶ Run on agent end. on_chain_end(outputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain ends running. on_chain_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain starts running. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs: Any) → None[source]¶ Run when LLM starts running. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends running. on_llm_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when LLM errors. on_llm_new_token(token: str, **kwargs: Any) → None[source]¶ Run on new LLM token. Only available when streaming is enabled.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout.StreamingStdOutCallbackHandler.html
e4624a723d4e-2
Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) → None[source]¶ Run when LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on a retry event. on_text(text: str, **kwargs: Any) → None[source]¶ Run on arbitrary text. on_tool_end(output: str, **kwargs: Any) → None[source]¶ Run when tool ends running. on_tool_error(error: BaseException, **kwargs: Any) → None[source]¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) → None[source]¶ Run when tool starts running. Examples using StreamingStdOutCallbackHandler¶ Anthropic 🚅 LiteLLM Ollama GPT4All Arthur
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout.StreamingStdOutCallbackHandler.html
e4624a723d4e-3
🚅 LiteLLM Ollama GPT4All Arthur Chat Over Documents with Vectara TextGen Llama.cpp Titan Takeoff Eden AI C Transformers Huggingface TextGen Inference Replicate Run LLMs locally Set env var OPENAI_API_KEY or load from a .env file Use local LLMs WebResearchRetriever
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.streaming_stdout.StreamingStdOutCallbackHandler.html
b526d9da30ed-0
langchain.callbacks.utils.import_textstat¶ langchain.callbacks.utils.import_textstat() → Any[source]¶ Import the textstat python package and raise an error if it is not installed.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.utils.import_textstat.html
f2056c8c7bc3-0
langchain.callbacks.mlflow_callback.analyze_text¶ langchain.callbacks.mlflow_callback.analyze_text(text: str, nlp: Any = None) → dict[source]¶ Analyze text using textstat and spacy. Parameters text (str) – The text to analyze. nlp (spacy.lang) – The spacy language model to use for visualization. Returns A dictionary containing the complexity metrics and visualizationfiles serialized to HTML string. Return type (dict)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.mlflow_callback.analyze_text.html
bf7d293e7a44-0
langchain.callbacks.llmonitor_callback.UserContextManager¶ class langchain.callbacks.llmonitor_callback.UserContextManager(user_id: str, user_props: Any = None)[source]¶ Methods __init__(user_id[, user_props]) __init__(user_id: str, user_props: Any = None) → None[source]¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.llmonitor_callback.UserContextManager.html
11cebbe7daba-0
langchain.callbacks.manager.collect_runs¶ langchain.callbacks.manager.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
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.manager.collect_runs.html
5ed9f121525c-0
langchain.callbacks.context_callback.ContextCallbackHandler¶ class langchain.callbacks.context_callback.ContextCallbackHandler(token: str = '', verbose: bool = False, **kwargs: Any)[source]¶ Callback Handler that records transcripts to the Context service. (https://context.ai). Keyword Arguments token (optional) – The token with which to authenticate requests to Context. Visit https://with.context.ai/settings to generate a token. If not provided, the value of the CONTEXT_TOKEN environment variable will be used. Raises ImportError – if the context-python package is not installed. Chat Example:>>> from langchain.llms import ChatOpenAI >>> from langchain.callbacks import ContextCallbackHandler >>> context_callback = ContextCallbackHandler( ... token="<CONTEXT_TOKEN_HERE>", ... ) >>> chat = ChatOpenAI( ... temperature=0, ... headers={"user_id": "123"}, ... callbacks=[context_callback], ... openai_api_key="API_KEY_HERE", ... ) >>> messages = [ ... SystemMessage(content="You translate English to French."), ... HumanMessage(content="I love programming with LangChain."), ... ] >>> chat(messages) Chain Example:>>> from langchain.chains import LLMChain >>> from langchain.chat_models import ChatOpenAI >>> from langchain.callbacks import ContextCallbackHandler >>> context_callback = ContextCallbackHandler( ... token="<CONTEXT_TOKEN_HERE>", ... ) >>> human_message_prompt = HumanMessagePromptTemplate( ... prompt=PromptTemplate( ... template="What is a good name for a company that makes {product}?", ... input_variables=["product"], ... ), ... ) >>> chat_prompt_template = ChatPromptTemplate.from_messages( ... [human_message_prompt] ... ) >>> callback = ContextCallbackHandler(token)
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.context_callback.ContextCallbackHandler.html
5ed9f121525c-1
... [human_message_prompt] ... ) >>> callback = ContextCallbackHandler(token) >>> # Note: the same callback object must be shared between the ... LLM and the chain. >>> chat = ChatOpenAI(temperature=0.9, callbacks=[callback]) >>> chain = LLMChain( ... llm=chat, ... prompt=chat_prompt_template, ... callbacks=[callback] ... ) >>> chain.run("colorful socks") 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__([token, verbose]) on_agent_action(action, *, run_id[, ...]) Run on agent action. on_agent_finish(finish, *, run_id[, ...]) Run on agent end. on_chain_end(outputs, **kwargs) Run when chain ends. on_chain_error(error, *, run_id[, parent_run_id]) Run when chain errors. on_chain_start(serialized, inputs, **kwargs) Run when chain starts. on_chat_model_start(serialized, messages, *, ...) Run when the chat model is started. on_llm_end(response, **kwargs) Run when LLM ends. on_llm_error(error, *, run_id[, parent_run_id]) Run when LLM errors. on_llm_new_token(token, *[, chunk, ...]) Run on new LLM token.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.context_callback.ContextCallbackHandler.html
5ed9f121525c-2
Run on new LLM token. on_llm_start(serialized, prompts, *, run_id) Run when LLM starts running. on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. on_retriever_start(serialized, query, *, run_id) Run when Retriever starts running. on_retry(retry_state, *, run_id[, parent_run_id]) Run on a retry event. on_text(text, *, run_id[, parent_run_id]) Run on arbitrary text. on_tool_end(output, *, run_id[, parent_run_id]) Run when tool ends running. on_tool_error(error, *, run_id[, parent_run_id]) Run when tool errors. on_tool_start(serialized, input_str, *, run_id) Run when tool starts running. __init__(token: str = '', verbose: bool = False, **kwargs: Any) → None[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], **kwargs: Any) → None[source]¶ Run when chain ends. on_chain_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.context_callback.ContextCallbackHandler.html
5ed9f121525c-3
Run when chain errors. on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) → None[source]¶ Run when chain starts. on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, **kwargs: Any) → Any[source]¶ Run when the chat model is started. on_llm_end(response: LLMResult, **kwargs: Any) → None[source]¶ Run when LLM ends. on_llm_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when LLM errors. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on new LLM token. Only available when streaming is enabled. Parameters token (str) – The new token. chunk (GenerationChunk | ChatGenerationChunk) – The new generated chunk, information. (containing content and other) – on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, 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 LLM starts running. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever ends running.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.context_callback.ContextCallbackHandler.html
5ed9f121525c-4
Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, 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 Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ 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, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool ends running. on_tool_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run when tool errors. on_tool_start(serialized: Dict[str, Any], input_str: str, *, 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 tool starts running. Examples using ContextCallbackHandler¶ Context
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.context_callback.ContextCallbackHandler.html
a12d5b5e0680-0
langchain.callbacks.tracers.langchain.log_error_once¶ langchain.callbacks.tracers.langchain.log_error_once(method: str, exception: Exception) → None[source]¶ Log an error once.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.log_error_once.html
e796b18fc09f-0
langchain.callbacks.comet_ml_callback.import_comet_ml¶ langchain.callbacks.comet_ml_callback.import_comet_ml() → Any[source]¶ Import comet_ml and raise an error if it is not installed.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.comet_ml_callback.import_comet_ml.html
558c4ff65bff-0
langchain.callbacks.base.RetrieverManagerMixin¶ class langchain.callbacks.base.RetrieverManagerMixin[source]¶ Mixin for Retriever callbacks. Methods __init__() on_retriever_end(documents, *, run_id[, ...]) Run when Retriever ends running. on_retriever_error(error, *, run_id[, ...]) Run when Retriever errors. __init__()¶ on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any[source]¶ Run when Retriever errors.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.base.RetrieverManagerMixin.html
bd42a4e24d48-0
langchain.callbacks.tracers.langchain.LangChainTracer¶ class langchain.callbacks.tracers.langchain.LangChainTracer(example_id: Optional[Union[str, UUID]] = None, project_name: Optional[str] = None, client: Optional[Client] = None, tags: Optional[List[str]] = None, use_threading: bool = True, **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__([example_id, project_name, client, ...]) Initialize the LangChain 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, *, ...) Start a trace for an LLM run. 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.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.LangChainTracer.html
bd42a4e24d48-1
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. wait_for_futures() Wait for the given futures to complete. __init__(example_id: Optional[Union[str, UUID]] = None, project_name: Optional[str] = None, client: Optional[Client] = None, tags: Optional[List[str]] = None, use_threading: bool = True, **kwargs: Any) → None[source]¶ Initialize the LangChain tracer. on_agent_action(action: AgentAction, *, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Any¶ Run on agent action.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.LangChainTracer.html
bd42a4e24d48-2
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, tags: Optional[List[str]] = None, parent_run_id: Optional[UUID] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → None[source]¶ Start a trace for an LLM run. 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¶ Handle an error for an LLM run.
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.LangChainTracer.html
bd42a4e24d48-3
Handle an error for an LLM run. on_llm_new_token(token: str, *, chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None, run_id: UUID, parent_run_id: Optional[UUID] = None, **kwargs: Any) → Run¶ Run on new LLM token. Only available when streaming is enabled. on_llm_start(serialized: Dict[str, Any], prompts: List[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 an LLM run. on_retriever_end(documents: Sequence[Document], *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever ends running. on_retriever_error(error: BaseException, *, run_id: UUID, **kwargs: Any) → Run¶ Run when Retriever errors. on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, name: Optional[str] = None, **kwargs: Any) → Run¶ Run when Retriever starts running. on_retry(retry_state: RetryCallState, *, run_id: UUID, **kwargs: Any) → 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¶
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.LangChainTracer.html
bd42a4e24d48-4
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. wait_for_futures() → None[source]¶ Wait for the given futures to complete. Examples using LangChainTracer¶ Async API
https://api.python.langchain.com/en/latest/callbacks/langchain.callbacks.tracers.langchain.LangChainTracer.html