Skip to content

Python: Keep the plugin name on Ollama assistant tool calls - #14749

Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix-ollama-tool-call-name
Open

Lanre Shittu (Shizoqua) wants to merge 1 commit into
microsoft:mainfrom
Shizoqua:fix-ollama-tool-call-name

Conversation

@Shizoqua

Copy link
Copy Markdown

Motivation and Context

Fixes #14748

The Ollama connector advertises tools by their fully qualified name, for example Weather-get_weather. When it formats an assistant message from the chat history, it sent each tool call back with only function_name (get_weather), so the tool calls in the history did not match any declared tool. This affects every follow-up request after an automatic function call to a plugin function.

Description

_format_assistant_message in connectors/ai/ollama/services/utils.py now uses tool_call.name, and falls back to tool_call.function_name when no name is set. That keeps calls built from only a function name working, which the existing test covers. The Bedrock and Google connectors already send item.name.

Added test_message_converters_assistant_tool_calls_keep_plugin_name. It fails on main with ['get_weather', 'get_time'] != ['Weather-get_weather', 'Time-get_time'] and passes with the fix.

Contribution Checklist

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.
@Shizoqua
Lanre Shittu (Shizoqua) requested a review from a team as a code owner November 8, 2026 15:09
Copilot AI balanced review requested due to automatic review settings November 8, 2026 15:09
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the change preserving plugin-qualified tool names in Ollama chat history.

No open issues 🎉

What changed in this PR

Fixes #14748 by preserving plugin-qualified tool names in Ollama assistant chat history, keeping them consistent with declared tools on follow-up requests.

Changes:

  • Uses tool_call.name, falling back to function_name when no name is set.
  • Adds regression coverage for tool calls constructed with either a qualified name or separate plugin and function names.
File Description
python/​tests/​unit/​connectors/​ai/​ollama/​services/​test_utils.py Adds regression coverage for preserving plugin-qualified tool names.
python/​semantic_kernel/​connectors/​ai/​ollama/​services/​utils.py Preserves the full tool name when formatting assistant messages.

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct. Here's what I checked.

  • name is set when it should be. FunctionCallContent.__init__ (function_call_content.py:79-85) builds name = f"{plugin_name}-{function_name}" when both parts are given. When only name is given, it splits name into the parts. So tool_call.name is the fully qualified name in both cases, and it is None only for a call built from a bare function_name, which the or tool_call.function_name fallback covers. Your test has one call of each of the first two kinds, and the existing test_message_converters_assistant_with_tool_calls covers the third.
  • It matches what's advertised. update_settings_from_function_choice_configuration in the same file sends tools through kernel_function_metadata_to_function_call_format, which uses the fully qualified name. So the history now uses the same names as the tool list.
  • The round trip. A tool call that Ollama returns as Weather-get_weather becomes FunctionCallContent(name=...) and is now sent back unchanged.
  • git merge-tree against main is clean.

I didn't run the tests.

A related gap, not for this PR: _format_tool_message (utils.py:91) sends only role and content. So with two parallel calls, the two tool results reach the model with nothing saying which call each one answers. Ollama's chat API takes an optional tool_name on tool messages for this (api.md, "Chat request (with history, with tools)"). Setting it from function_result_items[0].name would complete the pairing that this PR starts.

Reviewed with help from Claude Code.

@Shizoqua

Copy link
Copy Markdown
Author

Thanks for the review. Good point about tool_name on the tool message, I'll look at that separately.

This branch was previously deployed

1 inactive deployment
github-app-auth — c5c53ff2 Deployed Nov 8, 2026 by Shizoqua via add_label #29629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: Ollama connector drops the plugin name from assistant tool calls in chat history

3 participants