Repository navigation
Description
Use cases, pain points, and background
Gym standardizes on the OpenAI Responses API: every model server implements /v1/responses,
and Gym-native agents speak it. But real external/blackbox harnesses speak other protocols —
the Claude Code CLI only talks the Anthropic Messages API (/v1/messages), so today it can
only reach Anthropic's own endpoint. Users want to run such harnesses against any Gym
backend (vLLM, OpenAI, hosted inference providers) for evaluation.
This is the inverse direction of the claude_model / anthropic_model provider
(#1146, #1546), which lets Gym use Claude as a backend. Here we want Gym model
servers to serve Anthropic Messages so an Anthropic-speaking client can use any backend.
It is explicitly called for in the model-proxy target state (#1285) and assumed
by the CustomAgent EPIC (#1042):
Blackbox agent harnesses will call any common schema that exists (e.g. including Anthropic Messages).
Add a/v1/messagesroute on every Gym model proxy that by default maps Messages ↔ Responses.
The EPIC's sidecar model proxy is "path-preserving forward to the Gym model server" — it needs
a /v1/messages route on the server to forward to.
Description
Add a POST /v1/messages route to the base SimpleResponsesAPIModel, with a default
implementation that maps Anthropic Messages ↔ Responses around the server's own responses().
Every model server (vLLM, OpenAI, inference_provider, …) then speaks Anthropic Messages with no
per-server work, and claude_code_agent can target any of them via its model_server ref.
Key translation concerns (handled by a shared converter):
- Message format — Anthropic role-scoped content blocks (text, tool_use, tool_result,
thinking) vs Responses item-oriented input/output. - System prompt — Anthropic top-level
system(string or text-block array) ↔ Responses
instructions+ system/developer items. - Tool use —
tool_use/tool_resultcontent blocks ↔ Responsesfunction_call/
function_call_output; tool schema ↔input_schema. - Thinking/reasoning — Anthropic
thinkingblocks ↔ Responses reasoning items. - Streaming — the Claude CLI requires SSE; the backend is non-streaming through Responses,
so the server synthesizes the Anthropic SSE event stream from a complete response.
Design
Base class change
class SimpleResponsesAPIModel(BaseResponsesAPIModel, SimpleServer):
def setup_webserver(self) -> FastAPI:
app = FastAPI()
self.setup_session_middleware(app)
app.post("/v1/chat/completions")(self.chat_completions)
app.post("/v1/responses")(self.responses)
app.post("/v1/messages")(self.messages) # NEW: default Messages <-> Responses
return app
async def messages(self, request, body):
# anthropic_request_to_responses -> self.responses(...) -> responses_to_anthropic_response
# -> synthesized Anthropic SSE if stream:truemessages() is concrete and overridable; it delegates to the server's own responses()
(dispatching on its signature, since some take (body) and some (request, body)).
Shared bidirectional converter
nemo_gym/anthropic_converter.py (transport-free, no anthropic SDK — raw aiohttp via
nemo_gym.server_utils.request() per CLAUDE.md), shared with the egress anthropic_model
provider so the mapping rules exist once:
- egress:
responses_to_anthropic,anthropic_to_responses - ingress:
anthropic_request_to_responses,responses_to_anthropic_response,
anthropic_response_to_sse
Anthropic-API-as-backend policy (sampling-restriction allowlist, thinking-mode guards,
base-URL normalization, lossy cache-token accounting) stays in the anthropic_model server,
not the shared converter.
Files
nemo_gym/base_responses_api_model.py— add/v1/messages+ defaultmessages()nemo_gym/anthropic_converter.py— shared bidirectional converterresources_servers/reasoning_gym/configs/reasoning_gym_claude_code_agent_model_server.yaml—
showcase wiringclaude_code_agent.model_server → policy_model- tests for the converter (both directions + round-trip) and the base-class route
Out of scope
- RL token-ids / logprobs through the Messages path (eval-first; token-ids live only at the
Responses hop and cannot ride the Anthropic SSE response — would be side-channeled later). - Streaming generation from the backend (SSE is synthesized from a complete response).
- Multimodal beyond base64 images; computer-use response items.
- A separate proxy server /
messages_api_modelscategory (prototyped and rejected in favor of
the base-class route).
Acceptance Criteria
-
/v1/messagesis served by everySimpleResponsesAPIModel(verified on at leastopenai_model/vllm_model) - Default
messages()translates Messages → Responses → Messages aroundresponses(), for bothresponses()signatures - Tool use round-trips (function calls and results); thinking maps to reasoning items; system handled as top-level
system - SSE event stream synthesized for
stream: trueand accepted by the Claude Code CLI - Shared converter covered by unit tests including round-trip; fail-loud on unsupported content
-
claude_code_agentruns end-to-end against a Gym model server's/v1/messageson an existing environment
References
- Anthropic Messages API: https://docs.anthropic.com/en/api/messages
- Target state / shared converters: Add inference provider server for hosted inference providers #1285
- CustomAgent EPIC (assumes this model-proxy capability): epic: built-in agent harness evaluations #1042
- Inverse direction (egress provider): feat: claude model support #1146, feat: Add anthropic messages api support as a responses_api_model. #1546
- Chat-Completions ↔ Responses converter extraction: feat: add inference_provider server for hosted inference providers #1286
Activity
ffrujeri commentedon Jun 16, 2026
Design Note: Anthropic Messages on every Gym model server
1. Summary
Gym's native format is the OpenAI Responses API: every Gym model server implements
/v1/responses, and Gym-native agents speak it. But real external harnesses speak otherprotocols — the Claude Code CLI only talks the Anthropic Messages API (
/v1/messages), andtoday it can only reach Anthropic's own endpoint.
This change makes every Gym model server speak Anthropic Messages by default. A
/v1/messagesroute is added to the baseSimpleResponsesAPIModel, with a defaultimplementation that maps Messages ↔ Responses around the server's own
responses(). Themapping lives in one shared, transport-free converter (
nemo_gym/anthropic_converter.py),used in both directions and shared with the egress
anthropic_modelprovider (#1146/#1546).Result: a blackbox harness that requires an Anthropic endpoint (Claude Code today; Codex,
others later) can run against any Gym backend — vLLM, OpenAI, an inference provider —
with zero per-server work. This is the model-proxy layer the CustomAgent EPIC (#1042) assumes:
its sidecar's "path-preserving forward to the Gym model server" forwards
/v1/messageshere.2. Goals / Non-goals
Goals
/v1/messageswith a correct default Messages ↔ Responses mapping.anthropic_modelprovider — no duplication.claude_code_agentruns against any Gym model server, end-to-end, for eval.Non-goals (this change)
3. Background
SimpleResponsesAPIModelexposes/v1/chat/completionsand/v1/responses;NeMoGymResponseis the canonical (superset of OpenAI Responses) interlingua.claude_code_agentrunsclaude -pas a subprocess; the CLI calls{ANTHROPIC_BASE_URL}/v1/messages(Anthropic Messages, SSE). The harness already resolvesANTHROPIC_BASE_URLfrom amodel_serverref — it only needed a server that speaks Messages.nemo_gym/responses_converter.py. feat: claude model support #1146/feat: Add anthropic messages api support as a responses_api_model. #1546 added the egressanthropic_modelprovider(Responses → Anthropic) with its own
AnthropicConverter. This change makes that converterbidirectional and shared, and turns "Messages in" into a base-class capability.
4. Design
/v1/messageson the base class.SimpleResponsesAPIModel.setup_webserver()registers athird route, and a concrete default
messages()does:anthropic_request_to_responses(body)→ Responses create-params.self.responses(...)(so it reuses whatever backend theserver has — vLLM, OpenAI, …); a small
inspect-based dispatch handles the two existingresponses()signatures ((body)and(request, body)).responses_to_anthropic_response(result)→ Anthropic message.stream: true(the Claude CLI always does), re-emit the completeresponse as a synthesized Anthropic SSE event stream.
Servers may override
messages()for native handling.Why the base class, not a separate proxy. An earlier iteration built a standalone
anthropic_messages_proxyserver (+ aSimpleMessagesAPIModelbase) that forwarded to adownstream server over HTTP. Putting the route on the base class instead means every server
gets Messages for free, with no extra process or network hop, and
claude_code_agentpointsdirectly at any model server. The proxy and the messages-only base class were removed.
Why synthesize SSE. Backends are non-streaming through Gym's Responses API; the converter
fabricates the Anthropic event sequence (
message_start→ per-block deltas →message_stop)from the complete response. This satisfies the CLI without requiring streaming in every backend.
5. The converter (
nemo_gym/anthropic_converter.py)One
AnthropicConverter, transport-free and SDK-free (local Pydantic/dict shapes overGym's aiohttp; the
anthropicSDK is avoided for its httpx connection-pool behavior). It isbidirectional so the egress provider and this ingress path share one rule set:
responses_to_anthropicanthropic_modelanthropic_to_responsesanthropic_modelanthropic_request_to_responses/v1/messagesresponses_to_anthropic_response/v1/messagesanthropic_response_to_sse/v1/messagesSupports text, base64 images, function tools,
tool_use/tool_result, thinking blocks, andstop-reason mapping; raises
NotImplementedErroron unsupported blocks (fail-loud). Sharedfield-mapping helpers (tool_choice, stop_reason, data-URL/media-type, block↔item) exist once
and are exercised by round-trip property tests.
Boundary. Anthropic-API-as-backend policy (sampling-restriction allowlist, thinking-mode
guards, base-URL normalization, lossy cache-token accounting) stays in the egress
anthropic_modelserver — it is not structural mapping and does not apply to an open-modelbackend reached via
/v1/messages.6.
claude_code_agentwiringNo harness code change: set the agent's
model_serverref instead ofanthropic_base_url.The example config
resources_servers/reasoning_gym/configs/reasoning_gym_claude_code_agent_model_server.yamlpoints the agent at
policy_model; compose it with any model-server config (e.g.vllm_model).7. Cross-cutting
Anthropic SSE cannot carry them. So this path is eval-first. An RL path would side-channel
token-ids from the downstream Responses result (out of band), not through the Messages response
— consistent with the EPIC's conditional RL faithfulness.
computer_usevs Messages) are out of scope and fail loud rather than being dropped.8. Relationship to other efforts
responses_converter.py): sibling converter for the Chat-Completions spoke; same"converter in core, server is a thin shell" pattern.
anthropic_model): the egress provider; shares this converter (theduplication its note called "intentional vs the CC converter" is resolved — the Anthropic
converter is shared and bidirectional, just not the CC one).
/v1/messagesroutes; this change is the model-proxy capability that EPIC assumes.9. Testing
tests/unit_tests/test_anthropic_converter.py— ingress + round-trip;…_egress.py— egress;100% line coverage on the converter.
tests/unit_tests/test_responses_api_model_messages.py— base-class/v1/messagesfor bothresponses()signatures + SSE.openai_model's own tests pass unchanged (every server now has aworking
/v1/messages).claude_code_agent → policy_model (vLLM) /v1/messageson a reasoning_gym task —finished_naturally=1, 1 turn, ~5.5k tokens, 0 failures. (Reward 0 reflects the small model'sanswer, not the plumbing.)
10. Open questions (tracked, not solved here)
Chat-Completions ↔ Responses converters need a dedicated regression suite.
[-]feat: Add a default `/v1/messages` (Anthropic Messages) route to the base Gym model server[/-][+]Add a default `/v1/messages` (Anthropic Messages) route to the base Gym model server[/+]feat: Add a default /v1/messages (Anthropic Messages) route to the ba…
feat: Add a default /v1/messages (Anthropic Messages) route to the ba…
ffrujeri commentedon Jul 29, 2026
This issue can be closed by #1546, if need in the future we can re-open both.