The trace picture in Agent Harness shows non-streaming requests: one HTTP round-trip, one JSON blob back, harness inspects content, executes any tool_use, loops. In production every serious harness — including Pi (Coding Agent) — uses streaming instead. The response arrives as a sequence of server-sent events over a long-lived connection, with text and tool-call arguments dribbling in token by token.

This page is about what streaming actually changes — for UX, for interrupt semantics, and for sub-agents. Most of it is non-obvious until you stare at a real event stream.

What the Stream Looks Like

Anthropic Messages API, abbreviated:

event: message_start              { id, model, usage: { input_tokens: 2543 } }
event: content_block_start        { index: 0, type: "text" }
event: content_block_delta        { index: 0, delta: { text: "I'll" } }
event: content_block_delta        { index: 0, delta: { text: " read auth.py..." } }
event: content_block_stop         { index: 0 }
event: content_block_start        { index: 1, type: "tool_use", name: "read", id: "toolu_..." }
event: content_block_delta        { index: 1, delta: { partial_json: "{\"path\":" } }
event: content_block_delta        { index: 1, delta: { partial_json: " \"auth.py\"}" } }
event: content_block_stop         { index: 1 }
event: message_delta              { stop_reason: "tool_use", usage: { output_tokens: 64 } }
event: message_stop

Same final content as the blob trace, but:

  • Tool-call arguments arrive as partial JSON that must be accumulated and parsed only at content_block_stop. Mid-stream, the args are syntactically incomplete.
  • stop_reason arrives at the very end in message_delta. The harness doesn’t know whether the loop continues until the stream finishes.
  • input_tokens is known at message_start; output_tokens accrue throughout. Cost is observable live.
  • The harness must hold the HTTP stream open and maintain per-block buffers.

OpenAI’s Chat Completions streaming format differs in surface (delta chunks, finish_reason, tool_calls array) but is structurally analogous. Pi’s pi-ai package abstracts over both.

What Streaming Buys (UX)

Cosmetic answer: “it feels faster.” Real answer is bigger.

EffectWhat it actually changes
Progressive renderingUser can begin reading before generation finishes — read time and generate time overlap instead of being serial
Early-abort supervisionIf the model is heading the wrong direction, the user can hit Esc at token 50 instead of waiting for token 5,000. The user becomes a real-time supervisor of the model’s trajectory.
Live cost meteroutput_tokens accrue visibly. The user sees the meter run while it runs, instead of receiving a receipt afterward.
Trajectory visibilityWhen the model emits text before a tool_use block (e.g. “I’ll read auth.py…”), the user sees the intent before the action — a free observability checkpoint.

The early-abort property is the substantive one. It is a real change to the reactive-executor relationship described in Agent Harness: in blob mode, by the time output is visible, the API call is paid for and the tool call is about to fire. In streaming mode, the user has an intervention window during generation. Streaming gives the user a steering input the blob model didn’t allow.

Interrupt Semantics

User hits Esc mid-stream. The harness now holds: some partial assistant text, possibly an incomplete tool_use block whose JSON arguments are unfinished. What goes into the transcript determines what the model “sees” on every future turn — so the choice matters.

The hard rule first

Warning

Incomplete tool_use blocks are dropped, never executed, never “guessed.”
Tool-call arguments arrive as partial JSON. A stream cut at {"path": does not know whether the next chars were "auth.py"} or "production.db"}. Executing on a guess is fabrication, and it violates the reactive-executor principle from Agent Harness: a partial tool call is not yet an intention, it is an in-progress emission. The harness has no license to complete it.

Three viable strategies

StrategyTranscript on next turnTradeoff
Drop the whole turnUnchanged from before the user’s messageClean; loses evidence of where the model was heading
Keep partial text + [Interrupted by user] markerPartial assistant text + interrupt note; tool_use droppedHonest record; small risk of partial influencing next turn
Keep partial + immediate user correctionPartial + interrupt + user’s redirect messageMaximally informative; the parent thread of Pi’s Esc-then-type pattern

Pi’s preferred strategy is the third: the partial output is a real witness of where the model was going (preserving observability), the incomplete tool call is dropped (preserving honesty), and the user’s redirect lands in the same turn so the next API call sees a coherent “I started here, was stopped, told to do this instead” sequence.

