Repository navigation
Render a vf Response as each dialect's native response - #2754
Closed
parkerpettit wants to merge 3 commits into
Closed
parkerpettit wants to merge 3 commits into
parkerpettit wants to merge 3 commits into
Conversation
Dialect.response_to_wire turns a typed Response into the native response a harness's SDK expects, for responses no provider sent. Chat shares one converter with the train client (completion_to_wire, which now also carries provider_state as reasoning_details). Anthropic builds a message with thinking, text, and tool_use blocks; Responses reuses the recorded output items. Both now stream responses with several blocks or items; a single text block streams as before.
…responses A reply with reasoning but no provider items (a model without signed thinking, such as the train client's) lost its reasoning on the way to an Anthropic or Responses harness. Anthropic now emits a thinking block and Responses a reasoning item for it. Every rendered response is validated through the dialect's provider SDK model.
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.
Why
Each harness speaks one API format, its dialect: chat completions (bash, rlm, most harnesses), Anthropic Messages (claude_code), or Responses (codex). Normally the interception server passes the provider's response through unchanged. So the dialects only had to parse native responses into a typed
Response.Some responses have no provider behind them. The train client generates its own, and trace replay serves recorded ones again. Then the interception server must build the native response itself. Until now only chat could, inside the train client. Anthropic and Responses could parse responses but not build them.
Change
Dialect.response_to_wire(response, model)builds the native response. Parsing it back gives the same message and usage.completion_to_wire, and both callers share it. The only addition:provider_stateis emitted asreasoning_details. The train client never sets it.messagewith thinking, text, andtool_useblocks.stream_eventsnow streams every block, not only a single text block.outputitems, or builds them when there are none.stream_eventsnow streams every item.The rewrite path, which replaces a response with inert text, emits the same events as before.
Testing
pytest tests -m "not e2e": green.stream_eventsonly after a response interceptor rewrote it, andrewrite_responsereduces that reply to one text block. On that shape the newstream_eventsis byte-identical to main's: 44,421 shapes fuzzed from 247 recorded claude_code and codex responses. The train client's chat output is byte-identical too, because it never setsprovider_state.Note
Add
response_to_wireso each dialect renders a native vf ResponseDialect.response_to_wirein base.py that converts the internalResponsemodel into each dialect's native payload formatcompletion_to_wire, now including provider state underreasoning_details; removes the local serializer from train.pystream_eventsin both the Anthropic and Responses dialects to emit start/delta/stop events for every content block and output item instead of streaming only the first text blockDialectsubclasses must implementresponse_to_wireor they can no longer be instantiated; check out-of-tree dialect implementationsMacroscope summarized 8f7db49. (Automatic summaries will resume when PR exits draft mode or review begins).