langchain_core.callbacks.base.BaseCallbackManager¶

class langchain_core.callbacks.base.BaseCallbackManager(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]¶

Base callback manager that handles callbacks from LangChain.

Initialize callback manager.

Attributes

is_async

Whether the callback manager 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])

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 a chat model starts running.

on_llm_start(serialized, prompts, *, run_id)

Run when LLM starts running.

on_retriever_start(serialized, query, *, run_id)

Run when Retriever starts running.

on_tool_start(serialized, input_str, *, run_id)

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[source]¶

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[source]¶

Add a handler to the callback manager.

Parameters
Return type

None

add_metadata(metadata: Dict[str, Any], inherit: bool = True) None[source]¶
Parameters
  • metadata (Dict[str, Any]) –

  • inherit (bool) –

Return type

None

add_tags(tags: List[str], inherit: bool = True) None[source]¶
Parameters
  • tags (List[str]) –

  • inherit (bool) –

Return type

None

copy() T[source]¶

Copy the callback manager.

Parameters

self (T) –

Return type

T

on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) Any¶

Run when chain starts running.

Parameters
  • serialized (Dict[str, Any]) –

  • inputs (Dict[str, Any]) –

  • run_id (UUID) –

  • parent_run_id (Optional[UUID]) –

  • tags (Optional[List[str]]) –

  • metadata (Optional[Dict[str, Any]]) –

  • kwargs (Any) –

Return type

Any

on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) Any¶

Run when a chat model starts running.

ATTENTION: This method is called for chat models. If you’re implementing

a handler for a non-chat model, you should use on_llm_start instead.

Parameters
  • serialized (Dict[str, Any]) –

  • messages (List[List[BaseMessage]]) –

  • run_id (UUID) –

  • parent_run_id (Optional[UUID]) –

  • tags (Optional[List[str]]) –

  • metadata (Optional[Dict[str, Any]]) –

  • kwargs (Any) –

Return type

Any

on_llm_start(serialized: Dict[str, Any], prompts: List[str], *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) Any¶

Run when LLM starts running.

ATTENTION: This method is called for non-chat models (regular LLMs). If

you’re implementing a handler for a chat model, you should use on_chat_model_start instead.

Parameters
  • serialized (Dict[str, Any]) –

  • prompts (List[str]) –

  • run_id (UUID) –

  • parent_run_id (Optional[UUID]) –

  • tags (Optional[List[str]]) –

  • metadata (Optional[Dict[str, Any]]) –

  • kwargs (Any) –

Return type

Any

on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs: Any) Any¶

Run when Retriever starts running.

Parameters
  • serialized (Dict[str, Any]) –

  • query (str) –

  • run_id (UUID) –

  • parent_run_id (Optional[UUID]) –

  • tags (Optional[List[str]]) –

  • metadata (Optional[Dict[str, Any]]) –

  • kwargs (Any) –

Return type

Any

on_tool_start(serialized: Dict[str, Any], input_str: str, *, run_id: UUID, parent_run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, inputs: Optional[Dict[str, Any]] = None, **kwargs: Any) Any¶

Run when tool starts running.

Parameters
  • serialized (Dict[str, Any]) –

  • input_str (str) –

  • run_id (UUID) –

  • parent_run_id (Optional[UUID]) –

  • tags (Optional[List[str]]) –

  • metadata (Optional[Dict[str, Any]]) –

  • inputs (Optional[Dict[str, Any]]) –

  • kwargs (Any) –

Return type

Any

remove_handler(handler: BaseCallbackHandler) None[source]¶

Remove a handler from the callback manager.

Parameters

handler (BaseCallbackHandler) –

Return type

None

remove_metadata(keys: List[str]) None[source]¶
Parameters

keys (List[str]) –

Return type

None

remove_tags(tags: List[str]) None[source]¶
Parameters

tags (List[str]) –

Return type

None

set_handler(handler: BaseCallbackHandler, inherit: bool = True) None[source]¶

Set handler as the only handler on the callback manager.

Parameters
Return type

None

set_handlers(handlers: List[BaseCallbackHandler], inherit: bool = True) None[source]¶

Set handlers as the only handlers on the callback manager.

Parameters
Return type

None