fix(core): fix index checking when merging lists (#32431)

**Description:** fix an issue I discovered when attempting to merge
messages in which one message has an `index` key in its content
dictionary and another does not.
This commit is contained in:
John Bledsoe 2025-08-06 12:47:33 -04:00 committed by GitHub
parent 2543007436
commit bc4251b9e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -97,7 +97,7 @@ def merge_lists(left: Optional[list], *others: Optional[list]) -> Optional[list]
to_merge = [
i
for i, e_left in enumerate(merged)
if e_left["index"] == e["index"]
if "index" in e_left and e_left["index"] == e["index"]
]
if to_merge:
# TODO: Remove this once merge_dict is updated with special

View File

@ -1019,6 +1019,11 @@ def test_tool_message_str() -> None:
("foo", [["bar"]], ["foo", "bar"]),
(["foo"], ["bar"], ["foobar"]),
(["foo"], [["bar"]], ["foo", "bar"]),
(
[{"text": "foo"}],
[[{"index": 0, "text": "bar"}]],
[{"text": "foo"}, {"index": 0, "text": "bar"}],
),
],
)
def test_merge_content(