ππ Agent
Chapter 9 / 21

Streaming, Partial JSON & Retries

Tolerant streams & constrained sampling

Errors are events, never thrown: stopReason 'error'/'aborted'

Key Source Files

ai/src/utils/event-stream.ts
json-parse.ts
retry.ts (227)
api/constrained-sampling.ts
validation.ts
Total size ~ ~50KB

Run Demo

# Directly runnable
$ cd Pi-Agent-Site
$ npx tsx agents/s09_streaming_partial_json.ts