[fix] parse_tool_calls: replace shared dict refs from list multiplication with independent dicts#6932
Open
NIK-TIGER-BILL wants to merge 1 commit intoagno-agi:mainfrom
Conversation
…tion with independent dicts
`[{}] * N` creates N references to the **same** dict object — a classic
Python pitfall. When any element is mutated (e.g. tool_call_entry["id"] = ...),
all N elements change simultaneously because they share the same reference.
This caused every tool call to be executed twice (or more) when the model
returned a non-zero-based `tool_call.index`, because multiple slots in the
list pointed to the same dict and all got updated together.
Fix: replace `[{}] * N` with `[{} for _ in range(N)]` so each slot gets
its own independent empty dict.
Closes agno-agi#6542
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
parse_tool_callsinlibs/agno/agno/models/openai/chat.pyuses:This is a classic Python pitfall —
[{}] * Ncreates N references to the same dict object, not N independent dicts. When any element is mutated (e.g.tool_call_entry["id"] = ...), all N elements change simultaneously through the shared reference.This causes every tool call to be executed twice (or more) when the model returns a non-zero-based
tool_call.index(e.g., Claude via OpenRouter), because multiple slots in the list end up sharing the same dict and all get updated together.Fix
Replace
[{}] * Nwith a list comprehension:Each slot now gets its own independent empty dict, so mutations to one slot do not affect others.
Verification
Closes #6542