weft · features · v0.20.2

Every part of weft, drawn.

The building blocks under the improvement loop: tools as Go functions, parallel tool calls, sessions that last, recording, Studio, replay from any step and the devtools panel. Then the API, in code.

the tour

How weft works, step by step.

Each drawing plays once as it scrolls in; its numbered lines say what is happening. Click a line to watch from there.

01 · tools

A tool is a Go function.

A typed input struct in, a JSON Schema out. Errors, panics and timeouts reach the model as results.

weft.Tool weft.Timeout weft.ToolError

02 · loop

Tools run in parallel.

Each call runs on its own goroutine; results return in call order. When order matters, weft.Sequential().

weft.New agt.Generate weft.Sequential

03 · sessions

Conversations that last.

An append-only log that survives restarts. jsonl, SQLite and memory are built in; any database plugs in through thread.Storage.

s.Steer s.Fork s.Compact s.Uncompact thread.Storage

04 · record

Every run is recorded.

Standard OpenTelemetry, to a local file, Studio or any backend.

otel.Install otel.Slog

05 · studio

See exactly what happened.

Every step, tool call and exact request in one tree, with cost, search and what each middleware layer decided. The Agents page charts every agent's numbers.

weft dev studio.Handler weft mcp

06 · replay

Change it. Replay any step.

Edit the prompt, a tool result or the model, and rerun from that step, or replay up to 20 failures of one error class side by side. Side-effect tools never fire twice.

weft/runtime runtime.Install

07 · panel

Right beside your app.

One script tag docks the devtools panel next to your page. It follows each turn live, or a whole batch of runs by agent, flow or tag.

panel.js scope.Header scope.WithFlow

08 · more

Everything else, built in.

  • ApprovalsRequireApproval
  • Subagentsweft.Subagent
  • MCP, both waysmcp.Tools · Serve
  • Structured outputweft.Output[T]
  • Streamingagt.Stream
  • Middlewaremw.Retry · Fallback
  • BudgetsMaxSteps · UsageLimit
  • Child sessionsthread/pool
  • Offline testswefttest.Replay
  • Loop controlStopWhen · DetectLoops
  • Thinking & imagesweft.Thinking · FilePart
  • ProvidersOpenAI · Anthropic · Gemini

the api

An API you already know.
So does your coding agent.

Bad arguments, errors, panics and timeouts become results the model reads. ToolError gives it a code; ModelRetry asks for new arguments.

type LookupInput struct {
    OrderID string `json:"order_id" jsonschema:"the order to look up"`
}

lookup := weft.Tool("lookup_order", "Look up an order by ID.",
    func(ctx context.Context, in LookupInput) (Order, error) {
        o, err := db.Find(ctx, in.OrderID)
        if errors.Is(err, sql.ErrNoRows) {
            return Order{}, &weft.ToolError{Code: "ORDER_NOT_FOUND",
                Message: "no order " + in.OrderID}
        }
        return o, err
    },
    weft.Timeout(5*time.Second))

agt := weft.New(anthropic.Model("claude-sonnet-5"), lookup)
res, err := agt.Generate(ctx, weft.Prompt("Where is order 1042?"))

Build it once, run it from many goroutines. Budgets, middleware and MCP tools are options; Studio shows each call's middleware chain and what every layer decided.

gh, _ := mcp.Tools(ctx, sess, mcp.Server("github"), mcp.Prefix("gh_")) // origin mcp:github

agt := weft.New(model,
    weft.Instructions("You are a support agent."),
    weft.StopWhen(weft.HasToolCall("submit")),
    weft.MaxSteps(20),
    weft.UsageLimit(weft.Usage{OutputTokens: 50_000}),
    weft.WrapModel(mw.Retry(), mw.Fallback(backup)),
    weft.WrapTools(mw.Audit(logger)),
    weft.ToolSource(func() []*weft.ToolDef { return gh }),
    lookup, refund,
)
// and the other way: mcp.Serve(srv, agt, "Support agent.")

A range loop over typed events. Cancel with context.

for ev, err := range agt.Stream(ctx, prompt).Events() {
    if err != nil {
        return err
    }
    switch ev := ev.(type) {
    case weft.TextDelta:
        io.WriteString(w, ev.Text)
    case weft.ToolStart:
        slog.Info("tool", "name", ev.Name)
    }
}

The answer, decoded into your struct, on every provider.

type Verdict struct {
    Approved bool   `json:"approved"`
    Reason   string `json:"reason"`
}

agt := weft.New(model, weft.Output[Verdict](), lookup)
v, res, err := weft.GenerateAs[Verdict](ctx, agt, prompt)

A gated call parks the run. Resume it with the decision.

refund := weft.Tool("refund", "Refund an order.", doRefund,
    weft.RequireApproval())

res, _ := agt.Generate(ctx, weft.Prompt("Refund order 42"))
call := res.Pending[0] // ask someone: Slack, a UI, email

res, _ = agt.Generate(ctx, weft.Messages(res.Messages...),
    weft.Approve(call.ID))

An append-only log. Steer, branch, fork and compact; a crash loses nothing.

st, _ := jsonl.Open(dir) // or sqlite, Memory(), or your own thread.Storage
s, _ := thread.Create(ctx, st, agt)

turn, _ := s.Send(ctx, weft.User("Where is order 1234?"))
s.Steer(ctx, "", weft.User("Ship it to my work address."))
res, _ := turn.Wait()

// after a restart: the same conversation
s, _ = thread.Open(ctx, st, id, agt)

A subagent is a tool: its events nest, its usage adds up.

researcher := weft.New(model, searchTool)

orchestrator := weft.New(model,
    weft.Subagent("research", "Research in depth.",
        researcher, weft.Timeout(2*time.Minute)))

OpenTelemetry to several destinations at once, each with its own content policy.

defer otel.Install(
    otel.Local(".weft/weft.db"),   // local SQLite, replay-grade
    otel.Studio(studioURL, token),
    otel.Datadog(),                 // content off by default
    otel.Content(otel.ContentConfig{Redact: redact}),
    otel.Slog(),                    // app log lines, under the run
)()

One script tag docks the devtools panel beside your page. It follows a conversation, or a batch of runs named by agent, flow or tag.

// the panel follows the conversation each response names
h := scope.Header(chat, func(r *http.Request) scope.Scope {
    return scope.Scope{PublicID: conversationID(r)}
})

// or a batch: tag the runs, then scope the panel to the tag
ctx = weft.WithMetadata(ctx, map[string]string{"eval.batch": "nightly"})
// <script type="module" src="/studio/panel.js" data-weft
//         data-scope="tag.eval.batch=nightly"></script>

go test, no network: a scripted model, or a real one recorded once.

model := wefttest.Script(
    wefttest.ToolCalls(wefttest.Call{
        Name: "lookup_order", Args: `{"id":"1042"}`}),
    wefttest.Say("Order 1042 has shipped."),
)

// or record a real model once, replay it forever
model = wefttest.Replay(t, "testdata/order")

Full reference on pkg.go.dev.

get started

Start with one Go file.

Or ask your coding agent: it reads AGENTS.md and llms.txt, and every docs page has a Markdown twin.