INF-2933 item 6: isolate OpenAI SDK + simplify tool factory#53
Open
declanatinference wants to merge 10 commits into
Open
INF-2933 item 6: isolate OpenAI SDK + simplify tool factory#53declanatinference wants to merge 10 commits into
declanatinference wants to merge 10 commits into
Conversation
Drop direct `openai.AsyncOpenAI` and `agents.set_default_openai_client` imports from `engine.main`; build the per-run client via `build_async_openai_client` and pin the SDK default via `install_default_sdk_client`. The boundary module is now the single seam for OpenAI SDK / Agents SDK construction in engine.main. Tests that previously monkeypatched `engine.main.AsyncOpenAI` and `engine.main.set_default_openai_client` are repointed at the new seam (`build_async_openai_client` / `install_default_sdk_client`). The `use_for_tracing=False` invariant is now verified inside the boundary's own unit test, so the main test asserts only that the install routes through the boundary helper.
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
Lands items 6a, 6b, 6c from the INF-2933 HALO cleanup plan.
6a — single SDK boundary module. New
engine/agents/openai_sdk_client.pyre-exports the OpenAI Agents SDK and OpenAI client surface HALO uses (Agent,FunctionTool,RunConfig,RunContextWrapper,Runner,Tool,SdkToolContext,AsyncOpenAI,omit) and owns three helpers:build_async_openai_client,install_default_sdk_client(pinsuse_for_tracing=False), andis_retriable_llm_error. Eight engine modules (main.py,openai_agent_runner.py,compactor.py,engine_run_state.py,agent_context.py,synthesis_tool.py,tool_protocol.py,subagent_tool_factory.py) now go through the boundary instead of importing fromopenaioragentsdirectly.6b — drop the per-depth
make_ctxclosure.to_sdk_function_tool(tool, *, run_state, parent_context)now builds theToolContextitself per invocation. The closure that_child_tools_for_depthrebuilt at every recursion depth is gone.6c — extract subagent invocation, drop SDK
AgentAsToolInputleak. Replaced the inline ~125-lineguarded_invokeclosure with a module-level_run_subagent_invocation(plus a thin SDK-annotated wrapper that's load-bearing fortool_call_idplumbing). ReplacedAgentAsToolInput.model_validate_json(...).inputwith a localCallSubagentArgs(BaseModel)so the SDK's internal wrapper type stops leaking into HALO's call site.Stacked on PR #50 — base is
inf-2933-halo-cleanup, which GitHub will auto-retarget tomainwhen that merges. Plan and notes live underdocs/superpowers/plans/2026-05-19-inf-2933-item-6-isolate-sdk.md(gitignored).Test plan
uv run ruff check engine/ tests/— cleanuv run ruff format --check engine/ tests/— cleantask test:unit— 298 passing (288 baseline + 10 new sdk_client tests)task check— type-check pass (basedpyright kept spinning locally on an unrelated issue; will rerun on CI)task test:integration— cross-platform integration suiteNote
Medium Risk
Moderate risk because it restructures how the OpenAI client/Agents SDK are imported and initialized, and refactors tool context construction and subagent invocation paths that affect runtime execution and error-handling behavior.
Overview
Centralizes all OpenAI/Agents SDK usage behind a new boundary module
engine/agents/openai_sdk_client.py, re-exporting SDK/client symbols and adding helpers for client construction, default-client installation (alwaysuse_for_tracing=False), and retriable-error classification.Updates the engine to route SDK client creation/installation and retry logic through that boundary (including moving
_is_retriable_llm_errorout ofopenai_agent_runner.py), and refactors tool wiring soto_sdk_function_tool()buildsToolContextdirectly fromrun_state/parent_contextinstead of a per-depthcontext_factoryclosure.Simplifies subagent tooling by extracting the
call_subagentexecution into a module-level_run_subagent_invocation()and replacing the SDK-internalAgentAsToolInputdependency with a localCallSubagentArgsmodel; tests are updated and new unit coverage is added for the boundary helpers and lifecycle changes.Reviewed by Cursor Bugbot for commit 053f587. Bugbot is set up for automated code reviews on this repo. Configure here.