on_chat_model_start() — langchain Function Reference
Architecture documentation for the on_chat_model_start() function in langchain.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 68b325b2_a4ee_6bd3_7e65_01239a5c497c["on_chat_model_start()"] 178590bb_85ff_b79e_979a_46e5c3c5389f["LangChainTracer"] 68b325b2_a4ee_6bd3_7e65_01239a5c497c -->|defined in| 178590bb_85ff_b79e_979a_46e5c3c5389f 1a52c867_8259_f52c_1ade_c23b7b18c690["_start_trace()"] 68b325b2_a4ee_6bd3_7e65_01239a5c497c -->|calls| 1a52c867_8259_f52c_1ade_c23b7b18c690 1f28ee91_49f8_e93f_e967_a9380e8e96a7["_on_chat_model_start()"] 68b325b2_a4ee_6bd3_7e65_01239a5c497c -->|calls| 1f28ee91_49f8_e93f_e967_a9380e8e96a7 style 68b325b2_a4ee_6bd3_7e65_01239a5c497c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/tracers/langchain.py lines 152–196
def on_chat_model_start(
self,
serialized: dict[str, Any],
messages: list[list[BaseMessage]],
*,
run_id: UUID,
tags: list[str] | None = None,
parent_run_id: UUID | None = None,
metadata: dict[str, Any] | None = None,
name: str | None = None,
**kwargs: Any,
) -> Run:
"""Start a trace for an LLM run.
Args:
serialized: The serialized model.
messages: The messages.
run_id: The run ID.
tags: The tags.
parent_run_id: The parent run ID.
metadata: The metadata.
name: The name.
**kwargs: Additional keyword arguments.
Returns:
The run.
"""
start_time = datetime.now(timezone.utc)
if metadata:
kwargs.update({"metadata": metadata})
chat_model_run = Run(
id=run_id,
parent_run_id=parent_run_id,
serialized=serialized,
inputs={"messages": [[dumpd(msg) for msg in batch] for batch in messages]},
extra=kwargs,
events=[{"name": "start", "time": start_time}],
start_time=start_time,
run_type="llm",
tags=tags,
name=name,
)
self._start_trace(chat_model_run)
self._on_chat_model_start(chat_model_run)
return chat_model_run
Domain
Subdomains
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/tracers/langchain.py.
Where is on_chat_model_start() defined?
on_chat_model_start() is defined in libs/core/langchain_core/tracers/langchain.py at line 152.
What does on_chat_model_start() call?
on_chat_model_start() calls 2 function(s): _on_chat_model_start, _start_trace.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free