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. |
Observability
| Recipe | One-line |
|---|
| Basic metrics | Stack time-to-first-token, throughput, token totals, and completion time onto a generation; log them live while the story streams to a file. |
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. |
| Native deep research | Submit one question to a provider-hosted research agent (OpenAI, Perplexity, Gemini, Exa); stream its progress and get one cited report. |
Web reading
| Recipe | One-line |
|---|
| Market intel | Read a batch of vendor pages to clean markdown and extract a typed pricing record from each, concurrently; no selectors, so pages that share no layout still decode. |
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. |
Browser
| Recipe | One-line |
|---|
| Agent usability testing | Give an agent a goal and a URL; it drives the site like a first-time visitor and reports where the UX tripped it up. |
| Dashboard briefing | Screenshot a dashboard whose charts only exist client-side and decode one vision turn into a typed briefing. |