Repository navigation
Description
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.callsmetric and theexecute_toolspan 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
- Surfaced by the
execute_toolspan work (feat(telemetry): emit execute_tool spans for tool calls #1430), which addedModelToolCall.tool_call_idbut deliberately does not attempt the data-model change. - Adjacent tool-call serialization work: Support role: "tool" / tool_call_id feedback for tool results #1389 (result-turn
tool_call_idfeedback).
Activity
ajbozarth commentedon Jul 22, 2026
@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
akihikokuroda commentedon Jul 23, 2026
@ajbozarth May I take this?
ajbozarth commentedon Jul 23, 2026
@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_idin 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
jakelorocco commentedon Jul 23, 2026
Thanks for catching this. I think there's a few concerns related to this:
ajbozarth commentedon Jul 23, 2026
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)
akihikokuroda commentedon Jul 28, 2026
A discussion is created for this #1457