Skip to content

bug: Ollama provider sets toolUseId to tool name instead of unique ID #2050

@Ratansairohith

Description

@Ratansairohith

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

  1. Create an agent with the Ollama provider and multiple tools
  2. Give a prompt that causes the model to call the same tool twice in one turn
  3. The second tool result will have the same toolUseId as 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions