---
title: How weft is put together
description: 'weft is two Go modules: the framework github.com/weftgo/weft, whose root package is a generated facade over core, and github.com/weftgo/weft/core, the loop alone with the OpenTelemetry API as its only dependency.'
url: https://weftgo.dev/docs/explanation/architecture/
type: concept
sources:
  - weft/docs/adr/0027-framework-module-and-core.md:1-83
  - 'weft/AGENTS.md:1-18 (intro: two modules, the facades, make generate)'
  - weft/AGENTS.md:687-689 (rule 6), 693-706 (rule 10)
  - weft/README.md:964-972 (one dependency in core), 974-1017 (Layout and the two-modules paragraph)
  - weft/go.mod:1-20, weft/core/go.mod:1-17, weft/go.work:1-8
  - weft/facade.go:1-6 (generated by internal/cmd/genfacade from ./core), 367 (type Agent = core.Agent), 1139 (type Model = core.Model)
  - weft/facade_test.go:48 (TestFacadesAreComplete)
  - 'go list -f ''{{.Imports}}'' at v0.17.0: the root, openai, anthropic, google, mcp, thread, obsdb and scope import core; mw and wefttest import the root and core/mw, core/wefttest; thread/sqlite and thread/jsonl import thread and thread/backend; thread/pool imports core and thread; otel imports core, obsdb, obsdb/sqlite; studio imports core, obsdb, obsdb/sqlite; runtime imports core, obsdb, otel, studio, thread; cmd/weft imports obsdb, obsdb/clickhouse, obsdb/sqlite, studio; core imports nothing of weft'
  - weft/core/agent.go:176 (PrepareStep), 271 (WrapModel), 451 (Tap), 483 (OnRunEnd)
  - weft/core/tool.go:580 (WrapTools)
  - weft/docs/adr/0006-seams.md, weft/docs/adr/0016-observability.md, weft/docs/adr/0024-observability-data.md
  - weft/otel/pipeline.go:218 (Start), 226-240 (environment and discovery destinations), 332-342 (Install; the local sink only with no options and no environment destinations), 857 (LocalDB)
  - weft/otel/env.go:37-61 (WEFT_STUDIO_URL, OTEL_EXPORTER_OTLP_ENDPOINT as destinations), 156-169 (the discovery file)
  - 'weft/scripts/ux-gate/gate8.sh:204-207 (clause k1: rule 6)'
  - weft/facade_test.go:41-48 (TestFacadesAreComplete, a test that skips outside the repo)
  - weft/obsdb/db.go:26 (DB)
  - weft/studio/studio.go:56 (DB), 247 (New), 313 (Handler); weft/studio/doc.go:1-30 (the three setups)
  - weft/studio/assets.go:18-22 (go:embed all:dist); weft/studio/web/package.json:18-28 (TanStack Start, React)
  - 'weft/CHANGELOG.md:5501-5509 (studio 0.1.0: a prebuilt SPA embedded in studio/dist, no build step for users, offline by construction)'
  - weft/runtime/options.go:279 (Install), weft/runtime/breakpoints.go:80 (Breakpoints)
  - weft/scope/scope.go:1, 230 (Header)
  - weft/mcp/client.go:111 (Tools), weft/mcp/server.go:144 (Serve)
---

# How weft is put together

