mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 21:08:59 +00:00
anthropic[patch]: correctly handle tool msg with empty list (#27109)
This commit is contained in:
parent
4935a14314
commit
1e768a9ec7
@ -118,9 +118,13 @@ def _merge_messages(
|
|||||||
for curr in messages:
|
for curr in messages:
|
||||||
curr = curr.model_copy(deep=True)
|
curr = curr.model_copy(deep=True)
|
||||||
if isinstance(curr, ToolMessage):
|
if isinstance(curr, ToolMessage):
|
||||||
if isinstance(curr.content, list) and all(
|
if (
|
||||||
isinstance(block, dict) and block.get("type") == "tool_result"
|
isinstance(curr.content, list)
|
||||||
for block in curr.content
|
and curr.content
|
||||||
|
and all(
|
||||||
|
isinstance(block, dict) and block.get("type") == "tool_result"
|
||||||
|
for block in curr.content
|
||||||
|
)
|
||||||
):
|
):
|
||||||
curr = HumanMessage(curr.content) # type: ignore[misc]
|
curr = HumanMessage(curr.content) # type: ignore[misc]
|
||||||
else:
|
else:
|
||||||
|
@ -162,6 +162,13 @@ def test__merge_messages() -> None:
|
|||||||
"text": None,
|
"text": None,
|
||||||
"name": "blah",
|
"name": "blah",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"tool_input": {"a": "c"},
|
||||||
|
"type": "tool_use",
|
||||||
|
"id": "3",
|
||||||
|
"text": None,
|
||||||
|
"name": "blah",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
ToolMessage("buz output", tool_call_id="1", status="error"), # type: ignore[misc]
|
ToolMessage("buz output", tool_call_id="1", status="error"), # type: ignore[misc]
|
||||||
@ -178,6 +185,7 @@ def test__merge_messages() -> None:
|
|||||||
],
|
],
|
||||||
tool_call_id="2",
|
tool_call_id="2",
|
||||||
), # type: ignore[misc]
|
), # type: ignore[misc]
|
||||||
|
ToolMessage([], tool_call_id="3"), # type: ignore[misc]
|
||||||
HumanMessage("next thing"), # type: ignore[misc]
|
HumanMessage("next thing"), # type: ignore[misc]
|
||||||
]
|
]
|
||||||
expected = [
|
expected = [
|
||||||
@ -201,6 +209,13 @@ def test__merge_messages() -> None:
|
|||||||
"text": None,
|
"text": None,
|
||||||
"name": "blah",
|
"name": "blah",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"tool_input": {"a": "c"},
|
||||||
|
"type": "tool_use",
|
||||||
|
"id": "3",
|
||||||
|
"text": None,
|
||||||
|
"name": "blah",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
HumanMessage( # type: ignore[misc]
|
HumanMessage( # type: ignore[misc]
|
||||||
@ -226,6 +241,12 @@ def test__merge_messages() -> None:
|
|||||||
"tool_use_id": "2",
|
"tool_use_id": "2",
|
||||||
"is_error": False,
|
"is_error": False,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "tool_result",
|
||||||
|
"content": [],
|
||||||
|
"tool_use_id": "3",
|
||||||
|
"is_error": False,
|
||||||
|
},
|
||||||
{"type": "text", "text": "next thing"},
|
{"type": "text", "text": "next thing"},
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user