Repository navigation
Reduce startup and per-turn overhead for ordinary agent runs - #6224
Draft
markstuart-oai wants to merge 2 commits into
Draft
markstuart-oai wants to merge 2 commits into
markstuart-oai wants to merge 2 commits into
Conversation
| 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
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
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.
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
6afdd47band openai/openai-python at66266569. 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.
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
.agents/skills/code-change-verification/scripts/run.sh