Pin OpenAI Agents SDK to chat-completions API#54
Closed
inf-quantavius wants to merge 1 commit into
Closed
Conversation
The SDK defaults to the Responses API (``/v1/responses``), which the
OpenAI-compatible providers HALO targets (Inference.net, OpenRouter,
vLLM, …) do not implement; only api.openai.com itself does. When the
live ``test_call_subagent_through_sdk_adapter_live`` integration test
spun up a subagent against the dev gateway, the SDK's Responses
streaming hit the gateway and got back a closed connection, surfacing
as ``APIConnectionError`` and zero turns used.
Fix: call ``set_default_openai_api("chat_completions")`` at engine run
start in ``stream_engine_async`` (so production is portable across the
OpenAI-compatible ecosystem) and in ``tests/conftest.py``'s
``pytest_configure`` (so test paths that invoke tool factories
directly via ``wired_tools``, without going through
``stream_engine_async``, inherit the same default). Real OpenAI
supports both APIs, so this is a strict superset.
Regression guard: ``test_engine_pins_sdk_to_chat_completions_api``
asserts ``stream_engine_async`` invokes ``set_default_openai_api`` with
``"chat_completions"`` exactly once.
Contributor
Author
|
Heads up — I cannot trigger the live integration workflow myself: (or just click Run workflow and pick Local evidence the fix lands the SDK on the right API path: with the change in place, the e2e tests' stack trace now goes through |
francescov1
pushed a commit
that referenced
this pull request
May 23, 2026
…bal default PR #50 ("Isolate the OpenAI Agents SDK") replaced an env-var-driven configure_default_sdk_client(provider) with an unconditional set_default_openai_client(client, use_for_tracing=False) inside stream_engine_async. That works in production (where every Runner.run_streamed goes through that entrypoint) but breaks tests that invoke the call_subagent tool directly via tests/integration/tool_isolation_kit.wired_tools — those never enter stream_engine_async, so the SDK default stays None and OpenAIProvider lazy-constructs its own AsyncOpenAI from OPENAI_BASE_URL / OPENAI_API_KEY env vars, dropping default_headers and any deterministic close path. test_call_subagent_through_sdk_adapter_live started failing on 2026-05-22 with `APIConnectionError: Connection error.` raised mid-stream against a request that never left the runner. Fix: pass model_provider=OpenAIProvider(openai_client=client) on every RunConfig the engine constructs. This makes prod and tests symmetric — both paths now wire HALO's configured AsyncOpenAI to the SDK explicitly, no global state, no env-var fallback. The engine still owns the client's lifecycle (constructed in stream_engine_async, closed in its finally; the wired_tools test path owns its own instance). Bonus: removes a layer of SDK global state, which was already a footgun for callers running multiple engines / multiple test modules in one process. Closes the regression that motivated the (now-closed) workaround PR #54. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
The OpenAI Agents SDK defaults to the Responses API (
/v1/responses), which the OpenAI-compatible providers HALO targets (Inference.net, OpenRouter, vLLM, …) do not implement; only api.openai.com does. The live integration testtest_call_subagent_through_sdk_adapter_livestarted failing because the SDK posted to/v1/responseson the dev gateway, which closed the connection mid-stream — surfacing asAPIConnectionError: Connection error.andturns_used=0.Sister live test
test_synthesize_traces_through_sdk_adapter_livekeeps passing because it bypasses the SDK and callsclient.chat.completions.create()directly.Fix:
engine/main.py: callset_default_openai_api(\"chat_completions\")next to the existingset_default_openai_client(...)so HALO production is portable across the OpenAI-compatible ecosystem out of the box. Real OpenAI supports both APIs, so chat-completions is a strict superset.tests/conftest.py: same call inpytest_configure, so the live integration tests that invoke tool factories directly viawired_tools(and never enterstream_engine_async) inherit the same default.tests/unit/test_main.py: regression guardtest_engine_pins_sdk_to_chat_completions_api.Failing run for reference: https://github.com/context-labs/HALO/actions/runs/26316222866/job/77475862061
Test plan
Note
Medium Risk
Changes the OpenAI Agents SDK process-global default endpoint selection, which could affect all SDK calls at runtime, but is a small, targeted compatibility fix backed by tests.
Overview
Pins the OpenAI Agents SDK to use the
chat_completionsAPI instead of the default Responses API to ensure HALO works with OpenAI-compatible providers that don’t implement/v1/responses.The engine now calls
set_default_openai_api("chat_completions")alongsideset_default_openai_client(...), tests pin the same default inpytest_configurefor integration paths that bypass engine startup, and a new unit test guards the expected API selection.Reviewed by Cursor Bugbot for commit 978b651. Bugbot is set up for automated code reviews on this repo. Configure here.