Skip to content

perf(simple-agent): avoid deep request copies - #3049

Open
ananthsub wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/perf-simple-agent-shallow-copy
Open

perf(simple-agent): avoid deep request copies#3049
ananthsub wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/perf-simple-agent-shallow-copy

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

Summary

  • replace the full recursive request copy at episode start with a shallow Pydantic model copy
  • retain isolation for body.input, which the episode code rebinds rather than mutating in place
  • cover both string and structured-list inputs and verify that the caller's complete request remains unchanged

Performance

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.py
  • scoped pre-commit checks for changed files

Closes #3010.
Parent roadmap: #2998.

Copy only the request model shell because episode construction rebinds input without mutating nested request values.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
[{"role": "user", "content": [{"type": "input_text", "text": "question"}]}],
),
)
async def test_create_episode_does_not_mutate_request(self, input_value) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also test tool call, incomplete response, nested tool schema, failure paths?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid deep-copying the full request in simple_agent

2 participants