diff --git a/libs/community/langchain_community/adapters/openai.py b/libs/community/langchain_community/adapters/openai.py index 8db939d5c97..673e5fa567b 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: