Install weft and choose a module
Run go get github.com/weftgo/weft@v0.20.2 in a module on Go 1.26 or newer: that one module is the whole framework — the loop, the provider adapters, sessions, recording and Studio. If you want the agent loop and nothing else, go get github.com/weftgo/weft/core@v0.20.2 instead. The weft command line installs separately, with go install.
go get github.com/weftgo/weft@v0.20.2A typical app then imports the root package, one provider adapter and the recorder:
import ( "context" "fmt" "log"
"github.com/weftgo/weft" // the loop: Tool, New, Generate "github.com/weftgo/weft/anthropic" // a provider adapter "github.com/weftgo/weft/otel" // the recorder: otel.Install)How it works
Section titled “How it works”weft is two Go modules tagged at the same version. github.com/weftgo/weft holds the root package and every layer (openai, anthropic, google, mcp, mw, wefttest, thread, otel, obsdb, studio, runtime, scope). github.com/weftgo/weft/core holds the loop alone and depends only on the OpenTelemetry API. The root package re-exports core: weft.Agent is core.Agent.
Your go.mod lists every layer’s dependencies, but Go compiles only the packages you import. weft/otel brings in SQLite (modernc.org/sqlite) for its local sink; the ClickHouse driver is linked only through weft/obsdb/clickhouse, which the weft command imports.
Choose a module
Section titled “Choose a module”| You want | go get | You import |
|---|---|---|
| The framework: the loop plus any layer | github.com/weftgo/weft@v0.20.2 | weft, and weft/anthropic, weft/otel, weft/thread, … as needed |
| The loop alone, with the smallest dependency list | github.com/weftgo/weft/core@v0.20.2 | core, core/wefttest, core/mw |
Choose the framework unless your service must not carry the other layers’ dependencies in its module graph. The two are interchangeable at the type level, so you can start with core and move to weft later without changing a type.
Check your Go version
Section titled “Check your Go version”weft requires Go 1.26 or newer:
go versionThe current and the previous Go release are supported, and CI tests both.
Add a provider
Section titled “Add a provider”The first-party adapters for OpenAI, Anthropic and Google are packages of the framework module: import github.com/weftgo/weft/openai, …/anthropic or …/google and run go mod tidy, which fetches the vendor SDK the adapter wraps. Each adapter reads its key from the environment by default:
| Adapter | Constructor | Key read by default |
|---|---|---|
weft/anthropic | anthropic.Model(name, opts...) | ANTHROPIC_API_KEY |
weft/openai | openai.Model(name, opts...) | OPENAI_API_KEY |
weft/google | google.Model(name, opts...) | GOOGLE_API_KEY or GEMINI_API_KEY, then application default credentials |
Each adapter’s APIKey option sets the key in code instead. Connect a model provider covers every adapter option.
Install the weft command
Section titled “Install the weft command”The weft binary serves Studio for apps in any language, runs the dev loop, and lists, opens and exports runs. It is the package cmd/weft of the framework module:
go install github.com/weftgo/weft/cmd/weft@v0.20.2weft versionv0.20.2weft --help lists its commands: studio, dev, runs, open, export, doctor, mcp, vacuum and version. The weft CLI reference documents every flag.
Complete example
Section titled “Complete example”The file the imports above come from: it records one run of an Anthropic-backed agent.
// Command install is the Install page's program: the usual import set of a// weft app — the framework's root package, one provider adapter, and the// recorder — in one file that builds and runs.package main
import ( "context" "fmt" "log"
"github.com/weftgo/weft" // the loop: Tool, New, Generate "github.com/weftgo/weft/anthropic" // a provider adapter "github.com/weftgo/weft/otel" // the recorder: otel.Install)
// run records one run of an agent over model and returns its answer.func run(ctx context.Context, model weft.Model) (string, error) { defer otel.Install(otel.Local(""))() // ./.weft/weft.db, plus any Studio the environment names
agt := weft.New(model, weft.Instructions("Answer in one sentence.")) res, err := agt.Generate(ctx, weft.Prompt("What is a goroutine?")) if err != nil { return "", err } return res.Text(), nil}
func main() { // Reads $ANTHROPIC_API_KEY. text, err := run(context.Background(), anthropic.Model("claude-sonnet-5")) if err != nil { log.Fatal(err) } fmt.Println(text)}export ANTHROPIC_API_KEY=… # your keygo mod tidygo run .go test ./...The page’s test runs the same run function on a scripted model and reads the recorded run back from the local database (install/main_test.go).
Best practices & gotchas
Section titled “Best practices & gotchas”- Run
go mod tidyafter adding an adapter import.go get github.com/weftgo/weftdoes not record the vendor SDK’s checksums; untilgo mod tidyruns, the build fails withmissing go.sum entry. (Source: observed withgo run .in a fresh module) - Do not mix the retired per-layer modules with 0.9.0 or later. Before 0.9.0 each layer (
thread,otel, …) was its own module. Ago.modthat requires one of those paths and the framework fails with an ambiguous-import error;MIGRATION-0.9.mdin the weft repository is the fix. (Source: ADR 0027, Consequences) - Keep test suites off the network. Set
WEFT_MODEL_REQUESTS=denyand every first-party adapter that built its own client refuses to call its provider, failing withErrModelRequestsDenied. (Source: AGENTS.md;install/main_test.go:TestAnthropicDenied)
See also
Section titled “See also”- What is weft, and when should you not use it?
- How weft is put together
- Connect a model provider: OpenAI, Anthropic, Gemini
- Use the weft command
- Upgrade weft
Symbols used: weft.Tool · weft.Agent · core.Agent · weft.New · weft.Instructions · weft.Prompt · weft.ErrModelRequestsDenied · anthropic.Model · anthropic.APIKey · openai.Model · google.Model · otel.Install