ToolMessageChunk Class — langchain Architecture
Architecture documentation for the ToolMessageChunk class in tool.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 510ca078_83fe_9544_7b8c_c24fb3386f6c["ToolMessageChunk"] 4318b819_4fe9_65b0_5369_424ec9518efe["ToolMessage"] 510ca078_83fe_9544_7b8c_c24fb3386f6c -->|extends| 4318b819_4fe9_65b0_5369_424ec9518efe 6a1cf81e_444c_4b27_c510_8e86e205cabb["BaseMessageChunk"] 510ca078_83fe_9544_7b8c_c24fb3386f6c -->|extends| 6a1cf81e_444c_4b27_c510_8e86e205cabb 510ca078_83fe_9544_7b8c_c24fb3386f6c["ToolMessageChunk"] 510ca078_83fe_9544_7b8c_c24fb3386f6c -->|extends| 510ca078_83fe_9544_7b8c_c24fb3386f6c 210f83c5_4be3_e20e_b877_98a194178520["tool.py"] 510ca078_83fe_9544_7b8c_c24fb3386f6c -->|defined in| 210f83c5_4be3_e20e_b877_98a194178520 2c9ff55b_9016_e9d4_3b38_af67972c0908["__add__()"] 510ca078_83fe_9544_7b8c_c24fb3386f6c -->|method| 2c9ff55b_9016_e9d4_3b38_af67972c0908
Relationship Graph
Source Code
libs/core/langchain_core/messages/tool.py lines 174–203
class ToolMessageChunk(ToolMessage, BaseMessageChunk):
"""Tool Message chunk."""
# Ignoring mypy re-assignment here since we're overriding the value
# to make sure that the chunk variant can be discriminated from the
# non-chunk variant.
type: Literal["ToolMessageChunk"] = "ToolMessageChunk" # type: ignore[assignment]
@override
def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override]
if isinstance(other, ToolMessageChunk):
if self.tool_call_id != other.tool_call_id:
msg = "Cannot concatenate ToolMessageChunks with different names."
raise ValueError(msg)
return self.__class__(
tool_call_id=self.tool_call_id,
content=merge_content(self.content, other.content),
artifact=merge_obj(self.artifact, other.artifact),
additional_kwargs=merge_dicts(
self.additional_kwargs, other.additional_kwargs
),
response_metadata=merge_dicts(
self.response_metadata, other.response_metadata
),
id=self.id,
status=_merge_status(self.status, other.status),
)
return super().__add__(other)
Defined In
Source
Frequently Asked Questions
What is the ToolMessageChunk class?
ToolMessageChunk is a class in the langchain codebase, defined in libs/core/langchain_core/messages/tool.py.
Where is ToolMessageChunk defined?
ToolMessageChunk is defined in libs/core/langchain_core/messages/tool.py at line 174.
What does ToolMessageChunk extend?
ToolMessageChunk extends ToolMessage, BaseMessageChunk, ToolMessageChunk.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free