Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions libs/core/langchain_core/messages/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ def content_blocks(self) -> list[types.ContentBlock]:
"name": tool_call["name"],
"args": tool_call["args"],
}
if "index" in tool_call:
tool_call_block["index"] = tool_call["index"] # type: ignore[typeddict-item]
if "extras" in tool_call:
tool_call_block["extras"] = tool_call["extras"] # type: ignore[typeddict-item]
blocks.append(tool_call_block)
tool_call_dict = cast("dict[str, Any]", tool_call_block)
tool_call_as_dict = cast("dict[str, Any]", tool_call)
if "index" in tool_call_as_dict:
tool_call_dict["index"] = tool_call_as_dict["index"]
if "extras" in tool_call_as_dict:
tool_call_dict["extras"] = tool_call_as_dict["extras"]
blocks.append(cast("types.ToolCall", tool_call_dict))

# Best-effort reasoning extraction from additional_kwargs
# Only add reasoning if not already present
Expand Down Expand Up @@ -582,7 +584,8 @@ def add_chunk_to_invalid_tool_calls(chunk: ToolCallChunk) -> None:
self.content[idx] = cast("dict[str, Any]", id_to_tc[call_id])
if "extras" in block:
# mypy does not account for instance check for dict above
self.content[idx]["extras"] = block["extras"] # type: ignore[index]
content_item = cast("dict[str, Any]", self.content[idx])
content_item["extras"] = block["extras"]

return self

Expand All @@ -609,8 +612,9 @@ def init_server_tool_calls(self) -> Self:
try:
args = json.loads(args_str)
if isinstance(args, dict):
self.content[idx]["type"] = "server_tool_call" # type: ignore[index]
self.content[idx]["args"] = args # type: ignore[index]
content_item = cast("dict[str, Any]", self.content[idx])
content_item["type"] = "server_tool_call"
content_item["args"] = args
except json.JSONDecodeError:
pass
return self
Expand Down
Loading