perf(simple-agent): avoid deep request copies - #3049
Open
ananthsub wants to merge 1 commit into
Open
Conversation
Copy only the request model shell because episode construction rebinds input without mutating nested request values. Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
4 tasks
cmunley1
reviewed
Sep 3, 2026
| [{"role": "user", "content": [{"type": "input_text", "text": "question"}]}], | ||
| ), | ||
| ) | ||
| async def test_create_episode_does_not_mutate_request(self, input_value) -> None: |
Contributor
There was a problem hiding this comment.
Should this also test tool call, incomplete response, nested tool schema, failure paths?
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.
Summary
body.input, which the episode code rebinds rather than mutating in placePerformance
An in-process benchmark alternated deep and shallow Pydantic copies over nine repeats. Copy time fell from 10.365 to 0.677 microseconds for a one-message request and from 1.031 milliseconds to 0.697 microseconds for a synthetic 512-message request. This isolates episode-start request copying; model, tool, and network time are unchanged.
Test plan
uv run --extra dev pytest -q responses_api_agents/simple_agent/tests/test_app.pyCloses #3010.
Parent roadmap: #2998.