langchain_core.callbacks.manager
.AsyncCallbackManager¶
- class langchain_core.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.
- Parameters
handlers (List[BaseCallbackHandler]) –
inheritable_handlers (Optional[List[BaseCallbackHandler]]) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
inheritable_tags (Optional[List[str]]) –
metadata (Optional[Dict[str, Any]]) –
inheritable_metadata (Optional[Dict[str, Any]]) –
- __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.
- Parameters
handlers (List[BaseCallbackHandler]) –
inheritable_handlers (Optional[List[BaseCallbackHandler]]) –
parent_run_id (Optional[UUID]) –
tags (Optional[List[str]]) –
inheritable_tags (Optional[List[str]]) –
metadata (Optional[Dict[str, Any]]) –
inheritable_metadata (Optional[Dict[str, Any]]) –
- Return type
None
- add_handler(handler: BaseCallbackHandler, inherit: bool = True) None ¶
Add a handler to the callback manager.
- Parameters
handler (BaseCallbackHandler) –
inherit (bool) –
- Return type
None
- add_metadata(metadata: Dict[str, Any], inherit: bool = True) None ¶
- Parameters
metadata (Dict[str, Any]) –
inherit (bool) –
- Return type
None
- add_tags(tags: List[str], inherit: bool = True) None ¶
- Parameters
tags (List[str]) –
inherit (bool) –
- Return type
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 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
- copy() T ¶
Copy the callback manager.
- Parameters
self (T) –
- Return type
T
- 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.
kwargs (Any) –
- Returns
- The async callback manager
for the chain run.
- Return type
- 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.
kwargs (Any) –
- Returns
- The list of
async callback managers, one for each LLM Run corresponding to each inner message list.
- Return type
- async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) List[AsyncCallbackManagerForLLMRun] [source]¶
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.
kwargs (Any) –
- Returns
- The list of async
callback managers, one for each LLM Run corresponding to each prompt.
- Return type
- 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.
- Parameters
serialized (Dict[str, Any]) –
query (str) –
run_id (Optional[UUID]) –
parent_run_id (Optional[UUID]) –
kwargs (Any) –
- Return type
- 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.
kwargs (Any) –
- Returns
- The async callback manager
for the tool run.
- Return type
- remove_handler(handler: BaseCallbackHandler) None ¶
Remove a handler from the callback manager.
- Parameters
handler (BaseCallbackHandler) –
- Return type
None
- remove_metadata(keys: List[str]) None ¶
- Parameters
keys (List[str]) –
- Return type
None
- remove_tags(tags: List[str]) None ¶
- Parameters
tags (List[str]) –
- Return type
None
- set_handler(handler: BaseCallbackHandler, inherit: bool = True) None ¶
Set handler as the only handler on the callback manager.
- Parameters
handler (BaseCallbackHandler) –
inherit (bool) –
- Return type
None
- set_handlers(handlers: List[BaseCallbackHandler], inherit: bool = True) None ¶
Set handlers as the only handlers on the callback manager.
- Parameters
handlers (List[BaseCallbackHandler]) –
inherit (bool) –
- Return type
None