weft is two Go modules. [`github.com/weftgo/weft`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2) is the framework: one `go get`, one version, every package from the provider adapters to Studio. [`github.com/weftgo/weft/core`](https://pkg.go.dev/github.com/weftgo/weft/core@v0.20.2) is the agent loop alone, and its only dependency is the OpenTelemetry API. The framework's root package is a generated [facade](https://weftgo.dev/docs/reference/glossary/#facade) over `core`, so `weft.Agent` and `core.Agent` are the same type.

## 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](https://weftgo.dev/docs/explanation/repository/#where-things-live).

| 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](https://weftgo.dev/docs/get-started/install/) shows both.

## 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](https://weftgo.dev/docs/explanation/repository/) covers the gate.

Three rules follow from the facade:

- **User code imports `weft`; the layers import `core`.** `thread`, `otel`, `studio` and the adapters name `core.Model` and `core.Agent` in their signatures. An application holding a `weft.Model` passes the same type, so nothing converts.
- **Definition sites skip the facade.** `weft.Tool`, `weft.Output` and `weft.Subagent` record the caller's file and line for the [manifest](https://weftgo.dev/docs/guides/manifest/). The recorder walks past frames in the facade package, so `weft.json` names your file, not `facade.go`.
- **Methods live on `core`'s page.** pkg.go.dev lists no methods under an alias, so `Agent.Generate` is documented at [`core.Agent.Generate`](https://pkg.go.dev/github.com/weftgo/weft/core@v0.20.2#Agent.Generate).

## 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](https://weftgo.dev/docs/explanation/design-principles/#the-loop-rules)). 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).

> **Diagram:** The module github.com/weftgo/weft holds four layers, top to bottom: the UI (studio, runtime), recording (otel, obsdb), sessions (thread) and the loop, whose root package weft is a generated facade over core. Imports point down: each layer imports only the layers below it, and nothing imports upward. The loop itself, core, is its own module, github.com/weftgo/weft/core, and its only dependency is the OpenTelemetry API.

| 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

Inside the loop there are exactly two places code can change behaviour and one place it can watch (rule 10, ADR 0006):

- [`weft.WrapModel`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#WrapModel) wraps the model call: `func(next weft.Model) weft.Model`. `mw.Retry` and `mw.Fallback` sit here.
- [`weft.WrapTools`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#WrapTools) wraps each tool call: `func(next weft.ToolCaller) weft.ToolCaller`, per agent or per tool. `mw.Allow`, `mw.Audit` and `mw.MapErrors` sit here.
- [`weft.Tap`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Tap) observes every event and changes nothing.

Everything else is configuration the loop reads, not a hook. [`weft.PrepareStep`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#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](https://weftgo.dev/docs/explanation/agent-loop/#the-eleven-questions) explains why the field's lifecycle hooks were refused.

## 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.

> **Diagram:** Your app runs agents with agt.Generate; every run leaves as OpenTelemetry spans and log records. otel.Install starts the pipeline and sends them to every destination at once; with no options and no destination named by the environment it writes the local sink only. otel.Local writes .weft/weft.db synchronously; otel.Studio exports OTLP over HTTP to a running weft studio. The Inspector reads them back: embedded with studio.Handler over otel.LocalDB(), or served by weft studio.

1. **The pipeline, `otel`.** [`otel.Install`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Install) builds 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 add `otel.Local`.
2. **The record, `obsdb`.** [`obsdb.DB`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DB) is 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.LocalDB`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#LocalDB) returns the local sink's handle.
3. **The Inspector, `studio`.** [`studio.Handler`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#Handler) serves the UI, the JSON API, the live stream and OTLP ingest over one `obsdb.DB`. Embedded beside the app with `studio.DB(otel.LocalDB())` (setup A), it shares the sink's in-process live hub. Run as `weft studio` (setup B), it ingests OTLP from any process, in any language.

### 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](https://weftgo.dev/docs/observe/studio/setup/) has the setups.

Two packages connect the app to Studio in the other direction. [`runtime.Install`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Install) dials Studio out so the playground can run experiments as runs of the agents you register. [`scope.Header`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/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

- **No layer is required.** A program that imports `core` alone has a working agent loop, offline tests through `core/wefttest`, and spans through whatever OpenTelemetry SDK it registers.
- **No reverse imports.** The core cannot call `otel`, and `obsdb` cannot call `studio`. 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`, `runtime` and `studio` may change incompatibly in a minor release; `core`'s API is gated (see [Upgrade between releases](https://weftgo.dev/docs/production/upgrading/)).

## See also

- [Design principles: the rules weft keeps](https://weftgo.dev/docs/explanation/design-principles/)
- [How the weft repository is organised and checked](https://weftgo.dev/docs/explanation/repository/)
- [Install weft and choose a module](https://weftgo.dev/docs/get-started/install/)
- [Record runs](https://weftgo.dev/docs/observe/recording/)
- [Architecture decision records](https://weftgo.dev/docs/explanation/decisions/)

Symbols used: [`weft.WrapModel`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#WrapModel) · [`weft.WrapTools`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#WrapTools) · [`weft.Tap`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Tap) · [`weft.PrepareStep`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#PrepareStep) · [`weft.OnRunEnd`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#OnRunEnd) · [`weft.Tool`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Tool) · [`weft.Subagent`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Subagent) · [`core.Agent`](https://pkg.go.dev/github.com/weftgo/weft/core@v0.20.2#Agent) · [`otel.Install`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#Install) · [`otel.LocalDB`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/otel#LocalDB) · [`obsdb.DB`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/obsdb#DB) · [`studio.Handler`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#Handler) · [`studio.DB`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#DB) · [`runtime.Install`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Install) · [`scope.Header`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/scope#Header)