Sub-Agents

A sub-agent is the parent harness spawning a second agent loop, with its own system prompt and its own message history, to handle a subtask. When the sub-agent finishes, it returns one result to the parent — typically a final text answer — and the parent’s loop continues. From the parent’s API perspective, the sub-agent invocation is one tool_use that takes a very long time to resolve (possibly minutes). The parent’s API call sits paused until the sub-agent emits its final answer.

Streaming changes sub-agent design in two specific places.

The two visibility dials

DialOptionsWho decides
User sees sub-agent stream?Yes / No / On-demandUX choice — a setting
Parent sees sub-agent transcript?Just final answer / Summary / Full streamForced to “just final answer” by context budget

The parent’s blindness is not a UX choice — it’s a context-budget necessity. If the parent’s transcript carried the sub-agent’s full stream (every tool call, every multi-thousand-token tool result, every intermediate reasoning step), the entire reason to spawn a sub-agent collapses: the parent now pays for the sub-agent’s work on every subsequent turn. Sub-agents only earn their cost by keeping the side quest outside the parent’s window.

The user-visibility dial is independent. Without streaming, a sub-agent is fully opaque for its entire runtime — possibly minutes of silence. With streaming, the user can watch in a side panel or indented inline view. Streaming doesn’t fix the parent’s blindness (that’s structural), but it’s the difference between a sub-agent that’s unobservable to anyone and one that’s unobservable to the parent but watchable by the user.

Sub-agents as scoped auto-compaction

The deep structural point:

Key

A sub-agent’s final answer is, by construction, an LLM-written compression of an LLM-driven trajectory. This is structurally identical to auto-compaction.

Re-read failure mode A in Context Window Management Strategies: “compaction launders mistakes into assertions.” A sub-agent that misreads on its internal turn 3 produces a final answer that asserts the misreading as fact. The parent then reasons from that asserted fact, with no access to the underlying evidence — because the evidence is locked inside the sub-agent’s discarded transcript.

Auto-compaction lets the model rewrite the past of this session. A sub-agent lets the model write the only-surviving-record of a parallel session. They are the same failure mode, scoped differently.

This is why Pi (Coding Agent) refuses sub-agents by default. It is the same refusal as auto-compaction, applied to side quests instead of the main thread. Both put an LLM in charge of editing the evidence other LLM turns will reason from. Both defeat observability. Both amplify booboo compounding by hiding the original tool results.

The valid exception: code review

Pi acknowledges code review as a legitimate sub-agent use case. Why does that break the laundering chain?

  • The sub-agent’s job is to produce a list of findings — compression is the deliverable, not a side effect.
  • The consumer is the human, not the parent agent. The parent doesn’t reason from the review; the human does.
  • Findings are evaluated against the actual code (still on disk), not propagated as facts the parent must trust.

The principle generalizes: a sub-agent is safe when its output is consumed by a human or by a deterministic process, not when its output becomes premise material for another LLM turn.

Esc semantics get tricky

When the user interrupts during a sub-agent run, what does Esc kill?

  • (a) Just the sub-agent’s current tool call, letting it continue on the next turn?
  • (b) The entire sub-agent loop, returning a "cancelled" tool_result to the parent?
  • (c) The whole tree including the parent?

Harnesses differ. Pi’s bias: the user should be able to kill any layer cleanly, with the choice exposed.

The Underlying Principle

Key

Streaming is the only mechanism that lets a user supervise an LLM in flight rather than after the fact.
Blob-mode responses are receipts. Streaming responses are dashboards. Every observability property a minimal harness cares about — early abort, live cost, trajectory visibility, sub-agent watchability — depends on the stream existing. Any harness feature that breaks streaming (long buffered post-processing, hidden compaction passes, opaque sub-agents) is paying for itself in observability debt.

Open Questions

  • Is there a “transparent sub-agent” design where the parent receives both a summary and a structured pointer to the full sub-agent transcript on disk, so a future parent turn could read the evidence on demand? Would that defuse the laundering failure mode?
  • Should harnesses expose a “streaming replay” of completed sessions so users can watch a past session at the same pace they would have lived it? (Useful for debugging, training, and review.)
  • How does prompt caching interact with streaming? Cached prefixes process much faster than uncached suffixes — does that change the perceived UX of streaming, or only the cost?