refactor: extract codex_responses logic into dedicated adapter#13018
Merged
Conversation
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.
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
Extract 12 Codex Responses API format-conversion and normalization functions from
run_agent.pyintoagent/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 functionsrun_agent.py(-685 lines): Thin one-line wrappers delegate to adapter; two module-level helpers re-exported for backward compatWhat moved
_chat_content_to_responses_parts_summarize_user_message_for_log_deterministic_call_id_split_responses_tool_id_derive_responses_function_call_id_responses_tools_chat_messages_to_responses_input_preflight_codex_input_items_preflight_codex_api_kwargs_extract_responses_message_text_extract_responses_reasoning_text_normalize_codex_responseDesign
anthropic_adapter.py,bedrock_adapter.pyrun_agentso existingfrom run_agent import _chat_content_to_responses_partsstill worksValidation
-k 'codex or responses'test_run_agent_multimodal_prologue.pypy_compileSalvaged from PR #12975 by @kshitijk4poor — rebased onto current main with multimodal inline image support (PR #12969) included in the extraction.