Skip to content

Examples and recipes

View as Markdown

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 buildingRecipeIt combines
An agent whose risky actions wait for a personSupport desk with human approvalRequireApproval, a parking middleware, Approve/Deny/Resolve across a JSON round trip, Output
A lead agent that hands work to specialistsResearch team: a lead agent and specialist subagentsSubagent, Parallelism, Nested events, usage roll-up, Output
An agent over backends that failSurvive flaky infrastructureModelRetry, Timeout, panic containment, coded errors, mw.Retry, mw.Fallback
An agent that must not run awayGuard against runaway agentsUsageLimit, MaxSteps, DetectLoops, *RunError with the partial transcript
Agents owned by different teamsAn agent mesh over MCPmcp.Serve, mcp.Tools, mcp.Prefix, ToolSource
An agent inside company policyA governed agent stack: every seam on one runtoken limiter, response cache, mw.Audit, mw.Allow, rate limiter, PII scrub, approval, content policy
A chat that remembers across restartsA multi-turn session that survives a crashweft/thread on JSONL, queued sends, Continue, custom ledger entries, compaction, branching
Typed data out of messy textExtract structured data from a messy documentOutput[T], GenerateAs, the INVALID_INPUT repair loop, mw.RepairJSON
One step that asks for many toolsFan out many tool calls safelyParallelism, a Sequential barrier, MaxResultBytes

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.

The programs live in the docs examples module, one package per recipe under cookbook/. From a clone of weftgo.dev:

Terminal window
cd docs-site/examples
go run ./cookbook/supportdesk
go 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.