-
Notifications
You must be signed in to change notification settings - Fork 766
bug: Ollama provider sets toolUseId to tool name instead of unique ID #2050
Description
Description
In OllamaModel.format_chunk, the toolUseId is set to the tool name rather than a unique identifier.
src/strands/models/ollama.py, line 249:
return {"contentBlockStart": {"start": {"toolUse": {"name": tool_name, "toolUseId": tool_name}}}}When the model calls the same tool twice in one turn (e.g. two parallel searches), both calls get toolUseId="search". The SDK uses toolUseId to match results back to calls, so the second result overwrites the first.
There is a second issue at line 127 in format_request:
"name": content["toolUse"]["toolUseId"],This sends the toolUseId (which is already the tool name) as the function name back to Ollama. It works by accident since both are the same string, but it's reading the wrong field.
Other providers (OpenAI, Anthropic, Bedrock) use actual unique IDs from their APIs (tool_call.id, event.id, etc.).
Reproduction
- Create an agent with the Ollama provider and multiple tools
- Give a prompt that causes the model to call the same tool twice in one turn
- The second tool result will have the same
toolUseIdas the first
Suggested fix
Generate a unique ID when Ollama doesn't provide one:
import uuid
tool_use_id = f"tooluse_{uuid.uuid4().hex[:24]}"
return {"contentBlockStart": {"start": {"toolUse": {"name": tool_name, "toolUseId": tool_use_id}}}}And fix line 127 to use name instead of toolUseId:
"name": content["toolUse"]["name"],Happy to submit a PR for this.