CallbackManagerForLLMRun#
- class langchain_core.callbacks.manager.CallbackManagerForLLMRun(*, 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 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. 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.
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_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 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: 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
- classmethod get_noop_manager() BRM #
Return a manager that doesn’t perform any operations.
- Returns:
The noop manager.
- Return type:
- 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
Added in version 0.2.15.
- on_llm_end(response: LLMResult, **kwargs: Any) None [source]#
Run when LLM ends running.
- Parameters:
response (LLMResult) – The LLM result.
**kwargs (Any) – Additional keyword arguments.
- Return type:
None
- on_llm_error(error: BaseException, **kwargs: Any) None [source]#
Run when LLM errors.
- Parameters:
error (Exception or KeyboardInterrupt) – The error.
kwargs (Any) –
Additional keyword arguments. - response (LLMResult): The response which was generated before
the error occurred.
- Return type:
None
- on_llm_new_token(token: str, *, chunk: GenerationChunk | ChatGenerationChunk | None = None, **kwargs: Any) None [source]#
Run when LLM generates a new token.
- Parameters:
token (str) – The new token.
chunk (Optional[Union[GenerationChunk, ChatGenerationChunk]], optional) – The chunk. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Return type:
None
- 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