Skip to content

perf(responses_api_agents): bypass HTTP self-calls in all agents - #1439

Closed
ananthsub wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
ananthsub:inprocess-self-call-perf
Closed

ananthsub wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
ananthsub:inprocess-self-call-perf

Conversation

@ananthsub

@ananthsub ananthsub commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A production agent's /run path should not send an HTTP request back to that same agent's /v1/responses endpoint. The loopback request adds an aiohttp round trip, FastAPI middleware, Pydantic validation, and socket pressure to every rollout.

This change replaces every remaining production self-call with an in-process invocation. The public responses(request, response, body) endpoint remains unchanged for external callers.

The in-process helpers preserve request-specific behavior that was added after the original implementation, including cookies, rollout-scoped URL paths and IDs, trajectory capture, retry handling, metadata, and diagnostics.

Scope

The optimization now covers:

  • simple_agent, non_executing_simple_agent, simple_agent_with_compaction, and simple_strands_agent
  • proof_refinement_agent, speed_bench_agent, browsecomp_agent, cvdp_agent, and finance_agent
  • cline_agent, kilocode_agent, openclaw_agent, opencode_agent, pi_agent, and prime_agent
  • hermes_agent, remote_agent, scicode_agent, terminus_2_agent, critpt_agent, and tool_simulation_agent
  • conversational_tool_use/simulation
  • the langgraph_agent base and its rewoo, orchestrator, parallel_thinking, and reflection implementations

Agents that already used an in-process path, including claude_code_agent, are unchanged. An audit of responses_api_agents found no remaining production posts from an agent to its own /v1/responses endpoint.

Performance

Model inference remains the dominant latency. In the original end-to-end measurements with a real OpenAI model, removing the self-call improved throughput by 7.5% for simple_agent and 13.3% for proof_refinement_agent, which performs multiple response calls per rollout. The in-process path also avoids file-descriptor pressure from loopback connections at high concurrency.

@copy-pr-bot

copy-pr-bot Bot commented May 28, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ananthsub
ananthsub force-pushed the inprocess-self-call-perf branch 2 times, most recently from ed66904 to 75473cb Compare May 28, 2026 07:36
@ananthsub
ananthsub marked this pull request as ready for review May 28, 2026 12:54
@cmunley1

Copy link
Copy Markdown
Contributor

Did you run training or benchmarks to confirm no accuracy or convergence degradation? Seems fine to me otherwise, although the logic around cookies seems to change a bit

@ananthsub
ananthsub marked this pull request as draft June 16, 2026 17:06
@ananthsub
ananthsub marked this pull request as ready for review August 31, 2026 17:18
@ananthsub
ananthsub force-pushed the inprocess-self-call-perf branch from 75473cb to 8a80d0a Compare August 31, 2026 17:18
@ananthsub ananthsub changed the title perf: bypass HTTP self-call from /run to /v1/responses perf(responses_api_agents): bypass HTTP self-calls in all agents Aug 31, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Aug 31, 2026
…sponses

Each agent's `/run` handler previously made an HTTP self-call to its own
`/v1/responses` endpoint, paying for aiohttp round-trip, FastAPI
middleware, and pydantic re-validation on every rollout. This converts
all production agents that still did this to call the implementation
in-process.

The refactor extracts the existing `responses()` body into a private
`_responses(body, cookies) -> (response, set_cookies)` helper. The
public `responses(request, response, body)` method keeps its FastAPI
signature and is now a 4-line adapter that delegates to `_responses`,
so external HTTP callers see no change. `/run` replaces the 7-line
self-call block with two lines that call `_responses` directly.

Agents converted: simple_agent, proof_refinement_agent,
non_executing_simple_agent, speed_bench_agent, cvdp_agent,
finance_agent, browsecomp_agent, hermes_agent, claude_code_agent, and
the langgraph_agent base + 4 subclasses (rewoo, orchestrator,
parallel_thinking, reflection). swe_agents, aviary_agent,
verifiers_agent, and stirrup_agent were already on this pattern.

Microbenchmark shows ~0.7-1.2 ms framework overhead per self-call at
concurrency=1, scaling to a ~70-150x rps multiplier in the
LLM-overhead-isolated case. End-to-end with a mock model: simple_agent
+25% rps / 20% wall-time reduction; proof_refinement_agent (3
self-calls per rollout) up to +2x rps / 50% wall-time reduction at
concurrency=256. With a real OpenAI model in the loop the absolute
per-rollout savings carry over (~7% rps on simple, ~13% on pref) and
the HTTP path also hit FD exhaustion at concurrency=1024 where the
in-process path did not.

Signed-off-by: Ananth Subramaniam <[email protected]>
Keep the existing in-process helper so MCP configuration, skills, rollout
identity, and observation collection remain in scope.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor Author

Tracked by the performance roadmap in #2998. This PR directly implements #3012.

@ananthsub ananthsub linked an issue Sep 3, 2026 that may be closed by this pull request
5 tasks
@ananthsub

Copy link
Copy Markdown
Contributor Author

closing in favor of environment server abstraction, which will keep this hop

@ananthsub ananthsub closed this Sep 22, 2026

This branch was previously deployed

1 inactive deployment
public — 03852a79 Deployed Sep 1, 2026 by copy-pr-bot[bot] via release / finalize / notify #2350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bypass agent loopback HTTP self-calls while preserving session behavior

2 participants