Examples and recipes
Each recipe is one complete program that combines several weft features to solve a problem real agents have. The shapes come from the rw.* scenarios of weft-arena, weft’s test harness. Every program runs offline against scripted models, is tested, and records its runs so you can open them in Studio. Pick the recipe closest to what you are building.
| You are building | Recipe | It combines |
|---|---|---|
| An agent whose risky actions wait for a person | Support desk with human approval | RequireApproval, a parking middleware, Approve/Deny/Resolve across a JSON round trip, Output |
| A lead agent that hands work to specialists | Research team: a lead agent and specialist subagents | Subagent, Parallelism, Nested events, usage roll-up, Output |
| An agent over backends that fail | Survive flaky infrastructure | ModelRetry, Timeout, panic containment, coded errors, mw.Retry, mw.Fallback |
| An agent that must not run away | Guard against runaway agents | UsageLimit, MaxSteps, DetectLoops, *RunError with the partial transcript |
| Agents owned by different teams | An agent mesh over MCP | mcp.Serve, mcp.Tools, mcp.Prefix, ToolSource |
| An agent inside company policy | A governed agent stack: every seam on one run | token limiter, response cache, mw.Audit, mw.Allow, rate limiter, PII scrub, approval, content policy |
| A chat that remembers across restarts | A multi-turn session that survives a crash | weft/thread on JSONL, queued sends, Continue, custom ledger entries, compaction, branching |
| Typed data out of messy text | Extract structured data from a messy document | Output[T], GenerateAs, the INVALID_INPUT repair loop, mw.RepairJSON |
| One step that asks for many tools | Fan out many tool calls safely | Parallelism, a Sequential barrier, MaxResultBytes |
How a recipe is laid out
Section titled “How a recipe is laid out”Each page has the same sections: the problem and where it comes from, the program in parts with what each part does, what to look at in Studio, a table of the weft features it combines with the guide that explains each, the complete program with its output, and the gotchas. The recipes link the guides rather than re-explain them; start from the guides when you need one feature on its own.
Run a recipe
Section titled “Run a recipe”The programs live in the docs examples module, one package per recipe under cookbook/. From a clone of weftgo.dev:
cd docs-site/examplesgo run ./cookbook/supportdeskgo test ./cookbook/...The models are scripted with wefttest.Script, so no API key is needed and the output is the same on every run. Two lines rest on goroutine timing, each with a wide margin: tool-storm’s get_weather calls overlapped, never more than 3 at once: true (calls sleep 50 ms, so they overlap) and governed-stack’s rate limiter spaced the calls: true (the limiter’s waits set a floor on the elapsed time). Swap the scripted model for a provider adapter to run one against a real model; see Connect a model provider. Every recipe records with otel.Install(otel.Local("")) into ./.weft/weft.db (or $WEFT_DB); open that database with weft studio to see the runs, as Run Studio explains.
See also
Section titled “See also”- weft guides: one task per page
- weft concepts: what the pieces are and how they behave
- Test an agent with a scripted model: how the recipes run offline
AGENTS.md: the whole API on one screen; pkg.go.dev for the signatures