Adoption paths
Six ways onto one record for regulated work: a typed, hash-chained row per model call in your own database. Each path says which evidence mechanisms an auditor gets from it, which are on by default, and which you turn on.
Ways onto the record
Every path below writes to the same record: one typed, hash-chained row per model call, in your own database. That record is what a reviewer under 21 CFR Part 11, ALCOA+, HIPAA, GDPR, the EU AI Act or SOC 2 reads. The paths differ in who drives the turn, and so in which evidence mechanisms the path gets. The last column says what each path gives an auditor and what is on by default. Part 11 and ALCOA+ summarizes, by topic, what Pleach provides and what you still provide.
Pick the row that describes you; each names the first step and the page to read next.
Not on npm yet
@pleach/* packages aren't on npm yet. Some names are reserved with 0.0.1 placeholders. Each package's first real release ships under FSL-1.1-Apache-2.0. The commands on this page describe the install once it lands. Packages tracks each package's status.| You are | Start here | First step | Read next | For a regulated deployment | What this path does not give you |
|---|---|---|---|---|---|
| A1. New to agents, no runtime yet | One route, one page, rows you can see. | In a Next.js App Router project, run npx @pleach/core create, set a provider key, chat, then open /audit. | Getting started, Quickstart | A chained row per model call and the default PII redactor, both on. Point the route at Postgres to keep the rows past a restart; from there it is A2. | Nothing to give up; you start on the runtime. |
| A2. You know a runtime, new project | Start on Pleach instead of adding it later. | Mount createPleachRoute() as your chat route; for Postgres, npx @pleach/core migrate --database-url <url>. | Quickstart, CLI | Chained rows in your Postgres and the default PII redactor, both on. Approval gates, keyed chaining, an event log with WORM and retention, RFC 3161 anchoring and erasure are steps you take: turn each on, and wire a key store for erasure. | Nothing to give up; you start on the runtime. |
| B. Keep your loop, record each call | Keep your loop. Record each call. | init from @pleach/observe, then your host's integration (for the AI SDK, createObserveMiddleware). | @pleach/observe | The same chained row when pointed at Postgres or a ledger, with the default PII redactor on the Postgres destination. One row per call your hook sees. No event log, so approval gates, WORM, retention and attestation come via core. | No family lock, replay or checkpoints; those need the runtime. |
| C. Keep your provider and store, let Pleach drive the turn | Keep your provider and store. Pleach drives the turn over them. | createPleachRuntime({ provider }), or createBrownfieldRuntime with your storage and a paired checkpointer such as PgSaver. | Pick core-brownfield | Everything core writes, over your infra: chained rows when the ledger is Postgres, a chained row for every rollback, and the same opt-ins as A2. A custom provider writes one row per call rather than per attempt. | Your store must pair storage with a checkpointer. |
| D. Move one feature at a time | Move one feature at a time. | Convert tools with fromAiSdkTools / fromLangChainTools, bring threads over with importSessions. | Migrating from the AI SDK, from LangChain | Core's mechanisms for the features you've moved. The rest writes the observe row if you wrap it with B, and nothing otherwise. | The parts you haven't moved stay outside the record. |
| E. Replace your runtime | Replace your runtime; bring your history. | A runtime on core (new SessionRuntime({ provider })) plus the importers. | Migrating from the AI SDK, Landscape | The same as C for every turn core runs. Imported threads carry their messages, not call rows: the chain starts at the first turn on core. | Your old runtime's own features, until you rebuild them on core. |
// A2: the chat route in an existing Next.js app
import { createPleachRoute } from "@pleach/core/quickstart";
export const POST = createPleachRoute();
// B: observe a loop you keep (AI SDK shown)
import { wrapLanguageModel } from "ai";
import { init, createObserveMiddleware } from "@pleach/observe";
init({ destination }); // a destination from @pleach/observe/destinations
const model = wrapLanguageModel({ model: openai("gpt-4o-mini"), middleware: createObserveMiddleware() });
// C: core drives the turn over your provider; the model comes from the provider
import { createPleachRuntime, AiSdkProvider } from "@pleach/core";
const runtime = createPleachRuntime({ provider: new AiSdkProvider({ model: openai("gpt-4o-mini") }) });
// D: move tools and threads one at a time
import { definePleachPlugin, fromAiSdkTools } from "@pleach/core";
import { importSessions } from "@pleach/core/sessions";
const plugin = definePleachPlugin("my-app", { tools: fromAiSdkTools(tools) });
await importSessions(threads, { storage, checkpointer, userId });Why one path, not a mix. An application runs one runtime, so its capabilities are graded together on that host: your host's page (for example the AI SDK or Mastra) is the baseline you compare against. The four interactions (rows per attempt, a chain that holds, resume without forking, replay beside erasure) are written for B to E, readers who already run a runtime. If you're A1 or A2, skip it and start with the first step above.
What each path gives an auditor
The same mechanisms, read across the two ways a turn can run. "Core" covers A1, A2, C, E and the features you have moved under D; "Observe" covers B and the parts of D you wrap with it. Requirements are listed only for mechanisms that ship and work today; the Part 11 page has the full mapping and what you still provide.
| Mechanism | Core | Observe | Requirement it supports |
|---|---|---|---|
| Hash-chained row per model call | On, when the ledger is Postgres. The in-memory default ledger is for tests and local runs, not a record. | On, when the destination is Postgres or a ledger you pass. OTel and in-memory destinations get telemetry, not the chained row. | Part 11 · HIPAA · SOC 2 |
| A row for each attempt, including one that ends in an abort or error | On through the built-in providers, retries included. A custom provider writes one row per call. | One row per call your hook sees: per attempt with the AI SDK middleware, one per invocation with LangChain. | EU AI Act · ALCOA+ |
| One order under parallel writers | You provide a store with compare-and-set; the bundled stores have one. | The same, through the Postgres destination's ledger. | ALCOA+ |
| Keyed (HMAC) chaining | Opt-in: pass a signing key to the ledger. | Opt-in: configure it on a ledger you pass in. | — |
| PII redactor on call rows | On. Opt out with piiRedactorNoop(). | On for the Postgres destination's own ledger; a ledger you pass in uses its own setting. Tags are copied only with ledgerPayload. | GDPR |
| Compliance-profile scrubbers | Opt-in. A PHI scrubber is a separate opt-in. | Your redactor or the redact: policy. | — |
| Approval gates, each decision a chained row | Opt-in per tool; the decision is written to the event log you wire. | Via core. | EU AI Act · Part 11 |
| Permission grants as ledger rows | Recorded as rows. The bundled local server signs them with Ed25519; in your own host, signPermissionRow from @pleach/core/audit/permission-ledger signs them with a key you provide. | Via core. | — |
| Rollback writes a chained row | On, in the event log you wire. | Via core: observe has no checkpoints. | Part 11 |
| Event log and call ledger made append-only (WORM) | Opt-in tier on Postgres. Covers the event log and the call-row table, and records every disposal. | The call-row table, when the Postgres destination writes it; the event log via core. | Part 11 |
| Retention pass that honours legal holds | Opt-in on Postgres, one pass for event-log chains and one for call-row sessions; you set the period and run the pass. | Via core. | Part 11 · GDPR · EU AI Act |
| RFC 3161 time-stamps over event-log segments | Opt-in: you choose the authority. The scheduling recipe is experimental, and so is anchoring call rows. | Via core. | — |
| Fork linked to its parent row's hash | Experimental. On when your event-log writer uses the v3 chain identity (c9ChainIdentity, experimental); pass forkParentRowReader: null to turn it off. | Via core. | — |
| Erasure that keeps the chain verifying | Opt-in on Postgres: wire a key store and per-subject keys. | Via core. | GDPR |
| Attestation envelopes | Beta. Wire your key store to sign envelopes. | Via core. | — |
Human-readable copies (queryAudit, exportAuditPdf) | Opt-in. The PDF needs the optional pdfkit peer. | Via core. | Part 11 |
Audit reports (produceAuditReport) | Beta, opt-in. | Via core. | — |
Validation, electronic signatures, identity and your procedures stay with you on every path.
The three shapes underneath
There are three ways to adopt Pleach. They differ on one axis: who owns the turn loop, and what happens to the infrastructure you already run.
- Observe brownfield. You keep the loop. Add the
@pleach/observeSDK around it and it watches: it records each call you hand it, no behavior change. - Core brownfield (adapter graft). Core owns the loop, but your provider client, your database, and your tools stay yours — wrapped as adapters. Your loop code moves into core's turn loop; your infra stays, including what core has no built-in adapter for.
- Greenfield. Core owns the loop and you build on core's
defaults — the Memory/Supabase adapters,
AiSdkProvider, base-tools. Nothing existing to wrap.
The one-liner that separates them: observe watches; core
governs; and core-brownfield lets core govern while your infra
stays yours. @pleach/observe writes a chained row to the same table and chain the runtime writes to when pointed at Postgres (or any ledger you pass); OTel and in-memory destinations get telemetry. That row carries the tenant, the cost and the leaf sub-agent; tags and the full sub-agent path are copied only with the ledgerPayload option. The cost
shape and the feature ceiling are different.
This page is the decision. The per-stack walkthroughs
(Vercel AI SDK,
LangChain,
Anthropic Enterprise,
OpenAI Enterprise)
sit downstream of it. The migration guides are the
recognized-provider case of core-brownfield: core ships
AiSdkProvider, and @pleach/langchain ships LangChainProvider,
so your provider drops in. When your infra is bespoke, the same graft works — you
implement the adapter interface yourself.
The three paths
| Observe brownfield (SDK) | Core brownfield (adapter graft) | Greenfield (runtime) | |
|---|---|---|---|
| Package | @pleach/observe | @pleach/core | @pleach/core |
| Who owns the turn loop | You | Core | Core |
| Your existing infra | Untouched | Wrapped as adapters (provider · store · tools) | Replaced by core defaults |
| Adoption shape | init once, then recordCall after each LLM call | Implement OrchestratorAdapter + StorageAdapter over your infra; one plugin for domain logic | New SessionRuntime on core defaults |
| Behavior change | None (watch only) | Full runtime governance | Full runtime governance |
| Event-log mechanisms (approval rows, WORM, retention, time-stamps) | Via core | Opt-in, on the event log you wire | Opt-in, on the event log you wire |
| Audit row | The runtime's chained AuditableCall row when pointed at Postgres or a ledger; telemetry for OTel and in-memory. | Full AuditableCall, hash-chained by default. | Full AuditableCall, hash-chained by default. |
| Destinations | Postgres / Supabase / OTel / Memory / custom. | Your store, wrapped as a StorageAdapter. | Postgres / Supabase / Memory / any ProviderDecisionLedger. |
| Family-locked routing | No | Yes | Yes |
| Replay from the record | No | Yes | Yes |
| Channels + interrupts | No | Yes | Yes |
| Checkpoint / restore | No | Yes | Yes |
Time-travel via @pleach/replay | No | Yes | Yes |
| Provider swap without breaking dialect | Partial — observability only. | Yes — substrate-level. | Yes — substrate-level. |
| Migration cost | One recordCall per call site. | Adapter shims + one plugin; your loop moves into core. | Fresh build. |
The rows aren't a hierarchy. Observe asks the least and gives the least; greenfield gives the most and asks you to build fresh. Core-brownfield sits between them: full runtime governance over infrastructure you already run. Picking the one that matches what you already have is the right call.
The brownfield path is a runway, not a dead end
Every choice you make on the SDK destination travels with you when you adopt the full runtime. The two surfaces are designed to compose:
runtime.observe.record(row)forwards a row to the destination@pleach/observe'sinitinstalled. The runtime's own audit rows come from its own ledger, not through the SDK.- Before
init(),recordCall()drops the row and warns once (OBSERVE_RECORD_BEFORE_INIT). Inside a runtime-managed turn the runtime's turn id wins — SDK call sites can drop theirif (observe)guards while the runtime writes through the same destination. - Pointed at Postgres (or any ledger you pass), the SDK writes the
runtime's hash-chained
AuditableCallrow. Every bump inAUDIT_RECORD_VERSION_HISTORYis additive, so the fields the SDK wrote yesterday stay readable by the runtime tomorrow. ThetenantId,turnId, and(model, family, callClass)join keys don't change. - Fingerprints are computed separately: the SDK hashes a narrower
input than core, so the two
fp_v1:values don't match. Join onturnIdand the(model, family, callClass)keys instead.
A buyer who adopts the SDK first and the runtime second keeps
the audit history: rows the SDK wrote to Postgres or a ledger are
already the runtime's chained rows. The migration is monotonic by construction,
not by a legacy_* column.
Pick observe-brownfield when
- You already run an agent loop on the Vercel AI SDK, LangChain, or a thin wrapper over a provider SDK, and you don't want to rewrite it this quarter.
- A regulator, a finance team, or a customer is asking for
per-tenant cost attribution —
(tenantId, turnId, toolName, model, tokens, costUSD)joinable to your billing schema — and the row is what's missing, not the loop. - You already have an OTel collector (Honeycomb, Datadog, Grafana Tempo, an OTLP gateway). The OTel destination emits each row as a span on a backend you already operate.
- You want to start small. The observe path lets you wire one loop, watch the row land, and decide whether to widen.
Your loop stays where it is. Two calls record each provider call, and you pick where the row lands.
import { init, recordCall, costAttribution } from "@pleach/observe";
import { postgres } from "@pleach/observe/destinations";
init({ destination: postgres({ pgClient, tenantId, sessionId }) });
const reply = await yourExistingLLMCall(messages); // unchanged
recordCall({ // synchronous, one row
turnId: sessionId, providerId: "anthropic", family: "anthropic",
callClass: "synthesize", model, inputTokens, outputTokens, costUSD,
startedAt, completedAt: Date.now(),
tags: costAttribution({ tenantId }),
});ObserveRowis a strict subset of core's AuditableCall, so rows the SDK writes today stay valid rows the runtime reads tomorrow — adopt @pleach/core later and the history comes with you.The observe shape:
import { Pool } from "pg";
import { init, recordCall, costAttribution } from "@pleach/observe";
import { postgres } from "@pleach/observe/destinations";
const pgClient = new Pool({ connectionString: process.env.PG_URL! });
init({
destination: postgres({
pgClient,
tenantId, // every row is pinned to this tenant
sessionId, // the session row these calls belong to
sessionOwnerId: userId,
autoProvisionSession: true, // create that session row on first write
}),
});
const startedAt = Date.now();
const reply = await yourExistingLLMCall(messages);
recordCall({
turnId: sessionId,
providerId: "anthropic",
family: "anthropic",
callClass: "synthesize",
model: "claude-sonnet-4-6",
inputTokens: reply.usage.inputTokens,
outputTokens: reply.usage.outputTokens,
costUSD: reply.usage.costUSD,
startedAt,
completedAt: Date.now(),
tags: costAttribution({ tenantId }),
});That's the whole observe surface for the common case. The loop you had before stays the loop you have now.
Pick core-brownfield when
- You already run an agent loop and you need runtime behavior — routing, replay, checkpoints, interrupts, safety enforcement — not just the audit row, but you do not want to throw away your provider client, your database, or your tools.
- Your provider or store is bespoke — an in-house gateway, a
wrapped Bedrock or Vertex client, a Postgres schema that isn't
Supabase — so there's no built-in adapter. You implement
OrchestratorAdapter/StorageAdapteryourself; each is a small interface. - You want core to govern the turn — enforce safety policies, correct fabrications, halt a bad chunk mid-stream, walk a family-locked cascade — while every I/O boundary stays your code.
The adapter-graft shape wires your infra underneath the runtime:
import { createPleachRuntime, setOrchestratorAdapterCtor } from "@pleach/core/runtime";
import { definePleachPlugin } from "@pleach/core";
// 1. Wrap your existing LLM call as an OrchestratorAdapter (core drives it).
setOrchestratorAdapterCtor(MyExistingProviderAdapter);
// 2. Wrap your existing DB as a StorageAdapter + Checkpointer, and fold
// your prompts / tools / safety rules into ONE plugin.
const runtime = createPleachRuntime({
storage: new MyPostgresStorageAdapter(pool),
checkpointer: new MyPostgresCheckpointer(pool),
plugins: [myDomainPlugin],
host: { strategies: { orchestratorConfig: { /* your provider config */ } } },
});
// Core now owns the lattice, family-lock, replay, checkpoints, interrupts —
// over YOUR provider, YOUR store, YOUR tools.Adopt storage and checkpointer as a pair
A SessionRuntime splits durable state across two adapters: the
StorageAdapter holds the session row (messages, metadata) and the
Checkpointer holds graph/turn state. If you supply a custom durable
StorageAdapter but leave the checkpointer defaulted (the in-memory
MemorySaver), resumeSession reconciles graph state from the empty
checkpointer and writes it back — silently overwriting session data.
Always pass a matching durable Checkpointer alongside a custom
StorageAdapter (SupabaseAdapter + SupabaseSaver, or your own pair).
Conversation messages are written by executeMessage through both adapters —
never by a hand-spread saveSession. The createBrownfieldRuntime
menu factory (exported from @pleach/core/runtime, taking one flat
BrownfieldRuntimeMenu options object) enforces this pairing for you;
or wire both fields explicitly as shown above.
The bundled examples/brownfield-adapter/ in the
@pleach/core tarball is a runnable end-to-end version — it
implements both adapter interfaces over a fake "existing app".
The migrating-from-* guides are the recognized-provider
instances of this same graft, where core already ships the
wrapper.
Pick greenfield when
- You need replay from the record: replay re-serves a turn's
recorded responses instead of calling the model, for regression
tests or an
@pleach/evalsuite.replayRecordedTurn(from@pleach/replay/recorded) replays a recorded turn against its original record and names the first request that drifted; steps the runtime doesn't fingerprint yet (decision, synthesize) are marked blind, so a turn on a stock runtime is never reportedmatched. The SDK writes a row; replay needs the event log. - You need family-locked routing — the cascade-on-503 walk
that stays inside one provider family and refuses to silently
widen across families. That's a
GatewayClientdecision, made before the wire call; the SDK observes calls, it doesn't make them. - You need reactive channels — fan-out, back-pressure, and
interrupt handling tied to the same session. Those live in
@pleach/core/channels. - You need checkpoint / restore for long-running sessions
that survive process restarts, or time-travel forking via
@pleach/replayfor what-if analysis. Both consume the canonical event log. - You're starting fresh, the loop doesn't exist yet, and the cost of building on the runtime substrate is the same as the cost of building any other way.
- You're happy on core's built-in defaults — the Memory or
Supabase adapters,
AiSdkProvider, base-tools. The difference from core-brownfield is you're not wrapping existing infra; there's nothing to graft, so you take the defaults.
The greenfield shape leads with the runtime:
import { SessionRuntime, AiSdkProvider, defineTool, definePleachPlugin } from "@pleach/core";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";
const searchDocs = defineTool({
name: "search_docs",
description: "Search the product docs.",
inputSchema: z.object({ query: z.string() }),
execute: async ({ query }) => docs.search(query),
});
const runtime = new SessionRuntime({
provider: new AiSdkProvider({
model: anthropic("claude-sonnet-4-6"),
maxSteps: 5,
}),
plugins: [definePleachPlugin("my-app", { tools: [searchDocs] })],
userId,
});
const session = await runtime.createSession({
tools: { enabled: ["search_docs"] },
});
for await (const event of runtime.executeMessage(session.id, prompt)) {
// stream events, write audit rows, walk the family cascade —
// all of it is the runtime's job, not yours.
}The migration walkthroughs for the four common starting points — AI SDK, LangChain, Anthropic Enterprise, OpenAI Enterprise — each show the move step by step.
Pick neither when
These paths cover most starting points, but not all of them. Stay where you are when:
- You're shipping a single-shot RAG bot with no tools, no sub-agents, and no per-tenant attribution requirement. The row is overhead you won't recoup.
- Your audit need is satisfied by the provider's own dashboard (an Anthropic Workspace, an OpenAI Project, a Bedrock invocation log). Adding a second ledger to maintain isn't free.
- You're prototyping an agent shape and the loop is going to change three more times this week. Wire the SDK once the shape stabilizes.
The voice on those constraints is information, not gatekeeping —
if you do need the row later, the observe path is an init
call and one recordCall per call site.
Where to go next
@pleach/observe
The observe-brownfield SDK — facade surface, the four destinations, what's hookable and what isn't.
@pleach/core
The runtime substrate. SessionRuntime, channels, family-locked routing, replay from the record, checkpointing.
Host adapters
The setHarnessModuleLoader seam — for hosts mid-migration wiring their own implementations of capabilities the substrate hasn't fully absorbed yet.
Migrating from the Vercel AI SDK
The recognized-provider graft for the most common starting point. Keep the AI SDK as your provider; core drives the loop.
Migrating from LangChain
The recognized-provider graft from LangChain. Adapter-bridged tools and agents stay; the orchestrator becomes a SessionRuntime.
Runtime construction
When you need to drop below `createPleachRoute` — the `createPleachRuntime` factory, the `SessionRuntime` constructor, and the React `HarnessProvider`.
Project layout
Pleach doesn't prescribe a layout. The runtime is constructed in user code; adapters are constructor args. A working default plus per-use-case shapes.