Recipes are variations of the same harness: state is a record, one turn is a
stream, and the loop decides what happens next.
Each recipe shows one design move you can copy into your own agent: gate tool
calls before execution, stream inner work, catch provider failures, rewrite
history, pause between turns, or fan out to multiple models. They are real,
type-checked code in recipes/,
and each page mirrors the README.md sitting next to its index.ts and tests.
For the foundational shapes, start with One turn is a stream,
Basic usage, and Structured output.
Reliability and lifecycle
| Recipe | One-line |
|---|
| Multi-model fallback | Recover from provider stream failures by advancing to the next tier. |
| Model retry | Add retry policy around one model stream; only transient provider failures get another try. |
| Auto-compaction | Rewrite oversized history as an ordinary state transition. |
| Pause and resume | Pause between loop iterations with a latch; no provider call remains open. |
| Mid-stream abort | Cancel an in-flight turn through stream interruption and scope cleanup. |
| Agentic loop | Drive a long-lived chat from a user-message queue while continuing model/tool work between clean turn boundaries. |
| Sleeper agent | Wait for a long-running tool call — the agent goes quiet while the work runs and wakes up when it’s done. |
Transport
| Recipe | One-line |
|---|
| Modify output stream | Keep the loop transport-agnostic; project typed turn events into SSE or JSONL at the edge. |
Multi-model
| Recipe | One-line |
|---|
| Model escalation | Start on a fast cheap model; let it escalate hard questions to a stronger tier via a tool call. |
| Multi-model compare | Fan one prompt out to multiple providers; per-member errors stay isolated. |
| Model council | Build a stream graph where models answer, judge each other, and emit a winner. |
Web search
| Recipe | One-line |
|---|
| Grounded answer | Answer a current-events question from live web search with inline citations; swap the LLM and backend at will. |
| Deep research | Plan a broad question into sub-questions, investigate each with a streaming sub-agent, synthesize a cited report. |
Speech
| Recipe | One-line |
|---|
| Basic transcription | Transcribe a file via the generic Transcriber service; swap providers with --provider. |
| Basic speech synthesis | Synthesize a phrase via the generic SpeechSynthesizer service; sync or chunked-streaming mode. |
| Streaming transcription | Live mic → transcript over WebSocket; Bun server bridges browser AudioWorklet to provider realtime. |
| Streaming synthesis | Type text → audio plays as the first chunk arrives; incremental text-in over WS. |
| Voice loop | Full STT → LLM → TTS pipeline with stop-word interrupt and follow-up queueing; one fiber per turn. |
Music
| Recipe | One-line |
|---|
| Basic music generation | Generate a 30-second clip with Lyria 3; simple prompt or weighted prompts with lyrics and BPM hints. |
| Radio station | Run your own AI radio station. An AI DJ writes the next track while you listen to the current one; the same set replays for free after the first pass. |
Sandboxes
| Recipe | One-line |
|---|
| Run, fix, repeat | LLMs are bad at exact computation — give them Python. Tracebacks from a sandboxed microVM feed back into the next turn. |