Repository navigation
Conversation
Strix Security ReviewWarning This pull request has 37 commits after the last Strix review ( ✅ No open security findings. PR summary: PR #9588 makes `Agent.copy()` isolate LLM state: after the shallow copy of the LLM it deep-copies `additional_params` and `_token_usage` so a copied agent no longer shares or mutates the original's provider parameters and token totals, while deliberately keeping the HTTP client shared. A regression test asserts the two dicts are independent after copying. Review summaryThe change is a seven-line state-isolation fix inside Ruled out (2)
Review 1 on this PR · Reviewed by Strix |
| # copied agent actually mutates: provider params and token totals. | ||
| if getattr(existing_llm, "additional_params", None) is not None: | ||
| existing_llm.additional_params = deepcopy(existing_llm.additional_params) | ||
| if getattr(existing_llm, "_token_usage", None) is not None: |
There was a problem hiding this comment.
- The copied
_token_usagekeeps the original's counts. Resetting it to zero inbase_agent.py:739would keepkickoff_for_eachusage totals right when the source LLM was already used.
There was a problem hiding this comment.
Addressed in 33a489c. A copied agent's _token_usage is now a fresh zeroed dict, so kickoff_for_each no longer adds the source LLM's existing counts once per input. The test sets the original total to 10 and checks the copy starts at 0.
There was a problem hiding this comment.
Re-pushed bda2b9e with no change to the fix. It only merges main so the pip-audit check is green.
Related issue
Fixes #9587
Summary
Agent.copy() copied the LLM with copy.copy, so additional_params and
_token_usage stayed shared with the original agent. Deep-copy those two
dicts after the shallow copy, and leave the HTTP client in place.
Verification
uv run pytest lib/crewai/tests/agents/test_agent.py::test_agent_copy_isolates_llm_mutable_state -q --allowed-hosts=127.0.0.1
Additional context
Local mypy on Windows reports pre-existing errors in unrelated files
(fcntl, pwd, python_calamine). Those names exist on the Ubuntu CI runner.