feat(agent): M2 — OpenAI + Anthropic wire dialects#6
Merged
Conversation
Add `agent_core::dialect`: per-provider request building and streaming SSE decoding, normalizing both providers onto the dialect-agnostic StreamEvent sequence the loop will consume. - Dialect::for_model picks Anthropic for Claude, OpenAI wire otherwise. - anthropic: near-identity mapping (internal model is Anthropic-shaped); decodes content_block_*/message_* into TextDelta/ToolUseStart/ InputJsonDelta/ContentBlockStop/Usage/MessageStop. - openai: translates system→message, ToolUse→tool_calls (args as JSON string), ToolResult→role:"tool" messages; decoder synthesizes the block-stop boundaries OpenAI omits and defers MessageStop past the trailing usage chunk. Both dialects emit identical event shapes. Proven against recorded text+tool_use SSE fixtures for each dialect, plus golden request-body assertions. 15 agent-core unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 30, 2026
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.
What — M2
Adds
agent_core::dialect: per-provider request building and streaming SSE decoding, normalizing both providers onto the dialect-agnosticStreamEventsequence the agent loop will consume. This is the one piece ofpi-aiworth porting (the gateway owns provider keys/routing; the harness owns the wire).Dialect::for_model— Claude → Anthropic (/v1/messages), everything else → OpenAI wire (/v1/chat/completions).anthropic— near-identity request mapping (the internal model is Anthropic-shaped); decoder translatescontent_block_*/message_*intoTextDelta/ToolUseStart/InputJsonDelta/ContentBlockStop/Usage/MessageStop.openai— real translation: system→message,ToolUse→tool_calls(arguments as a JSON string),ToolResult→role:"tool"messages; decoder synthesizes the block-stop boundaries OpenAI omits and defersMessageStoppast the trailing usage chunk. Both dialects emit identical event shapes so the loop is dialect-blind.Proven by
Recorded text + tool_use SSE fixtures for each dialect decoded to an exact
StreamEventsequence, plus golden request-body assertions (system hoisting, tool-call arg stringification, tool-result fan-out). 15 agent-core unit tests, no network.Part of the agent-harness series (M1 scaffold merged in #5). Next: M3 transport + M4 loop.
🤖 Generated with Claude Code