perf: reduce unnecessary deepcopies in Agent#10704
Merged
anakin87 merged 4 commits intodeepset-ai:mainfrom Mar 6, 2026
Merged
Conversation
Replace deepcopy of state_schema with shallow dict copy since only top-level keys are modified. Remove deepcopy of agent_inputs for span tags since the dict is freshly created and only used for tracing.
|
@Br1an67 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
anakin87
requested changes
Mar 4, 2026
Member
anakin87
left a comment
There was a problem hiding this comment.
Based on my investigation, these deepcopies can be safely removed.
Nice PR.
I only left some minor comments to be addressed.
releasenotes/notes/reduce-agent-deepcopies-2fc601301180d190.yaml
Outdated
Show resolved
Hide resolved
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
anakin87
approved these changes
Mar 6, 2026
Member
anakin87
left a comment
There was a problem hiding this comment.
Looks good!
I only added the explanatory comments.
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.
Related Issues
Proposed Changes:
Reduced unnecessary
deepcopycalls in theAgentcomponent for improved performance:state_schema(init): Replaced_deepcopy_with_exceptions(self._state_schema)with a shallowdict()copy. The only modification to the resolved schema is adding/overwriting the top-level"messages"key — nested values are never mutated, so a shallow copy is sufficient to keepself._state_schemaandself.state_schemaseparate.agent_inputsspan tags (run/run_async): Removed_deepcopy_with_exceptions(agent_inputs)when setting span content tags. Theagent_inputsdict is freshly created just before the span tag and is not referenced or mutated elsewhere — it exists solely for tracing purposes.How did you test it?
pytest test/components/agents/test_agent.py— all 51 non-async tests pass.test_run_async_falls_back_to_run_when_chat_generator_has_no_run_async) is unrelated (missingpytest-asyncioin local env) and also fails on the unmodifiedmainbranch.Notes for the reviewer
_deepcopy_with_exceptionsfromhaystack.core.pipeline.utilsis no longer used inagent.pyafter these changes.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.