diff --git a/python/packages/core/agent_framework/_types.py b/python/packages/core/agent_framework/_types.py index 52df892130e..a91f3203848 100644 --- a/python/packages/core/agent_framework/_types.py +++ b/python/packages/core/agent_framework/_types.py @@ -1546,7 +1546,7 @@ def _add_function_call_content(self, other: Content) -> Content: return Content( "function_call", call_id=self_call_id, - name=getattr(self, "name", getattr(other, "name", None)), + name=getattr(self, "name", None) or getattr(other, "name", None), arguments=arguments, exception=getattr(self, "exception", None) or getattr(other, "exception", None), informational_only=getattr(self, "informational_only", False) diff --git a/python/packages/core/tests/core/test_types.py b/python/packages/core/tests/core/test_types.py index 40c7081e092..bb67f936fed 100644 --- a/python/packages/core/tests/core/test_types.py +++ b/python/packages/core/tests/core/test_types.py @@ -570,6 +570,21 @@ def test_function_call_content_add_merging_and_errors(): with raises(ContentError): _ = a + b + # name merging: when the first chunk has no name (e.g. a streaming delta where + # the function name arrives later), the merged content must keep the name from + # whichever side provides it, regardless of order. + # A nameless delta is constructed via Content(...) directly (the factory + # from_function_call requires name: str); this mirrors how a streaming + # function-call delta with no name yet is represented. + a = Content("function_call", call_id="1", name=None, arguments='{"a":') + b = Content.from_function_call(call_id="1", name="get_weather", arguments="1}") + assert (a + b).name == "get_weather" + assert (b + a).name == "get_weather" + # both sides missing a name stays None + a = Content("function_call", call_id="1", name=None, arguments="") + b = Content("function_call", call_id="1", name=None, arguments="") + assert (a + b).name is None + # region FunctionResultContent