Zero Labs
Industry News / AI

The Weaver Stack: One Contract Layer for Safe LLM Agents

Source · Towards AI By Diogo Santos

From the publisher’s feed, collected in the ZeroLabs newsroom.

Four agent problems — tool explosion, context bloat, unsafe execution, flaky orchestration — solved by one shared spec your components can actually compose against.You wired up an LLM agent. It worked in the demo. Then you gave it real tools, and four things broke at once.You injected every tool schema into the prompt, and 1,000+ definitions ate your context window and your token budget. Raw tool outputs — database rows, API blobs, file contents — came back huge and full of things the model should never see. There was no record of what ran, on whose authority, or why. And the moment you chained more than two steps, retries and partial failures turned the pipeline into something you couldn’t reproduce twice.Here’s the part that stings: each of those four problems has been solved a dozen times. Everyone writes their own tool router, their own output filter, their own audit log, their own retry logic. They just don’t compose. Your router and your executor disagree about what a “routing decision” even is, so you write glue. Then you write glue for the glue.weaver-spec is an attempt to fix the boundary, not to ship yet another framework.The problem, concretelyThe VISION doc names the four compounding failure modes directly:Tool explosion — a production agent may have 1,000+ tools; injecting all their schemas every turn is expensive and noisy.Context bloat — raw outputs are large, sometimes sensitive, and unsafe to hand an LLM unfiltered.Unsafe execution — with no authorization layer, an agent can call any tool with any arguments, with no auditable trail.Flaky orchestration — ad-hoc chaining produces non-deterministic, hard-to-debug pipelines.The gap weaver-spec targets isn't any one of these. It's that they're each solved in isolation, so the pieces never interoperate.The idea in one paragraphweaver-spec is documentation plus contracts — not a runtime library. It's a single source of truth for the vocabulary, invariants, and language-agnostic schemas that a set of independently adoptable agent components share: a routing layer (contextweaver), an execution layer (agent-kernel), and an orchestration layer (ChainWeaver). Define a RoutingDecision, a Frame, a CapabilityToken once, as JSON Schema and as Python dataclasses, and any implementation that honors them composes with any other — or with your own code at whatever boundary you happen to cross.The four compounding agent problems and which Weaver layer owns each.How it worksThe stack is three runtime layers, each owning exactly one responsibility and talking only through the shared contracts:Routing (contextweaver) compiles context and presents the LLM a small, pre-screened set of ChoiceCards instead of an unbounded tool list. It emits a RoutingDecision. It never executes a tool and never sees raw output.Execution (agent-kernel) validates a CapabilityToken, authorizes the call (PolicyDecision), runs the tool, and firewalls the raw result into a Frame (the LLM-safe view) plus an optional Handle (an opaque reference to the full artifact). It emits TraceEvents. It owns the only firewall.Orchestration (ChainWeaver) runs deterministic DAG flows and delegates every tool step back to the execution layer — it never calls tools directly.What makes this more than a diagram is that the boundaries are pinned down as seven non-negotiable invariants in INVARIANTS.md. The load-bearing one is I-01: the LLM never sees raw tool output by default. Everything has to pass through the firewall and become a Frame first. I-02 says every execution is preceded by a PolicyDecision and followed by a TraceEvent — there is no "silent" execution. I-06 says tokens must be scoped and either single-use or expiring. An implementation that breaks any of I-01 through I-07 is, by definition, not spec-compliant.A single request flowing through the stack, plus the closed learning loop that feeds the next one.Contracts come in two tiers. Core is minimal and stable — nine JSON Schemas (selectable_item, choice_card, routing_decision, capability, capability_token, policy_decision, frame, handle, trace_event). Changing one requires a major bump and an ADR. Extended (23 schemas at the time of writing) carries optional metadata — telemetry hints, UI hints, risk assessments, the TraceBundle audit envelope — and evolves faster without breaking the Core.Try it in 5 minutesYou don’t need any sibling repo to feel the contracts. The Python package vendors the same field shapes as the JSON Schemas as plain stdlib dataclasses — zero runtime dependencies.# From a local checkout (always works):pip install -e ./contracts/python# Or, once published:pip install weaver_contractsConstruct a Core routing decision. Validation runs in each dataclass’s __post_init__, so a malformed object fails the moment you build it:from datetime import datetime, timezonefrom weaver_contracts import SelectableItem, ChoiceCard, RoutingDecisionitem = SelectableItem( id="search-docs", label="Search documentation", description="Full-text search across the product documentation index.", capability_id="org.myapp.search_docs",)card = ChoiceCard( id="card-retrieval", items=[item], context_hint="Select the most appropriate document retrieval action.",)decision = RoutingDecision( id="rd-20260308-001", choice_cards=[card], timestamp=datetime.now(timezone.utc), selected_item_id="search-docs", selected_card_id="card-retrieval",)That’s the routing side. To see the whole request — routing, a scoped token, an authorization decision, the firewall producing a Frame plus a Handle, and a trace event — run the repo's single runnable reference implementation:pip install -e "contracts/python[dev]" # adds jsonschema, jcs, cryptographypython examples/reference_impl/reference_impl.pyIt constructs every Core artifact, gathers them into a TraceBundle, mints a real ed25519 signature over the RFC 8785 (JCS) canonical form using an ephemeral keypair, verifies it, validates all six payloads against the JSON Schemas, and asserts I-01 and I-02. Running it locally prints:Weaver reference implementation — contract version 0.7.0[1] Constructed RoutingDecision, CapabilityToken, PolicyDecision, Frame, Handle, TraceEvent and gathered them into a TraceBundle.[2] Signed the bundle (alg=ed25519, kid='reference-impl-ephemeral').[3] Signature verified against the ephemeral public key.[4] Validated 6 payloads against contracts/json/ schemas.[5] Invariants I-01 (no raw output in Frames) and I-02 (PolicyDecisions are traced) hold.Reference implementation: all checks passed.Not on Python? The schemas are the language-agnostic source of truth. The QUICKSTART shows the same validation in JS/TS with ajv + ajv-formats (Draft 2020-12), plus a json-schema-to-typescript codegen line if you want compile-time types.How the firewall actually pays offThe minimal end-to-end example makes I-01 concrete. A docs-search tool returns this internally:{ "hits": [ { "internal_id": "doc://internal/retry-policies", "title": "Retry Policies Overview" } ], "ranking_signals": { "bm25": [], "semantic": [] }, "index_metadata": { "shard": 3, "version": "2026.03" }}The firewall strips the internal IDs, ranking signals, and shard metadata, stores the full payload as a Handle, and emits a Frame whose summary is "Found 3 documentation pages matching 'retry configuration'…". The LLM sees the summary. It never sees the internal IDs or index internals — and there's a TraceEvent for the authorization, the execution, and the firewall step. That's the difference between "we filter outputs somewhere" and "the boundary is a typed artifact your audit log can prove."Honest limitationsThis is the part hype articles skip, so let’s be direct.It’s early and single-author. The project’s own WEAVER_STACK explainer says the credible part today is the architecture and the contracts, not production hardening or adoption numbers. The Python package is marked Development Status :: 4 - Beta.The siblings aren’t verified against the spec yet. The machine-readable compatibility.yaml lists contextweaver, agent-kernel, and ChainWeaver all as unverified — no compatibility declaration published yet. The spec is deliberately honest about this: a sibling can only be marked verified once it's backed by real conformance tests. The weaver-stack umbrella meta-package's runtime extra is empty today for exactly this reason.It’s contracts, not a runtime. weaver-spec won't route your tools or run them. You adopt a sibling, or you bring your own implementation that honors the contracts. That's the point, but it means there's no pip install that gives you a working agent.Pre-1.0. The contract version is 0.7.0. All 0.x versions share MAJOR 0 and are mutually compatible, but the surface can still move before 1.0.What is solid: 9 Core + 23 Extended schemas, a stdlib-only Python package, a runnable signed-and-validated reference flow, and a test suite that passes 302 tests on Python 3.10–3.14.The rest of the stackweaver-spec is the hub. Around the three runtime layers sit adjacent tools that share the same contracts without being on the request path:contextweaver — routing: bounded ChoiceCards instead of 1,000 schemas.agent-kernel — execution: authorization, the output firewall, and audit.ChainWeaver — orchestration: deterministic DAG flows that delegate execution.AgentFence — an external policy firewall/proxy at the edge; complements (doesn’t replace) the kernel firewall.lessonweaver — reviews captured traces into reusable LessonCard / SkillCard artifacts, closing the learning loop back into routing.vibeguard — a pre-merge safety gate for AI-generated code and file changes.You don’t have to adopt all of it. Want smarter routing for an LLM you already host? Take contextweaver and return your own Frame. Need authorization and audit on an existing tool runner? Take agent-kernel and feed it a RoutingDecision. Just want the shared shapes? Read the schemas or pip install weaver_contracts. You only honor the contracts at the boundaries you actually cross.TakeawaysThe four agent pain points — tool explosion, context bloat, unsafe execution, flaky orchestration — are usually solved in isolation, so the pieces don’t compose. weaver-spec fixes the boundary instead of shipping another framework.The whole stack rests on seven invariants, anchored by I-01: the LLM never sees raw tool output by default. Only a Frame (safe view) and a Handle (opaque ref) leave the execution kernel.Contracts ship as language-agnostic JSON Schema (9 Core, 23 Extended) and a zero-dependency Python package — adopt either, in any language.One file, examples/reference_impl/reference_impl.py, takes you from "construct every Core artifact" to "sign, verify, and schema-validate a full audit bundle" — and it passes.It’s early and single-author; siblings are unverified today. The credible value right now is the architecture and the contracts, and the repo says so itself.Try itIf you’ve ever written glue between a tool router and a tool executor, the contracts will feel familiar — and the firewall boundary is worth stealing even if you adopt nothing else. Read weaver-spec, run the reference implementation, and if the boundary model resonates, star the repo so the work continues — then pick the one layer you need.The Weaver Stack: One Contract Layer for Safe LLM Agents was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.