How weft is put together
weft is two Go modules. github.com/weftgo/weft is the framework: one go get, one version, every package from the provider adapters to Studio. github.com/weftgo/weft/core is the agent loop alone, and its only dependency is the OpenTelemetry API. The framework’s root package is a generated facade over core, so weft.Agent and core.Agent are the same type.
Layout
Section titled “Layout”The layout is two modules; ADR 0027 split the repository this way in 0.9.0. Before it, github.com/weftgo/weft was the loop and every layer was its own module with its own tag, so a release note ended in a compatibility sentence such as “requires weft v0.8.0 and thread v0.9.1”. The split keeps the property the old layout had, a loop whose dependency list is the OpenTelemetry API, and removes the version matrix. The directory-by-directory layout is in How the weft repository is organised and checked.
| Module | Holds | Depends on |
|---|---|---|
github.com/weftgo/weft | the root facade, openai, anthropic, google, mcp, mw, wefttest, thread (+ sqlite, jsonl, pool), otel, obsdb (+ sqlite, clickhouse), studio, runtime, scope, cmd/weft | core at the same version, the vendor SDKs, the MCP Go SDK, the OpenTelemetry SDK and exporters, SQLite and the ClickHouse driver |
github.com/weftgo/weft/core | the loop: agents, tools, messages, events, errors, the model contract, core/mw, core/wefttest | the OpenTelemetry API: go.opentelemetry.io/otel, go.opentelemetry.io/otel/log, go.opentelemetry.io/otel/trace |
A release is two tags in order: the core module’s tag (core/ plus the version), then the root, tidied against it, tagged with the bare version. The root’s go.mod requires core at that exact version with no replace; go.work joins the two modules (and two example modules) for development.
The cost is stated in the ADR: a program that requires the framework carries every layer’s dependencies in its module graph. Only the packages it imports are compiled and linked, so the cost is go.sum lines and downloads. A program that wants none of it imports core. Install weft and choose a module shows both.
Why the root package is a facade
Section titled “Why the root package is a facade”The root package weft declares nothing of its own. Every exported name of core exists in it as a type alias (type Agent = core.Agent), a constant or variable bound to the original, or a one-line wrapper function, so signatures, generics and doc comments survive on pkg.go.dev. mw, wefttest and wefttest/conformance are the same kind of facade over core/mw, core/wefttest and core/wefttest/conformance.
The facades are generated, not written. internal/facadegen produces them from core’s source (facade.go starts Code generated by internal/cmd/genfacade; DO NOT EDIT.), make generate regenerates them, and TestFacadesAreComplete fails make test when a facade lacks a name its source exports or differs from what the generator writes. How the weft repository is organised and checked covers the gate.
Three rules follow from the facade:
- User code imports
weft; the layers importcore.thread,otel,studioand the adapters namecore.Modelandcore.Agentin their signatures. An application holding aweft.Modelpasses the same type, so nothing converts. - Definition sites skip the facade.
weft.Tool,weft.Outputandweft.Subagentrecord the caller’s file and line for the manifest. The recorder walks past frames in the facade package, soweft.jsonnames your file, notfacade.go. - Methods live on
core’s page. pkg.go.dev lists no methods under an alias, soAgent.Generateis documented atcore.Agent.Generate.
The layers and the import rule
Section titled “The layers and the import rule”Imports point down. The core imports nothing above it: no HTTP, no database, no tracing backend (rule 6 of Design principles). Because core is its own module, any import from outside it needs a require line in core/go.mod, and the release gate checks both (clause k1 of scripts/ux-gate/gate8.sh: no package outside the core module among core’s dependencies, core/go.mod and go.sum unchanged).
| Layer | Packages | Imports from weft |
|---|---|---|
| The loop | core, core/mw, core/wefttest | nothing outside the core module (core/mw and core/wefttest import core) |
| The facade | root weft, mw, wefttest | core (and, for mw and wefttest, the root) |
| Providers and interop | openai, anthropic, google, mcp, scope | core |
| Sessions | thread; thread/jsonl, thread/sqlite (storage); thread/pool | core; the storage packages import thread and thread/backend |
| The record | obsdb, obsdb/sqlite, obsdb/clickhouse | core, obsdb |
| The pipeline | otel | core, obsdb, obsdb/sqlite |
| The Inspector | studio | core, obsdb, obsdb/sqlite |
| The playground | runtime | core, obsdb, otel, studio, thread |
| The binary | cmd/weft | obsdb, its two backends, studio |
Each row may import the rows above it and none below. The record (obsdb) knows nothing of the pipeline that writes it or the Inspector that reads it. thread knows the loop and nothing about recording: a session’s runs are recorded because the loop reports through the OpenTelemetry providers otel.Install registered, not because thread imports otel.
Where behaviour attaches: two seams and one tap
Section titled “Where behaviour attaches: two seams and one tap”Inside the loop there are exactly two places code can change behaviour and one place it can watch (rule 10, ADR 0006):
weft.WrapModelwraps the model call:func(next weft.Model) weft.Model.mw.Retryandmw.Fallbacksit here.weft.WrapToolswraps each tool call:func(next weft.ToolCaller) weft.ToolCaller, per agent or per tool.mw.Allow,mw.Auditandmw.MapErrorssit here.weft.Tapobserves every event and changes nothing.
Everything else is configuration the loop reads, not a hook. weft.PrepareStep rewrites the request before the model seam (ADR 0006’s amendment calls it “the one loop knob”). weft.OnRunEnd and weft.OnMessages are observers like Tap. The loop’s OpenTelemetry spans and log records are its own reporting at fixed phases (ADR 0016), emitted through the API that weft.TracerProvider and weft.LoggerProvider point at, and a no-op until an SDK registers. A third seam needs an ADR. The agent loop, from first principles explains why the field’s lifecycle hooks were refused.
From a run to Studio: the pipeline, obsdb and the Inspector
Section titled “From a run to Studio: the pipeline, obsdb and the Inspector”The loop reports; something else records. Three packages share the work, joined by the OpenTelemetry data model rather than by Go calls.
- The pipeline,
otel.otel.Installbuilds OpenTelemetry tracer and logger providers with one or more destinations, each with its own content policy, and installs them as the global providers the loop reports through. With no options it writes the local sink,./.weft/weft.db, unless the environment names a destination:WEFT_STUDIO_URL,OTEL_EXPORTER_OTLP_ENDPOINT, or a running Studio’s discovery file each become a destination, and then no local sink is written unless you addotel.Local. - The record,
obsdb.obsdb.DBis the observability database: runs, records, spans and app logs, with a SQLite backend (the local sink) and a ClickHouse backend. It is the only thing the Inspector reads;otel.LocalDBreturns the local sink’s handle. - The Inspector,
studio.studio.Handlerserves the UI, the JSON API, the live stream and OTLP ingest over oneobsdb.DB. Embedded beside the app withstudio.DB(otel.LocalDB())(setup A), it shares the sink’s in-process live hub. Run asweft studio(setup B), it ingests OTLP from any process, in any language.
Studio
Section titled “Studio”The UI is a single-page app (TanStack Start and React, built with Bun) prebuilt into studio/dist, committed, and embedded with go:embed. A user of studio needs Go only: there is no build step, and the page loads nothing from another origin. The devtools panel, /panel.js, is served by the same handler and reads the same API. Run Studio has the setups.
Two packages connect the app to Studio in the other direction. runtime.Install dials Studio out so the playground can run experiments as runs of the agents you register. scope.Header tells the devtools panel which conversation an HTTP response belongs to. Neither is imported by the core or by thread.
What this layout does not do
Section titled “What this layout does not do”- No layer is required. A program that imports
corealone has a working agent loop, offline tests throughcore/wefttest, and spans through whatever OpenTelemetry SDK it registers. - No reverse imports. The core cannot call
otel, andobsdbcannot callstudio. A feature “for the UI” that would need the core to know about Studio is a design error, not a missing import. - No single version per layer. The layers ship at the framework’s version. Pre-1.0,
thread,obsdb,otel,runtimeandstudiomay change incompatibly in a minor release;core’s API is gated (see Upgrade between releases).
See also
Section titled “See also”- Design principles: the rules weft keeps
- How the weft repository is organised and checked
- Install weft and choose a module
- Record runs
- Architecture decision records
Symbols used: weft.WrapModel · weft.WrapTools · weft.Tap · weft.PrepareStep · weft.OnRunEnd · weft.Tool · weft.Subagent · core.Agent · otel.Install · otel.LocalDB · obsdb.DB · studio.Handler · studio.DB · runtime.Install · scope.Header