Python: fix(ollama): send the tool name on tool result messages - #8815
Conversation
Function results don't carry the tool name, so every tool message was sent to Ollama with tool_name=''. Look the name up from the function call with the same call_id.
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 502f7d5ddb44
Model: gpt-5.6-sol-fast
Overview
The PR correctly derives Ollama's required tool name from function-call history, preserves result ordering, and adds coverage for reordered results with distinct IDs. Fresh UUIDs mitigate the issue for ordinary Ollama-originated calls, but the conversation-global lookup breaks valid replayed or caller-supplied histories when a call_id is reused across completed occurrences. That residual correlation defect can send historical tool output under the wrong tool identity.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/ollama/agent_framework_ollama/_chat_client.py
…s keep the right name
Eduard van Valkenburg (eavanvalkenburg)
left a comment
There was a problem hiding this comment.
Anish Mehta (@anishmehta24) Thanks — the reused call_id occurrence fix and regression address the prior review feedback, the dedicated review found no additional issues, and all reported checks are green.
Motivation & Context
OllamaChatClient._format_tool_messagesetstool_namefromgetattr(item, "name", ""), but function result content has noname(Content.from_function_resultonly takes thecall_id). So in a normal tool-calling run every tool message goes to Ollama with an empty tool name:Ollama's chat API has no tool call ids, so
tool_nameis the only thing tying a result back to the tool that produced it, and the model templates use it when rendering tool results.Description & Review Guide
_prepare_messages_for_ollamabuilds acall_id -> namemap from the function calls in the conversation and passes it to_format_tool_message, which uses it when the result item has no name of its own.Related Issue
No existing issue.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.Test:
test_tool_message_gets_name_from_matching_function_callinpackages/ollama/tests/test_ollama_chat_client.py; it fails on main. The ollama tests pass (38 passed, 5 skipped), and ruff check/format and pyright are clean.