CallbackManagerForToolRun#

class langchain_core.callbacks.manager.CallbackManagerForToolRun(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: UUID | None = None, tags: List[str] | None = None, inheritable_tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, inheritable_metadata: Dict[str, Any] | None = 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. Defaults to None.

  • inheritable_tags (Optional[List[str]]) – The list of inheritable tags. Defaults to None.

  • metadata (Optional[Dict[str, Any]]) – The metadata. Defaults to None.

  • inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Defaults to None.

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_custom_event(name,Β data,Β *,Β run_id[,Β ...])

Override to define a handler for a custom event.

on_retry(retry_state,Β **kwargs)

Run when a retry is received.

on_text(text,Β **kwargs)

Run when a text is received.

on_tool_end(output,Β **kwargs)

Run when the tool ends running.

on_tool_error(error,Β **kwargs)

Run when tool errors.

__init__(*, run_id: UUID, handlers: List[BaseCallbackHandler], inheritable_handlers: List[BaseCallbackHandler], parent_run_id: UUID | None = None, tags: List[str] | None = None, inheritable_tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, inheritable_metadata: Dict[str, Any] | None = 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. Defaults to None.

  • inheritable_tags (Optional[List[str]]) – The list of inheritable tags. Defaults to None.

  • metadata (Optional[Dict[str, Any]]) – The metadata. Defaults to None.

  • inheritable_metadata (Optional[Dict[str, Any]]) – The inheritable metadata. Defaults to None.

Return type:

None

get_child(tag: str | None = 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_custom_event(name: str, data: Any, *, run_id: UUID, tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, **kwargs: Any) β†’ Any#

Override to define a handler for a custom event.

Parameters:
  • name (str) – The name of the custom event.

  • data (Any) – The data for the custom event. Format will match the format specified by the user.

  • run_id (UUID) – The ID of the run.

  • tags (List[str] | None) – The tags associated with the custom event (includes inherited tags).

  • metadata (Dict[str, Any] | None) – The metadata associated with the custom event (includes inherited metadata).

  • kwargs (Any) –

Return type:

Any

New in version 0.2.15.

on_retry(retry_state: RetryCallState, **kwargs: Any) β†’ None#

Run when a retry is received.

Parameters:
  • retry_state (RetryCallState) – The retry state.

  • **kwargs (Any) – Additional keyword arguments.

Return type:

None

on_text(text: str, **kwargs: Any) β†’ Any#

Run when a text is received.

Parameters:
  • text (str) – The received text.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

The result of the callback.

Return type:

Any

on_tool_end(output: Any, **kwargs: Any) β†’ None[source]#

Run when the tool ends running.

Parameters:
  • output (Any) – The output of the tool.

  • **kwargs (Any) – Additional keyword arguments.

Return type:

None

on_tool_error(error: BaseException, **kwargs: Any) β†’ None[source]#

Run when tool errors.

Parameters:
  • error (Exception or KeyboardInterrupt) – The error.

  • **kwargs (Any) – Additional keyword arguments.

Return type:

None

Examples using CallbackManagerForToolRun