langchain_core.callbacks.manager
.CallbackManagerForChainRun¶
- class langchain_core.callbacks.manager.CallbackManagerForChainRun(*, 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 chain 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.
Return a manager that doesn't perform any operations.
on_agent_action
(action, **kwargs)Run when agent action is received.
on_agent_finish
(finish, **kwargs)Run when agent finish is received.
on_chain_end
(outputs, **kwargs)Run when chain ends running.
on_chain_error
(error, **kwargs)Run when chain errors.
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.
- __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. 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: 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
- classmethod get_noop_manager() BRM ¶
Return a manager that doesn’t perform any operations.
- Returns
The noop manager.
- Return type
- on_agent_action(action: AgentAction, **kwargs: Any) Any [source]¶
Run when agent action is received.
- Parameters
action (AgentAction) – The agent action.
**kwargs (Any) – Additional keyword arguments.
- Returns
The result of the callback.
- Return type
Any
- on_agent_finish(finish: AgentFinish, **kwargs: Any) Any [source]¶
Run when agent finish is received.
- Parameters
finish (AgentFinish) – The agent finish.
**kwargs (Any) – Additional keyword arguments.
- Returns
The result of the callback.
- Return type
Any
- on_chain_end(outputs: Union[Dict[str, Any], Any], **kwargs: Any) None [source]¶
Run when chain ends running.
- Parameters
outputs (Union[Dict[str, Any], Any]) – The outputs of the chain.
**kwargs (Any) – Additional keyword arguments.
- Return type
None
- on_chain_error(error: BaseException, **kwargs: Any) None [source]¶
Run when chain errors.
- Parameters
error (Exception or KeyboardInterrupt) – The error.
**kwargs (Any) – Additional keyword arguments.
- Return type
None
- on_custom_event(name: str, data: Any, *, run_id: UUID, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = 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 (Optional[List[str]]) – The tags associated with the custom event (includes inherited tags).
metadata (Optional[Dict[str, Any]]) – 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