Repository navigation
Python: Keep the plugin name on Ollama assistant tool calls - #14749
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
🟢 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 tofunction_namewhen 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
Muhammad Abdullah Butt (1AbdullahButt)
left a comment
There was a problem hiding this comment.
Looks correct. Here's what I checked.
nameis set when it should be.FunctionCallContent.__init__(function_call_content.py:79-85) buildsname = f"{plugin_name}-{function_name}"when both parts are given. When onlynameis given, it splitsnameinto the parts. Sotool_call.nameis the fully qualified name in both cases, and it isNoneonly for a call built from a barefunction_name, which theor tool_call.function_namefallback covers. Your test has one call of each of the first two kinds, and the existingtest_message_converters_assistant_with_tool_callscovers the third.- It matches what's advertised.
update_settings_from_function_choice_configurationin the same file sends tools throughkernel_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_weatherbecomesFunctionCallContent(name=...)and is now sent back unchanged. git merge-treeagainstmainis 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.
|
Thanks for the review. Good point about tool_name on the tool message, I'll look at that separately. |
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 onlyfunction_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_messageinconnectors/ai/ollama/services/utils.pynow usestool_call.name, and falls back totool_call.function_namewhen 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 senditem.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