Skip to content

Reduce startup and per-turn overhead for ordinary agent runs - #6224

Draft
markstuart-oai wants to merge 2 commits into
mainfrom
perf/reduce-python-runner-overhead
Draft

markstuart-oai wants to merge 2 commits into
mainfrom
perf/reduce-python-runner-overhead

Conversation

@markstuart-oai

Copy link
Copy Markdown
Contributor

Summary

This pull request reduces the time to an agent's first answer and the work each later turn performs. Ordinary runs have been importing the sandbox implementation, loading the parser for tools without docstrings, and scheduling hooks with no user code to run. The runner now waits until it needs those imports, skips known empty work, and avoids inspecting the signature of an unchanged SDK-owned tool invoker.

Runs with parallel input guardrails keep the original scheduling so immediate rejections can stop provider entry. Each run uses its own guardrail state. Overlapping runs skip comparing a tool tuple to itself and still check assignments.

Custom prompt getters and user hooks keep their task and cancellation boundaries. Hook factories still run in order, so one can replace a later hook. Replaced invokers and invokers with custom signature metadata still use reflection. Sandbox cleanup preserves saved session state when a run resumes without a sandbox configuration.

Performance

The Python client has been staying fixed at its main revision in this 24-block comparison.

One tool, two model replies Main This change Paired reduction
Process launch to first answer 674.8 ms 565.5 ms 15.4% (95% interval 12.9–18.1%)
Warm median 1.669 ms 1.277 ms 23.3% (95% interval 23.1–24.0%)
Warm 95th percentile 1.738 ms 1.338 ms 22.9% (95% interval 22.7–23.5%)

Timing only the first call after setup has been showing a small cost, from 4.74 to 4.94 ms (paired +3.89%, 95% interval +1.59% to +5.76%). The launch-to-answer result includes that call.

Across 83 Codex-off comparisons, 82 medians have been meeting the 3% slowdown limit. One result remains inconclusive. No interval lies wholly above the limit. The comparison combines both Python changes against openai/openai-agents-python at 6afdd47b and openai/openai-python at 66266569. It cannot isolate the effect of either PR. Each row uses 32 primary pairs. In 4 prespecified or uncertain rows, the reported estimate uses 64 new pairs without pooling samples.

The 32-stream workload has been taking 355.4 ms per batch against 410.3 ms on main (paired −12.79%, 95% interval −13.52% to −12.29%). The large SQLite write has been remaining inconclusive (48.92 to 49.35 ms, paired +1.98%, interval −1.11% to +3.83%). The small write has been meeting the margin on confirmation (−4.56%, interval −7.61% to +0.09%). Building an agent with 12 tools and dictionary settings has been taking 51.7 to 52.5 µs (+1.07%, interval +0.80% to +1.92%). A separate 256-request burst with 32 ordinary requests at a time has been showing a real tail cost for the combined changes. The median has been falling from 11.86 to 7.40 ms, while p95 has been rising from 13.15 to 59.55 ms in all 32 pairs.

A separate 128-block test has been synchronizing four writers using separate databases on the same storage on another host. The large write has been showing +0.009% (95% interval −0.030% to +0.052%), close to the comparisons between identical builds. The small write has been showing +0.81% (−0.67% to +3.48%). All 11,776 committed-data checks have been passing. This control leaves the original 83 results intact.

When callers can wait longer

In four separately instrumented pairs of the short burst above, each process has been doing one full garbage collection. It has been overlapping 5 of 256 requests on main and 25 or 26 with the changes. That moves the pause across the 95th percentile. In six fresh pairs starting directly with the burst, p95 has been falling from 49.12 to 35.51 ms. In six longer pairs with the original preceding work and 4,096 requests, p95 has been falling from 57.97 to 43.52 ms. The original short-window loss matters for workloads with that request history. No collector settings have been changing.

Documented tools still pay the parser cost when declared. Sandbox users pay for the implementation at first use. In a separate local sandbox test on an earlier version, execution has been taking 1.57 ms longer while script start through the checked answer has been falling from 659 to 629 ms. With both SDK changes and explicit aiohttp, the first adapter call after setup has been taking 132.1 ms against 96.7 ms, while launch through the answer has been falling from 851.1 to 736.1 ms. Separate traces on an earlier version have been locating a full collection inside that first call.

A separate 12-block Responses adapter run has been keeping the Agents testing package unloaded. Launch to answer has been taking 852.8 ms on both mains, 676.4 ms with only the Agents change and 674.0 ms with both changes. Warm medians have been taking 5.089, 4.678 and 3.671 ms respectively. This checks that the application benefit survives removal of the test helper imports. Responses have been using an intercepted transport without live inference.

All 83 comparisons with both Python changes and Codex off

