From c5c53ff274187b8e45608734d0592fa564a859c9 Mon Sep 17 00:00:00 2001 From: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com> Date: Sun, 8 Nov 2026 13:24:47 +0000 Subject: [PATCH] Python: Keep the plugin name on Ollama assistant tool calls The Ollama connector advertises tools by their fully qualified name (for example "Weather-get_weather"), but when it formats an assistant message from the chat history it sent each tool call back with only function_name ("get_weather"). The tool calls in the history then did not match any declared tool. Use the fully qualified name, and fall back to function_name when no name is set, the same way the other connectors do. --- .../connectors/ai/ollama/services/utils.py | 2 +- .../connectors/ai/ollama/services/test_utils.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/semantic_kernel/connectors/ai/ollama/services/utils.py b/python/semantic_kernel/connectors/ai/ollama/services/utils.py index 9745a4063484..414116fcbd75 100644 --- a/python/semantic_kernel/connectors/ai/ollama/services/utils.py +++ b/python/semantic_kernel/connectors/ai/ollama/services/utils.py @@ -76,7 +76,7 @@ def _format_assistant_message(message: ChatMessageContent) -> Message: assistant_message["tool_calls"] = [ { "function": { - "name": tool_call.function_name, + "name": tool_call.name or tool_call.function_name, "arguments": tool_call.arguments if isinstance(tool_call.arguments, Mapping) else json.loads(tool_call.arguments or "{}"), diff --git a/python/tests/unit/connectors/ai/ollama/services/test_utils.py b/python/tests/unit/connectors/ai/ollama/services/test_utils.py index a4829f4f858d..7c19398d7ad9 100644 --- a/python/tests/unit/connectors/ai/ollama/services/test_utils.py +++ b/python/tests/unit/connectors/ai/ollama/services/test_utils.py @@ -166,6 +166,20 @@ def test_message_converters_assistant_with_tool_calls() -> None: ) +def test_message_converters_assistant_tool_calls_keep_plugin_name() -> None: + """Test assistant tool calls are sent back with the fully qualified name used in the tool definitions.""" + tool_call_1 = FunctionCallContent(name="Weather-get_weather", arguments={"city": "Paris"}) + tool_call_2 = FunctionCallContent(plugin_name="Time", function_name="get_time", arguments='{"zone": "Tokyo"}') + content = ChatMessageContent(role=AuthorRole.ASSISTANT, items=[tool_call_1, tool_call_2]) + + result = MESSAGE_CONVERTERS[AuthorRole.ASSISTANT](content) + + assert [tool_call["function"]["name"] for tool_call in result["tool_calls"]] == [ + "Weather-get_weather", + "Time-get_time", + ] + + def test_message_converters_tool_with_result() -> None: """Test tool message with a FunctionResultContent, verifying the message content is set.""" # Arrange