Architecture
April 11, 2026 ยท View on GitHub
The Three Layers
The Weaver stack is divided into three independent layers. Each layer has a single, clear responsibility. They communicate through the contracts defined in this repository.
| Layer | Repository | Responsibility |
|---|---|---|
| Routing | contextweaver | Compiles context, selects tools as ChoiceCards, produces a RoutingDecision |
| Execution | agent-kernel | Authorizes capabilities, executes tools, firewalls raw output, produces Frames + Handles |
| Orchestration | ChainWeaver | Executes deterministic DAG flows; may expose flow steps as capability types |
Layer Descriptions
contextweaver (Routing Layer)
Receives the current conversation state and a set of candidate tools. Compiles a concise context window and selects a bounded number of tools as ChoiceCard objects. Returns a RoutingDecision. It never calls tools directly and never sees raw tool output.
agent-kernel (Execution Layer)
Receives a RoutingDecision and a CapabilityToken. Validates the token, authorizes the capability, executes the tool, and applies the firewall. The firewall transforms raw tool output into a Frame (safe summary) and optionally a Handle (opaque reference to the raw artifact). Only Frames and Handles leave the kernel.
ChainWeaver (Orchestration Layer)
Executes multi-step flows defined as directed acyclic graphs. Each step can be a capability invocation (delegated to agent-kernel) or a pure transformation. ChainWeaver is optional; the stack is fully functional with just contextweaver + agent-kernel for single-step tool use.
Architecture Diagram
graph TD
A([User / Caller]) -->|conversation state + candidate tools| B[contextweaver]
B -->|RoutingDecision| C[agent-kernel]
C -->|validates CapabilityToken| D{Policy Engine}
D -->|authorized| E[Tool Executor]
D -->|denied| F([PolicyDecision: deny])
E -->|raw output| G[Firewall / Filter]
G -->|Frame| B
G -->|Handle| H[HandleStore]
B -->|enriched context| A
C -->|TraceEvent| I[(Audit Log)]
subgraph ChainWeaver
J[Flow DAG] -->|step: capability invocation| C
J -->|step: pure transform| K[Transform]
end
A -->|flow request| J
Data Flow Summary
- The caller sends a request with conversation state.
- contextweaver compiles a bounded context and returns a
RoutingDecisioncontaining one or moreChoiceCardobjects. - The selected
ChoiceCard(plus aCapabilityToken) is sent to agent-kernel. - agent-kernel validates the token against its policy engine (
PolicyDecision). - If authorized, the tool is executed; raw output is passed through the firewall.
- The firewall produces a
Frame(safe view) and optionally stores the raw artifact as aHandle. - The
Frameis returned to contextweaver or the caller. The raw artifact is never exposed by default. - All execution events are recorded as
TraceEvententries in the audit log. - ChainWeaver (when present) orchestrates multiple such cycles as a DAG, treating each step as either a capability invocation or a pure transformation.
Composable Adoption
The stack is designed for incremental adoption:
- contextweaver alone: You get smart tool routing without any execution kernel. You provide your own execution layer.
- agent-kernel alone: You get safe, auditable execution without contextweaver's routing. You provide your own routing layer.
- ChainWeaver alone: You get deterministic flow execution with any tool execution backend.
- Any combination: The contracts defined here ensure that the pieces fit together without modification.
See ADOPTION_GUIDE.md for detailed guidance.