Each row reports a median in milliseconds. The paired percentage uses within-pair ratios, so it can differ from the ratio of the displayed medians. When a row has 64 pairs, the table uses the independent confirmation. The two SQLite rows have been writing 2 items of 256 characters and 1,024 items of 4,096 characters. The 32 concurrent ordinary requests and the 32 concurrent streams have separate rows. The short-burst p95 falls outside these medians. The cold_normal and cold_stream rows time the run after imports and fixture setup. The process-launch measurement above includes both.

Suite Workload Main ms Both changes ms Paired change 95% interval Pairs
archived_holdouts cold_normal 64.426 61.758 -4.35% -5.03% to -2.91% 32
archived_holdouts cold_stream 259.78 242.58 -6.77% -9.06% to -5.28% 32
archived_holdouts ids_17x32769 68.066 65.027 -3.93% -4.61% to -1.69% 32
archived_holdouts ids_17x32769_stream 91.406 84.614 -7.79% -9.27% to -6.53% 32
archived_holdouts ids_3x8193 5.7447 4.8384 -16.02% -16.81% to -15.09% 32
archived_holdouts ids_3x8193_stream 8.0181 6.999 -12.79% -13.16% to -11.81% 32
archived_holdouts reuse_normal 38.783 38.254 -1.87% -4.18% to -0.56% 32
archived_holdouts reuse_stream 39.975 39.393 -1.22% -3.31% to +0.41% 32
archived_holdouts typed_3x257 5.5834 5.3571 -5.22% -6.21% to -3.28% 32
archived_holdouts typed_3x257_stream 7.0601 6.1027 -13.72% -14.85% to -12.41% 32
round1 add_tool 1.7158 1.3035 -24.27% -24.44% to -24.00% 32
round1 build_dict_12 0.051716 0.052452 +1.07% +0.80% to +1.92% 32
round1 build_omitted_12 0.069718 0.070001 +0.37% -0.17% to +1.38% 32
round1 build_typed_12 0.038884 0.038865 -0.00% -0.62% to +0.51% 32
round1 con1 0.49985 0.34304 -32.10% -33.52% to -30.39% 32
round1 32 concurrent ordinary requests 11.856 7.4002 -38.12% -38.65% to -37.35% 32
round1 con8 2.8859 2.0035 -30.82% -31.23% to -30.35% 32
round1 diag_32 12.018 7.3393 -38.99% -39.51% to -38.26% 32
round1 h128 1.2553 1.0949 -12.73% -12.99% to -12.23% 32
round1 handoffs_0 0.50605 0.34686 -31.84% -33.94% to -30.14% 32
round1 handoffs_12 0.7154 0.57527 -19.84% -20.08% to -18.65% 32
round1 history120 0.93131 0.78017 -16.19% -16.75% to -15.56% 32
round1 history2000 6.1862 6.022 -2.60% -3.24% to -1.84% 32
round1 history720 2.6756 2.5154 -6.18% -6.66% to -5.86% 32
round1 mixed_6 0.72115 0.6124 -15.07% -15.40% to -14.40% 32
round1 nested67_stream16 73.713 69.132 -6.35% -7.01% to -5.97% 32
round1 repeat_8 0.99012 0.88827 -10.21% -10.92% to -9.85% 32
round1 retained_16384 0.19738 0.19918 +0.07% -0.27% to +0.60% 32
round1 retained_2048 0.029487 0.029228 -0.75% -1.09% to -0.38% 32
round1 run_dict_6 0.77385 0.63052 -18.53% -19.17% to -18.44% 32
round1 run_omitted_6 0.82787 0.68395 -17.14% -17.61% to -16.95% 32
round1 run_typed_6 0.74513 0.59694 -19.88% -20.21% to -19.17% 32
round1 schemas_24 0.85975 0.71884 -16.29% -16.73% to -15.86% 32
round1 server_1 1.796 1.3869 -22.86% -23.32% to -22.49% 32
round1 server_1024 20.983 20.376 -2.38% -3.11% to -1.68% 32
round1 server_128 4.3569 3.9281 -9.31% -10.54% to -8.59% 32
round1 server_512 11.403 10.858 -4.79% -5.49% to -3.70% 32
round1 single_0 0.50048 0.33047 -34.33% -34.75% to -33.25% 32
round1 single_12 0.5986 0.44654 -25.19% -26.47% to -24.52% 32
round1 stream 0.78425 0.61071 -22.26% -22.61% to -21.65% 32
round1 sustained_32 11.823 7.2339 -38.63% -38.95% to -38.34% 32
round1 Large SQLite write 48.923 49.348 +1.98% -1.11% to +3.83% 64
round1 time_16384_2 0.40213 0.39668 -1.46% -1.94% to -0.65% 32
round1 time_2048_2 0.057975 0.057933 -0.14% -0.34% to +0.26% 32
round1 Small SQLite write 6.2549 5.9762 -4.56% -7.61% to +0.09% 64
round1 time_4096_8 0.4325 0.42575 -1.43% -2.28% to +0.01% 32
round1 tools1 1.6155 1.1966 -25.99% -26.42% to -25.71% 32
round1 tools16 19.239 15.083 -21.50% -21.77% to -21.01% 32
round1 tools4 4.5589 3.4511 -24.24% -24.43% to -24.02% 32
round1 warm 0.48 0.33118 -31.34% -32.32% to -29.77% 32
round2 batch-compare 1x1024 21.133 20.647 -2.17% -2.56% to -1.71% 32
round2 batch-compare 2x32 3.6859 3.0396 -17.48% -17.76% to -17.26% 32
round2 bulk-live 12x64 16.542 13.316 -19.43% -19.82% to -19.10% 32
round2 bulk-live 1x1024 20.854 20.392 -1.83% -2.59% to -1.30% 32
round2 bulk-live 1x2048 39.774 39.003 -1.91% -2.29% to -1.23% 32
round2 bulk-live 1x256 6.783 6.361 -6.44% -6.82% to -6.11% 32
round2 combo5 4x1024 44.359 43.052 -3.06% -3.91% to -2.15% 32
round2 combo5 8x128 36.398 34.181 -6.48% -6.73% to -5.76% 32
round2 32 concurrent streams 410.35 355.36 -12.79% -13.52% to -12.29% 64
round2 first-final 1x0 1594.4 1328 -16.48% -17.75% to -15.76% 32
round2 first-mcp 1x0 1594.7 1324.9 -16.72% -17.27% to -15.91% 32
round2 lists-final 1x1024 5.2867 4.3683 -17.68% -18.47% to -17.15% 32
round2 lists-final 8x8192 35.039 29.91 -15.22% -16.39% to -13.23% 32
round2 provider-final 1x2048 262.47 198.95 -24.45% -24.94% to -23.82% 32
round2 provider-final 1x4096 520.25 393.8 -24.27% -24.59% to -23.93% 32
round2 quote-final 1x1 1.7077 1.3208 -22.74% -23.25% to -22.43% 32
round2 quote-final 1x64 2.5888 2.2281 -14.11% -14.57% to -13.90% 32
round2 quote-final 8x16 11.485 9.4046 -18.41% -18.82% to -17.89% 32
round2 quote-final 8x256 37.156 34.993 -5.92% -6.15% to -5.31% 32
round2 quote-final 8x64 16.791 14.808 -11.95% -12.20% to -11.77% 32
round2 shape-local normal 12x96 35.032 31.428 -9.62% -10.30% to -9.28% 32
round2 shape-local stream 12x96 56.48 52.891 -6.46% -6.90% to -6.23% 32
round2 shape-local stream 4x12 11.586 10.262 -10.86% -12.24% to -10.26% 32
round2 shape-local stream 8x0 14.341 12.286 -14.20% -14.72% to -13.82% 32
round2 tail 4x1024 43.686 42.403 -2.74% -3.35% to -2.55% 64
round2 values-final ids 1x1 1.6622 1.284 -22.88% -23.62% to -22.57% 32
round2 values-final ids 8x8192 13.483 10.796 -19.98% -20.56% to -17.74% 32
round2 values-final last 4x512 6.0543 4.9802 -17.88% -17.97% to -17.51% 32
round2 values-final records 8x512 11.234 9.1382 -18.66% -19.13% to -18.23% 32
round2 values-final typed 16x1024 27.245 23.335 -14.01% -14.90% to -13.43% 32
round2 values-final typed 4x128 5.0662 3.9724 -21.54% -21.89% to -20.89% 32
round2 warm-control 1x0 1.7102 1.3124 -23.28% -23.66% to -22.89% 32
round2 warm-control 1x4096 34.927 34.557 -1.34% -2.11% to -0.75% 32

