fix(core): treat empty tool chunk ids as missing in merge (#35414)

This commit is contained in:
Guofang.Tang
2026-02-25 07:12:49 +08:00
committed by GitHub
parent 4ffb584ddf
commit 78678534f9
2 changed files with 31 additions and 3 deletions

View File

@@ -121,9 +121,9 @@ def merge_lists(left: list | None, *others: list | None) -> list | None:
"index" in e_left
and e_left["index"] == e["index"] # index matches
and ( # IDs not inconsistent
e_left.get("id") is None
or e.get("id") is None
or e_left["id"] == e["id"]
e_left.get("id") in (None, "")
or e.get("id") in (None, "")
or e_left.get("id") == e.get("id")
)
)
]

View File

@@ -122,6 +122,34 @@ def test_message_chunks() -> None:
],
)
assert (
AIMessageChunk(
content="",
tool_call_chunks=[
create_tool_call_chunk(name="tool1", args="", id="1", index=0)
],
)
+ AIMessageChunk(
content="",
tool_call_chunks=[
create_tool_call_chunk(name=None, args='{"arg1": "val', id="", index=0)
],
)
+ AIMessageChunk(
content="",
tool_call_chunks=[
create_tool_call_chunk(name=None, args='ue"}', id="", index=0)
],
)
) == AIMessageChunk(
content="",
tool_call_chunks=[
create_tool_call_chunk(
name="tool1", args='{"arg1": "value"}', id="1", index=0
)
],
)
assert (
AIMessageChunk(
content="",