Skip to content

refactor: extract codex_responses logic into dedicated adapter#13018

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-91e86ae2
Apr 20, 2026
Merged

refactor: extract codex_responses logic into dedicated adapter#13018
teknium1 merged 1 commit into
mainfrom
hermes/hermes-91e86ae2

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Extract 12 Codex Responses API format-conversion and normalization functions from run_agent.py into agent/codex_responses_adapter.py.

run_agent.py: 12,550 → 11,865 lines (-685 lines)

Changes

  • agent/codex_responses_adapter.py (new, 813 lines): All 12 stateless functions extracted as module-level functions
  • run_agent.py (-685 lines): Thin one-line wrappers delegate to adapter; two module-level helpers re-exported for backward compat

What moved

Function Purpose
_chat_content_to_responses_parts Multimodal content conversion (PR #12969)
_summarize_user_message_for_log Multimodal message logging
_deterministic_call_id Cache-safe fallback IDs
_split_responses_tool_id Composite ID splitting
_derive_responses_function_call_id fc_ prefix conversion
_responses_tools Schema format conversion
_chat_messages_to_responses_input Message format conversion (with multimodal)
_preflight_codex_input_items Input validation (with multimodal)
_preflight_codex_api_kwargs API kwargs validation
_extract_responses_message_text Response text extraction
_extract_responses_reasoning_text Reasoning extraction
_normalize_codex_response Full response normalization

Design

  • Follows existing pattern: anthropic_adapter.py, bedrock_adapter.py
  • All callers (tests, gateway, CLI) are completely unchanged
  • Backward-compat re-exports from run_agent so existing from run_agent import _chat_content_to_responses_parts still works

Validation

Suite Result
-k 'codex or responses' 241 passed, 1 skipped
test_run_agent_multimodal_prologue.py 15 passed
py_compile Both files pass

Salvaged from PR #12975 by @kshitijk4poor — rebased onto current main with multimodal inline image support (PR #12969) included in the extraction.

Extract 12 Codex Responses API format-conversion and normalization functions
from run_agent.py into agent/codex_responses_adapter.py, following the
existing pattern of anthropic_adapter.py and bedrock_adapter.py.

run_agent.py: 12,550 → 11,865 lines (-685 lines)

Functions moved:
- _chat_content_to_responses_parts (multimodal content conversion)
- _summarize_user_message_for_log (multimodal message logging)
- _deterministic_call_id (cache-safe fallback IDs)
- _split_responses_tool_id (composite ID splitting)
- _derive_responses_function_call_id (fc_ prefix conversion)
- _responses_tools (schema format conversion)
- _chat_messages_to_responses_input (message format conversion)
- _preflight_codex_input_items (input validation)
- _preflight_codex_api_kwargs (API kwargs validation)
- _extract_responses_message_text (response text extraction)
- _extract_responses_reasoning_text (reasoning extraction)
- _normalize_codex_response (full response normalization)

All functions are stateless module-level functions. AIAgent methods remain
as thin one-line wrappers. Both module-level helpers are re-exported from
run_agent.py for backward compatibility with existing test imports.

Includes multimodal inline image support (PR #12969) that the original PR
was missing.

Based on PR #12975 by @kshitijk4poor.
@teknium1 teknium1 merged commit ff56beb into main Apr 20, 2026
4 of 6 checks passed
@teknium1 teknium1 deleted the hermes/hermes-91e86ae2 branch April 20, 2026 18:53
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.

2 participants