Test plan

The repository's full verification script has been passing on the reviewed files. The parallel test phase has been reporting 12,819 passes and 26 skips. The separate serial phase has been reporting 107 passes and four skips. Format, lint, mypy and Pyright have been passing. The focused run has been passing 1,738 tests with two skips, including overlapping runs, mutation, cancellation, saved state and first imports. Across 100 guardrail timing checks, model entry and rejection order have been matching main. A second run with the proposed client wheel installed has been passing the same parallel and serial suites. All 326 Agents source files and 2,090 client source files have been matching the benchmarked versions.

The timings have been using deterministic local replies, with two model calls, one tool execution, and checks on the final answer and history. The cold clock starts at process launch. The warm clock covers calls 101 through 800 in each fresh process. These measurements exclude external network and model inference time.

Issue number

No linked issue.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • Two independent reviewers have checked the final diff under the repository’s high-risk review procedure.

class CustomAgent(Agent):
guard_instruction_access: bool = False

def __getattribute__(self, name: str) -> Any:
from .capabilities.memory import Memory
from .memory.manager import SandboxMemoryGenerationManager
from .memory.rollouts import RolloutTerminalMetadata
from .runtime_session_manager import SandboxRuntimeSessionManager

This branch has not been deployed

No deployments
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.

1 participant