Skip to content

What is weft, and when should you not use it?

View as Markdown

weft is an open-source Go framework for building AI agents. A tool is a plain Go function, an agent is a value you build once and run many times, and Generate runs the loop — model, tools, model — until the model answers. One go get brings the loop, durable sessions, run recording and Studio, the web UI that shows each run. weft is pre-1.0 and Go only.

The smallest agent in getstarted/main.go has one tool, one agent and one run:

getstarted/main.go
lookup := weft.Tool("lookup_order", "Look up an order by ID.",
func(ctx context.Context, in LookupInput) (string, error) {
return "order " + in.OrderID + ": shipped", nil
})
agt := weft.New(model,
weft.Name("support"),
weft.Instructions("You are a support agent."),
lookup,
)
res, err := agt.Generate(ctx, weft.Prompt(question))
if err != nil {
return "", err
}
return res.Text(), nil

getstarted/main.go on GitHub

weft.Tool reflects the tool’s JSON Schema from LookupInput’s struct tags. weft.New builds the agent; every option has a working default. weft.Prompt is the user’s message, and res.Text() the model’s final answer.

weft’s API is small interfaces, context.Context first in every signature, functional options, wrapped errors, and no required configuration. The framework is one module, github.com/weftgo/weft, at one version. Its packages are layers; you import the ones you use. The loop’s companions — the provider adapters, MCP, middleware and the test model — sit alongside the root package, each in its own package:

PackageWhat it gives you
weftThe agent loop: tools from Go functions, parallel tool calls, typed streaming events, structured output, approvals, steering and subagents.
weft/openai, weft/anthropic, weft/google, weft/mcp, weft/mw, weft/wefttestThe OpenAI, Anthropic and Google adapters (openai, anthropic, google), MCP both ways (mcp), reference middleware (mw) and the offline test model (wefttest).
weft/threadDurable sessions: an append-only conversation tree with branching, compaction, approvals that survive a restart, steering and a bounded pool of child agents, stored as JSONL, in SQLite or in memory.
weft/otelRecording with otel.Install: every event, transcript and span exported over OpenTelemetry to a local database, Studio or any OTLP backend, with a content policy and redaction per destination.
weft/obsdbThe database those records land in, queryable from Go: SQLite locally, ClickHouse hosted (weft/obsdb/clickhouse).
weft/studioStudio, the inspector: runs, sessions, traces and live streams in a web UI; a devtools panel for your own pages; a playground that re-runs a turn with an edited prompt, model or tools. The weft command (weft studio, weft dev) serves it for apps in any language.
weft/scopeThe devtools panel’s scope header: scope.Header sets Weft-Scope on your own chat endpoint, so the in-page panel follows the conversation and run a response belongs to.
weft/runtimeThe playground’s in-app side: your app executes Studio’s experiment commands, with side-effect tools substituted or parked unless you opt them in.

The loop also exists alone, as the module github.com/weftgo/weft/core, whose only dependency is the OpenTelemetry API. The root package weft re-exports it name for name: weft.Agent is core.Agent. Install weft and choose a module says which one to go get.

A step’s tool calls run on their own goroutines, at most four at once by default; weft.Parallelism changes the bound, and a failing tool never cancels its siblings.

Recording and inspection are two lines: defer otel.Install(otel.Local(""))() records every run to ./.weft/weft.db (plus any Studio the environment names), and studio.Handler(studio.DB(otel.LocalDB())) serves Studio over that database. Your first agent builds both.

weft Studio's runs list: each run's status, prompt and id, agent, steps, tokens, cost, start and duration, newest first, with a checkbox per row to pick runs to compareweft Studio's runs list: each run's status, prompt and id, agent, steps, tokens, cost, start and duration, newest first, with a checkbox per row to pick runs to compare

The status at v0.20.2: experimental and pre-1.0, released as the framework module plus core. The core’s message model, error model and tool contract are implemented and tested. CI runs on every change (CI on GitHub), the API reference is on pkg.go.dev, and each release is tagged on GitHub (v0.20.2).

A run is one call to Generate or Stream. Each step is one model call. When the model asks for tools, the loop runs them, sends their results back as one tool message, and calls the model again. The run ends when the model answers without asking for a tool, when a weft.StopWhen condition matches, or when a call is parked for approval; it fails when a budget such as MaxSteps runs out.

The agent loop: the model calls tools, their results go back to the model, and the run ends at RunFinish.agt.Generate starts a run (RunStart). Each step is one model call, one chat span. When the model asks for tools, each call starts (ToolStart), the tools run in parallel, and their results come back (ToolFinish) to the model as one tool message; the step ends with StepFinish and, if the budgets allow, the next step calls the model again. MaxSteps bounds the loop, 10 steps by default. The run ends at RunFinish when the model answers with no tool calls, when StopWhen matches, or when calls are pending approval.

Three rules hold on every run:

  • A tool error is data the model sees; a run error is a Go error. A handler error, a panic or bad arguments become an error result the model reads. A model failure, a cancelled ctx or a spent budget fail the run with a *weft.RunError that carries the partial transcript.
  • Every run has an id. weft.RunStart is its first event and, when it succeeds, weft.RunFinish its last.
  • Budgets fail at the continuation point. weft.MaxSteps caps a run’s model calls, 10 by default; the run fails with ErrMaxSteps only when the loop would call the model again.

weft is the wrong tool in these cases:

  • Your agent is not written in Go. The loop is a Go library. Studio is not tied to Go: weft studio inspects any language’s OpenTelemetry app (Inspect agents written in other languages).
  • You need a frozen API. weft is pre-1.0. A minor release can break the framework module’s packages, and weft/thread’s API and file format are not frozen. Only the core module fails CI on an incompatible change.
  • You want a graph or workflow engine. Orchestration lives in the loop: a subagent is a tool (weft.Subagent), and weft.PrepareStep rewrites each step’s request. weft ships no graph.
  • You need a run to resume after its process dies. The core keeps no state: a run is a function of the agent, the input transcript and the approval decisions, and it lives in its process. weft ships no durable-execution engine.
  • You need a security boundary around tools. Approval is a policy seam, not a security boundary (ADR 0007), and weft ships no sandbox for tools.
  • You need a model server or evaluations. Neither has shipped: serving and the eval modules are next on the roadmap.

weft is released under the MIT License. The full text is in LICENSE.

  • Import weft in application code, not core. The root package is the facade users write against; the layers import core inside the repository. Import core only when you want the loop and nothing else. (Source: AGENTS.md intro; ADR 0027, decision 4)
  • Pin the exact version. Pre-1.0, a minor release may carry breaking changes; the CHANGELOG lists them under Breaking. (Source: README.md status; AGENTS.md “Working in this repo”)
  • Test without a network. wefttest.Script plays model turns offline, and WEFT_MODEL_REQUESTS=deny makes the first-party adapters refuse to call their provider. (Source: AGENTS.md “Test offline”; getstarted/main_test.go)

Symbols used: weft.Tool · weft.New · weft.Name · weft.Instructions · weft.Prompt · Agent.Generate · RunResult.Text · weft.Parallelism · weft.StopWhen · weft.MaxSteps · weft.ErrMaxSteps · weft.RunError · weft.RunStart · weft.RunFinish · weft.Subagent · weft.PrepareStep · wefttest.Script · otel.Install · otel.Local · otel.LocalDB · studio.Handler · studio.DB · scope.Header