Skip to content

feat: add ResponsesApiTransport + wire Codex build_kwargs#13430

Merged
teknium1 merged 1 commit into
mainfrom
feat/codex-transport
Apr 22, 2026
Merged

feat: add ResponsesApiTransport + wire Codex build_kwargs#13430
teknium1 merged 1 commit into
mainfrom
feat/codex-transport

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

PR 4 of the provider transport refactor (PR 1: #12975, PR 2: #13073, PR 3: #13366).

Adds the second concrete transport — ResponsesApiTransport for the Codex/Responses API — and wires all transport methods to production paths. Removes 7 dead legacy wrappers from AIAgent.

What ships

agent/transports/codex.py — ResponsesApiTransport (220 lines)

  • build_kwargs() — 50 lines of kwargs construction extracted from run_agent.py
  • normalize_response() — wraps adapter, maps to NormalizedResponse with tool call provider_data
  • convert_tools() — wraps _responses_tools()
  • convert_messages() — wraps _chat_messages_to_responses_input() (called via build_kwargs)
  • validate_response() — checks response.output with output_text fallback
  • preflight_kwargs() — request sanitization (wraps _preflight_codex_api_kwargs)
  • map_finish_reason() — completed/incomplete/failed/cancelled mapping

run_agent.py — All Codex paths wired, legacy wrappers removed

Site Method
Main build_kwargs build_kwargs()
Main normalize loop normalize_response() (with back-compat shim)
Memory flush normalize normalize_response()
Iteration-limit summary normalize_response()
Iteration-limit retry normalize_response()
Memory flush tool override convert_tools()
Response validation validate_response()
Pre-call sanitization (2 sites) preflight_kwargs()

Removed from AIAgent: 7 dead wrappers (_responses_tools, _chat_messages_to_responses_input, _normalize_codex_response, _preflight_codex_api_kwargs, _preflight_codex_input_items, _extract_responses_message_text, _extract_responses_reasoning_text). 3 ID manipulation methods kept (_deterministic_call_id, _split_responses_tool_id, _derive_responses_function_call_id) — still used by _build_assistant_message.

Tests updated: 18 call sites across 3 test files migrated from agent._method() to direct adapter function calls.

What stays on agent

  • _run_codex_stream() / _run_codex_create_stream_fallback() — streaming
  • Client construction, credential refresh, fallback routing
  • ID manipulation methods (used by shared _build_assistant_message)
  • _looks_like_codex_intermediate_ack() — agent loop heuristic

Test plan

  • 24 new transport tests
  • 343 codex/responses/transport tests pass (0 failures)
  • All pre-existing tests pass (test call sites updated)

@github-actions

Copy link
Copy Markdown
Contributor

🚨 CRITICAL Supply Chain Risk Detected

This PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging.

🚨 CRITICAL: Install-hook file added or modified

These files can execute code during package installation or interpreter startup.

Files:

hermes_cli/setup.py

Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting.

@github-actions

Copy link
Copy Markdown
Contributor

🚨 CRITICAL Supply Chain Risk Detected

This PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging.

🚨 CRITICAL: Install-hook file added or modified

These files can execute code during package installation or interpreter startup.

Files:

hermes_cli/setup.py

Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting.

Add ResponsesApiTransport wrapping codex_responses_adapter.py behind the
ProviderTransport ABC. Auto-registered via _discover_transports().

Wire ALL Codex transport methods to production paths in run_agent.py:
- build_kwargs: main _build_api_kwargs codex branch (50 lines extracted)
- normalize_response: main loop + flush + summary + retry (4 sites)
- convert_tools: memory flush tool override
- convert_messages: called internally via build_kwargs
- validate_response: response validation gate
- preflight_kwargs: request sanitization (2 sites)

Remove 7 dead legacy wrappers from AIAgent (_responses_tools,
_chat_messages_to_responses_input, _normalize_codex_response,
_preflight_codex_api_kwargs, _preflight_codex_input_items,
_extract_responses_message_text, _extract_responses_reasoning_text).
Keep 3 ID manipulation methods still used by _build_assistant_message.

Update 18 test call sites across 3 test files to call adapter functions
directly instead of through deleted AIAgent wrappers.

24 new tests. 343 codex/responses/transport tests pass (0 failures).

PR 4 of the provider transport refactor.
@github-actions

Copy link
Copy Markdown
Contributor

🚨 CRITICAL Supply Chain Risk Detected

This PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging.

🚨 CRITICAL: Install-hook file added or modified

These files can execute code during package installation or interpreter startup.

Files:

hermes_cli/setup.py

Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants