on_chat_model_start() — langchain Function Reference
Architecture documentation for the on_chat_model_start() function in manager.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD fd9cf5b0_df49_0a9e_1f92_c0f24cb802a3["on_chat_model_start()"] 90ea8982_7d84_5e8f_4b5a_533f89fc7211["AsyncCallbackManager"] fd9cf5b0_df49_0a9e_1f92_c0f24cb802a3 -->|defined in| 90ea8982_7d84_5e8f_4b5a_533f89fc7211 a6207573_f43a_6004_ebfd_c9da6a0f2d8f["on_chat_model_start()"] a6207573_f43a_6004_ebfd_c9da6a0f2d8f -->|calls| fd9cf5b0_df49_0a9e_1f92_c0f24cb802a3 a6207573_f43a_6004_ebfd_c9da6a0f2d8f["on_chat_model_start()"] fd9cf5b0_df49_0a9e_1f92_c0f24cb802a3 -->|calls| a6207573_f43a_6004_ebfd_c9da6a0f2d8f 3a243d21_72d1_dca9_f7be_acbb482b9f86["ahandle_event()"] fd9cf5b0_df49_0a9e_1f92_c0f24cb802a3 -->|calls| 3a243d21_72d1_dca9_f7be_acbb482b9f86 style fd9cf5b0_df49_0a9e_1f92_c0f24cb802a3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/callbacks/manager.py lines 1873–1942
async def on_chat_model_start(
self,
serialized: dict[str, Any],
messages: list[list[BaseMessage]],
run_id: UUID | None = None,
**kwargs: Any,
) -> list[AsyncCallbackManagerForLLMRun]:
"""Async run when LLM starts running.
Args:
serialized: The serialized LLM.
messages: The list of messages.
run_id: The ID of the run.
**kwargs: Additional keyword arguments.
Returns:
The list of async callback managers, one for each LLM run corresponding to
each inner message list.
"""
inline_tasks = []
non_inline_tasks = []
managers = []
for message_list in messages:
if run_id is not None:
run_id_ = run_id
run_id = None
else:
run_id_ = uuid7()
for handler in self.handlers:
task = ahandle_event(
[handler],
"on_chat_model_start",
"ignore_chat_model",
serialized,
[message_list],
run_id=run_id_,
parent_run_id=self.parent_run_id,
tags=self.tags,
metadata=self.metadata,
**kwargs,
)
if handler.run_inline:
inline_tasks.append(task)
else:
non_inline_tasks.append(task)
managers.append(
AsyncCallbackManagerForLLMRun(
run_id=run_id_,
handlers=self.handlers,
inheritable_handlers=self.inheritable_handlers,
parent_run_id=self.parent_run_id,
tags=self.tags,
inheritable_tags=self.inheritable_tags,
metadata=self.metadata,
inheritable_metadata=self.inheritable_metadata,
)
)
# Run inline tasks sequentially
for task in inline_tasks:
await task
# Run non-inline tasks concurrently
if non_inline_tasks:
await asyncio.gather(*non_inline_tasks)
return managers
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does on_chat_model_start() do?
on_chat_model_start() is a function in the langchain codebase, defined in libs/core/langchain_core/callbacks/manager.py.
Where is on_chat_model_start() defined?
on_chat_model_start() is defined in libs/core/langchain_core/callbacks/manager.py at line 1873.
What does on_chat_model_start() call?
on_chat_model_start() calls 2 function(s): ahandle_event, on_chat_model_start.
What calls on_chat_model_start()?
on_chat_model_start() is called by 1 function(s): on_chat_model_start.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free