weft guides
Each guide does one task with weft and ends with a complete program that runs offline, against a scripted model or (for providers) a local test server. The guides assume you have built an agent once (Quickstart) and know what a run and a tool are (Concepts). Pick a guide by what you need to do.
Run an agent and read the result
Section titled “Run an agent and read the result”- Stream a run’s events: range over
Events()to show progress, read the terminal error, stop early. - Get structured output from a run: constrain the final answer to a Go struct with
weft.Output. - Continue a conversation: feed the transcript back with
weft.Messagesand store it between requests.
Shape what a run does
Section titled “Shape what a run does”- Rewrite the request each step (PrepareStep): trim messages, change the tools, the system prompt or sampling for each model call.
- Change an agent’s configuration for one run: override instructions, narrow tools, switch the model, sample differently or force a tool call for a single run.
- Steer a running turn: deliver a user message into a run that is already going.
- Control reasoning (thinking): set a reasoning level for every run or for one.
- Require human approval for a tool: park a call, end the run, resume it with a decision.
Give an agent tools
Section titled “Give an agent tools”- Set per-tool policy: timeouts, caps, ordering and strict input: one tool’s own deadline, result cap, barrier, input rule or prompt snippet.
- Define tools at runtime: RawTool and ToolSource: a tool with an explicit schema, or a catalogue that changes during a run.
- Delegate to another agent (subagents): run an agent as another agent’s tool.
- Use MCP both ways: import an MCP server’s tools, or serve an agent as an MCP server.
Work with models and providers
Section titled “Work with models and providers”- Connect a model provider: OpenAI, Anthropic, Gemini: construct and configure the first-party adapters.
- Send images and files to a model: mix text and files in one prompt.
- Add behaviour with middleware (the two seams): wrap the model and every tool call.
- Retry and fall back when a provider fails: retry transient errors and switch to a backup model.
Observe and describe your agents
Section titled “Observe and describe your agents”- Observe a run without changing it: Tap, OnRunEnd, OnMessages: see every event, the outcome, or each batch of messages as it joins the transcript.
- Tag runs with metadata: put tenant, user or request ids on every span and record of a run.
- Describe your agents in weft.json (the manifest): generate and golden-gate the manifest that Studio’s Agents page reads.
See also
Section titled “See also”- Concepts: what the core pieces are and how they behave
- Sessions: durable conversations with
weft/thread - Testing: scripted models, record and replay
- Package weft on pkg.go.dev