__add__() — langchain Function Reference
Architecture documentation for the __add__() function in chat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 34cb5a5b_2a5c_c35e_c787_ad9a6deabb75["__add__()"] 1418b16b_02b1_1c29_ec3f_d2c27cadc13e["ChatMessageChunk"] 34cb5a5b_2a5c_c35e_c787_ad9a6deabb75 -->|defined in| 1418b16b_02b1_1c29_ec3f_d2c27cadc13e style 34cb5a5b_2a5c_c35e_c787_ad9a6deabb75 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/chat.py lines 35–64
def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override]
if isinstance(other, ChatMessageChunk):
if self.role != other.role:
msg = "Cannot concatenate ChatMessageChunks with different roles."
raise ValueError(msg)
return self.__class__(
role=self.role,
content=merge_content(self.content, other.content),
additional_kwargs=merge_dicts(
self.additional_kwargs, other.additional_kwargs
),
response_metadata=merge_dicts(
self.response_metadata, other.response_metadata
),
id=self.id,
)
if isinstance(other, BaseMessageChunk):
return self.__class__(
role=self.role,
content=merge_content(self.content, other.content),
additional_kwargs=merge_dicts(
self.additional_kwargs, other.additional_kwargs
),
response_metadata=merge_dicts(
self.response_metadata, other.response_metadata
),
id=self.id,
)
return super().__add__(other)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does __add__() do?
__add__() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/chat.py.
Where is __add__() defined?
__add__() is defined in libs/core/langchain_core/messages/chat.py at line 35.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free