feat(agent): M3+M4 — gateway transport + the agent loop#7
Merged
Conversation
… loop M3 (transport): - client::GatewayClient — the harness's only network surface. Picks the dialect by model, POSTs provider wire to the gateway with a bai_v1 bearer (adds anthropic-version for the Anthropic dialect), and frames the chunked SSE body line-by-line into StreamEvents via async-stream. No provider keys. - mock::MockTransport — replays scripted StreamEvent turns and records requests, so the loop and the binaries test with no network. - dialect::push_sse_line — incremental per-line decode the client drives off the socket (decode_sse now builds on it). M4 (loop): - agent::Agent — Pi's pi-agent-core runtime. One iteration = stream a turn, assemble assistant content blocks from the event stream (dialect-blind), append, run requested tools, feed results back, repeat until end_turn or max_steps. Tool failures become error tool_results, not aborted runs. Proven: 21 agent-core unit tests (loop dispatch, tool round-trip, unknown/ failing tool, max_steps, event streaming) + 2 real-socket integration tests driving GatewayClient against a bare TCP SSE server (success + HTTP error). 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 — M3 (transport) + M4 (loop)
M3 — transport
client::GatewayClient— the harness's only network surface. Picks the dialect by model id, POSTs provider wire to the gateway with anAuthorization: Bearer <bai_v1…>(addsanthropic-versionfor the Anthropic dialect), and frames the chunked SSE body line-by-line intoStreamEvents (viaasync-stream). It never holds a provider key — the gateway swaps the pool key and meters.mock::MockTransport— replays scriptedStreamEventturns and records the requests the loop sends, so the loop and the binaries test with zero network. Shipsturn::text/turn::tool_callhelpers.dialect::push_sse_line— incremental per-line decode the client drives off the socket;decode_ssenow builds on it.M4 — the loop
agent::Agent— Pi'spi-agent-coreruntime. One iteration = stream a turn → assemble assistant content blocks from the event stream (dialect-blind) → append → run requested tools → feedtool_results back → repeat untilend_turnormax_steps. A tool's own failure becomes an errortool_result, not an aborted run. Streams every event to anon_eventcallback (for live rendering).Proven by
tool_result), unknown tool, failing tool,max_stepsenforcement, event streaming.GatewayClientdriven against a bare TCP server emitting chunked SSE — success path (decodesTextDelta/Usage/MessageStop) and HTTP-error path (403 surfaces as a stream error). No hyper, no gateway, no keys.Series: M1 (#5), M2 (#6) merged. Next: M6 tools + M5 binary e2e against a mock model server.
🤖 Generated with Claude Code