Skip to content

Recipes

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.

Tools and HITL

RecipeOne-line
Tool call approvalGate sensitive calls before Toolkit.run; still return one result per model-requested tool call.
Streaming tool outputShow inner tool work to the user while returning one clean output to the model.
Streaming structured outputValidate prompted JSONL one object at a time as the model streams.

Reliability and lifecycle

RecipeOne-line
Multi-model fallbackRecover from provider stream failures by advancing to the next tier.
Model retryAdd retry policy around one model stream; only transient provider failures get another try.
Auto-compactionRewrite oversized history as an ordinary state transition.
Pause and resumePause between loop iterations with a latch; no provider call remains open.
Mid-stream abortCancel an in-flight turn through stream interruption and scope cleanup.
Agentic loopDrive a long-lived chat from a user-message queue while continuing model/tool work between clean turn boundaries.
Sleeper agentWait for a long-running tool call — the agent goes quiet while the work runs and wakes up when it’s done.

Transport

RecipeOne-line
Modify output streamKeep the loop transport-agnostic; project typed turn events into SSE or JSONL at the edge.

Multi-model

RecipeOne-line
Model escalationStart on a fast cheap model; let it escalate hard questions to a stronger tier via a tool call.
Multi-model compareFan one prompt out to multiple providers; per-member errors stay isolated.
Model councilBuild a stream graph where models answer, judge each other, and emit a winner.
RecipeOne-line
Grounded answerAnswer a current-events question from live web search with inline citations; swap the LLM and backend at will.
Deep researchPlan a broad question into sub-questions, investigate each with a streaming sub-agent, synthesize a cited report.

Speech

RecipeOne-line
Basic transcriptionTranscribe a file via the generic Transcriber service; swap providers with --provider.
Basic speech synthesisSynthesize a phrase via the generic SpeechSynthesizer service; sync or chunked-streaming mode.
Streaming transcriptionLive mic → transcript over WebSocket; Bun server bridges browser AudioWorklet to provider realtime.
Streaming synthesisType text → audio plays as the first chunk arrives; incremental text-in over WS.
Voice loopFull STT → LLM → TTS pipeline with stop-word interrupt and follow-up queueing; one fiber per turn.

Music

RecipeOne-line
Basic music generationGenerate a 30-second clip with Lyria 3; simple prompt or weighted prompts with lyrics and BPM hints.
Radio stationRun 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

RecipeOne-line
Run, fix, repeatLLMs are bad at exact computation — give them Python. Tracebacks from a sandboxed microVM feed back into the next turn.