Skip to content

feat: centralize Responses API input conversion across agent paths#5711

Closed
ProgramCaiCai wants to merge 2 commits into
NousResearch:mainfrom
ProgramCaiCai:fix/responses-input-unification
Closed

feat: centralize Responses API input conversion across agent paths#5711
ProgramCaiCai wants to merge 2 commits into
NousResearch:mainfrom
ProgramCaiCai:fix/responses-input-unification

Conversation

@ProgramCaiCai

Copy link
Copy Markdown
Contributor

Summary

  • add shared agent.responses_api helpers for Responses API message conversion
  • route both run_agent.py and the auxiliary Codex adapter through the same conversion path
  • convert assistant tool calls and tool outputs into function_call / function_call_output items instead of replaying raw role=tool messages
  • add a regression test covering the auxiliary Responses adapter path

Problem

Hermes already had one correct Responses conversion path in run_agent.py, but agent/auxiliary_client.py still kept its own adapter logic.

That split was fragile: one path normalized tool transcripts correctly, while another could still replay chat-style role=tool messages into Responses input[]. Providers that implement the OpenAI Responses contract reject that shape with a 400 because tool is 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 -q

Closes #5709

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 30, 2026
@teknium1

teknium1 commented Jun 8, 2026

Copy link
Copy Markdown
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 main: since the canonical converter now lives in agent/codex_responses_adapter.py (_chat_messages_to_responses_input), we routed _CodexCompletionsAdapter.create() through it directly rather than introducing a new module, and removed the now-dead _convert_content_for_responses() helper. Your authorship is preserved as a co-author on the merged commit, and you're credited in the issue.

Thanks for both reporting #5709 and proposing the right fix.

@teknium1 teknium1 closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses API paths should never replay tool messages with role=tool

3 participants