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 recipe.ts, app.ts and run.ts.

Every recipe has the same four files: recipe.ts holds the effect-uai logic and names capability tags rather than vendors, app.ts composes it (flags, provider Layers, rendering), run.ts is one line and works unchanged on Node, Bun and Deno, and README.md is the page you are reading. Run any of them with pnpm tsx recipes/<name>/run.ts, bun recipes/<name>/run.ts, or deno run --allow-all recipes/<name>/run.ts.

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.
MCP toolsTurn a live MCP server’s tools into a Toolkit; the connection lives exactly as long as the stream.

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.

Observability

RecipeOne-line
Basic metricsStack time-to-first-token, throughput, token totals, and completion time onto a generation; log them live while the story streams to a file.

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.
Native deep researchSubmit one question to a provider-hosted research agent (OpenAI, Perplexity, Gemini); stream its progress and get one cited report.

Web reading

RecipeOne-line
Market intelRead 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.

Retrieval

RecipeOne-line
Retrieve and rerankYour top results are about the question but never answer it. Add a rerank pass and watch the right document climb.
Agentic searchGive an agent search that catches exact names and paraphrases both, and let it search again when the first try misses. No server.
Contextual retrievalChunks that say “he” and “that house” never match a question naming either. Write one line of context per chunk at indexing time, and measure the difference.

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.

Realtime

RecipeOne-line
Realtime voice agentOne duplex session instead of a pipeline; talk over it and it stops, tools run beside the conversation.
Camera assistantPoint a camera at something and ask about it; frames ride the same session, gated by a capability marker.

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.

Images

RecipeOne-line
StoryboardTell a story in pictures: your characters stay themselves across every panel, so eight images read as one comic.
Conversational image editSay what to change, keep the picture. Getting the image you want takes a few goes, and your subject survives every one of them.

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.

Browser

RecipeOne-line
Agent usability testingGive 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 briefingScreenshot a dashboard whose charts only exist client-side and decode one vision turn into a typed briefing.

Messenger

RecipeOne-line
Messenger agentPut the agent where people already are. Mention it in Telegram; it types, searches, draws, and streams the answer into one message.