feat: centralize Responses API input conversion across agent paths#5711
Closed
ProgramCaiCai wants to merge 2 commits into
Closed
feat: centralize Responses API input conversion across agent paths#5711ProgramCaiCai wants to merge 2 commits into
ProgramCaiCai wants to merge 2 commits into
Conversation
Contributor
|
Merged via #41714 (commit 2789bf4). Your fix here was the architecturally correct one — centralizing the chat-to-Responses conversion so the auxiliary path can't drift from the main path. We reimplemented that approach on current Thanks for both reporting #5709 and proposing the right fix. |
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
agent.responses_apihelpers for Responses API message conversionrun_agent.pyand the auxiliary Codex adapter through the same conversion pathfunction_call/function_call_outputitems instead of replaying rawrole=toolmessagesProblem
Hermes already had one correct Responses conversion path in
run_agent.py, butagent/auxiliary_client.pystill kept its own adapter logic.That split was fragile: one path normalized tool transcripts correctly, while another could still replay chat-style
role=toolmessages into Responsesinput[]. Providers that implement the OpenAI Responses contract reject that shape with a 400 becausetoolis not a valid input role there.Why this approach
This bug should not be fixed with another provider-specific patch.
The underlying problem was duplicated conversion logic across Responses-capable call paths. As long as those paths drift independently, custom gateways and Codex-compatible providers can regress in different ways.
This PR fixes it centrally by moving the conversion rules into shared helpers and making every Responses-capable path use the same normalization logic.
Testing
env -u OPENAI_BASE_URL -u OPENAI_API_KEY -u OPENROUTER_API_KEY HOME=$(mktemp -d) ./venv/bin/pytest tests/agent/test_auxiliary_client.py::TestCodexResponsesAdapter::test_adapter_converts_tool_messages_to_function_call_output tests/test_run_agent_codex_responses.py -qCloses #5709