Repository navigation
Conversation
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.
Description
CodeActAgent.__init__modifies thetoolslist owned by the caller.Summary
CodeActAgentappends its internalexecutetool to thetoolsargument it is given. When that argument is a non-empty list, the list is aliased rather than copied, so the caller's list is modified in place.Why (root cause)
llama-index-core/llama_index/core/agent/workflow/codeact_agent.py:98tools or []evaluates to the caller's list object whenever that list is non-empty — the[]fallback is only constructed whentoolsisNoneor empty. Theappendon the next line therefore writes into the caller's list.Consequence: a tool list shared between agent instances gains one duplicate
executetool per construction:Changes
codeact_agent.py:98— copy the incoming sequence into a new list before appending:tools = [*(tools or [])]. This uses the same copy idiom already present in this module (base_agent.py:277,multi_agent_workflow.py:253).tests/agent/workflow/test_code_act_agent.py— addtest_code_act_agent_does_not_mutate_caller_tools, asserting the caller's list still holds only the tool it was given and that the agent itself receives both the caller tool andexecute.Testing
Red — test added,
codeact_agent.pyreverted toorigin/main:Green — fix applied:
AI usage disclosure
Per CONTRIBUTING.md ("How to Use AI when Contributing" — Transparency), AI assistance was used to draft the one-line change and the regression test. Verification: I reproduced the failure against unmodified
origin/main, confirmed the assertion passes with the change, and ran the fulltests/agent/suite,mypy llama_index, and the pre-commit hooks on the changed files locally. Both files are small and fully reviewed.New Package?
Version Bump?
llama-index-core)Type of Change
How Has This Been Tested?
Suggested Checklist
No linked issue — this is a self-contained bug fix found by reading the
CodeActAgentconstructor; I could not find a matching open issue or PR.