langchain_core.callbacks.manager.AsyncCallbackManagerForLLMRun¶

class langchain_core.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.

__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.

  • kwargs (Any) –

    Additional keyword arguments. - response (LLMResult): The response which was generated before

    the error occurred.

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