Skip to content

Duplicate same-name parallel tool calls collapse to a single execution #1431

Closed

Description

@ajbozarth

Summary

When a model requests the same tool more than once in a single response (parallel tool calling — e.g. search({"q": "X"}) and search({"q": "Y"}) in one turn), Mellea executes only the last call and silently drops the rest.

Root cause

Model tool calls are stored in a dict keyed by tool name:

  • ModelOutputThunk.tool_calls: dict[str, ModelToolCall] (mellea/core/base.py)
  • Populated per backend via model_tool_calls[tool_name] = ModelToolCall(...):
    • mellea/helpers/openai_compatible_helpers.py (OpenAI-compatible, LiteLLM, Watsonx)
    • mellea/backends/ollama.py

Because the key is the tool name, a second call to the same name overwrites the first before execution. _acall_tools (mellea/stdlib/functional.py) then iterates the collapsed dict, so the tool runs once and produces a single ToolMessage. The dropped call's result never returns to the model.

This dates to the initial commit and predates parallel tool calling being common; the "one call per tool name per turn" assumption is no longer valid for current OpenAI/Anthropic-style APIs.

Impact

  • Correctness (primary): parallel calls to the same tool with different arguments lose all but the last. Affects tool execution and the messages fed back to the model — not just observability.
  • Observability (symptom): the mellea.tool.calls metric and the execute_tool span each fire once instead of N times. This faithfully reflects that only one call executed — the telemetry is correct about a broken execution. No telemetry code needs to change.

Suggested fix

Key tool calls by the provider-supplied call id rather than by name. ModelToolCall.tool_call_id (added in #1430) is the field a fix would key on. This is a data-model change (dict[str, ModelToolCall] → keyed by call id, or a list) touching core/base.py and all four backend extraction sites; no telemetry code needs to change — the correct span/metric cardinality falls out automatically once execution stops collapsing.

Related

Activity

  1. added
    bug
    area/tools
    on Jul 22, 2026
  2. ajbozarth commented on Jul 22, 2026

    @ajbozarth
    MemberAuthor

    @jakelorocco I found this while working on telemetry and it feels like a pretty big gap on first glance. I don't know if this is something we want to jump up the priorities or if it's just a back log item. I also don't know if I should mark it need design or good first issue

  3. akihikokuroda commented on Jul 23, 2026

    @akihikokuroda
    Contributor

    @ajbozarth May I take this?

  4. ajbozarth commented on Jul 23, 2026

    @ajbozarth
    MemberAuthor

    @akihikokuroda feel free, but I'm not 100% sure of the direction @jakelorocco wants us to go with it. Also if we decide to leverage ModelToolCall.tool_call_id in the solution it would be blocked on #1430 that surfaces it.

    I wasn't planning to pick it up myself though, so feel free to drive that discussion and design

  5. jakelorocco commented on Jul 23, 2026

    @jakelorocco
    Contributor

    Thanks for catching this. I think there's a few concerns related to this:

    1. ensuring all tool requests are fulfilled; this could be implemented by changing from a dict to set (I'm not sure if there are second order issues with this) and/or using the id. It seems like the id would be the best longterm solution.
    2. ensuring we only append a single tool with any given name
    3. ensuring components differentiate their tool calls (feat: add prefix to component tool names #1432 (comment)).
  6. ajbozarth commented on Jul 23, 2026

    @ajbozarth
    MemberAuthor

    It seems like the id would be the best longterm solution.

    worth noting that ModelToolCall.tool_call_id surfaces the id from the provider, and not all providers do so (Ollama never does). So if we do leverage it we'd need a solid fallback mechanic that doesn't break provider sourced id's (see my comment on #1389)

  7. akihikokuroda commented on Jul 28, 2026

    @akihikokuroda
    Contributor

    A discussion is created for this #1457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/toolsbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions