core[patch]: return ToolMessage from tools when tool call ID is empty string (#29921)

This commit is contained in:
Vadym Barda 2025-02-21 11:53:15 -05:00 committed by GitHub
parent 5ee8a8f063
commit 437fe6d216
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -960,7 +960,7 @@ def _format_output(
name: str,
status: str,
) -> Union[ToolOutputMixin, Any]:
if isinstance(content, ToolOutputMixin) or not tool_call_id:
if isinstance(content, ToolOutputMixin) or tool_call_id is None:
return content
if not _is_message_content_type(content):
content = _stringify(content)

View File

@ -2457,3 +2457,14 @@ def test_simple_tool_args_schema_dict() -> None:
assert tool.args == {
"a": {"title": "A", "type": "integer"},
}
def test_empty_string_tool_call_id() -> None:
@tool
def foo(x: int) -> str:
"""Foo."""
return "hi"
assert foo.invoke({"type": "tool_call", "args": {"x": 0}, "id": ""}) == ToolMessage(
content="hi", name="foo", tool_call_id=""
)