Skip to content

The agent engineering platform.

community: [fix] add missing tool_calls kwargs of delta message in openai adapter (#27492)

Wang621f78babd03
diff --git a/libs/community/langchain_community/adapters/openai.py b/libs/community/langchain_community/adapters/openai.py
index 8db939d5c9..673e5fa567 100644
--- a/libs/community/langchain_community/adapters/openai.py
+++ b/libs/community/langchain_community/adapters/openai.py
@@ -180,6 +180,12 @@ def _convert_message_chunk(chunk: BaseMessageChunk, i: int) -> dict:
# not missing, but None.
if i == 0:
_dict["content"] = None
+ if "tool_calls" in chunk.additional_kwargs:
+ _dict["tool_calls"] = chunk.additional_kwargs["tool_calls"]
+ # If the first chunk is tool calls, the content is not empty string,
+ # not missing, but None.
+ if i == 0:
+ _dict["content"] = None
else:
_dict["content"] = chunk.content
else: