Dependency tiers
Modules placed by measured import fan-in — the real coupling, not the org chart. Each tier depends only on the tiers below it. Hover a tier to focus it.
Result[T] · NewType ids · enums · utc_now · Settings · provider registry
The layer boundary, precisely (4.0.0)
No base module imports meta, audit or operator at load time. Two lazy edges exist: the CLI's docs export-okf command imports meta.okf inside the function, and RBAC imports audit.models inside the method that writes AuditEntry records (its AuditLog type is a Protocol). knowledge started in Layer 2 but is now a base dependency: RuntimeServices.knowledge_graph (SPEC-02/07) makes orchestration, resolvers, agents, collision and interceptors import its KnowledgeGraph Protocol, and docs_api, ingestion and the pull interceptor use its OKF and relation models.
The node hot-path
Every node travels one path: ContextNodeExecutor.execute_node. Features aren't branches — they're stations on this line. An unwired interceptor pipeline is a no-op; behaviour is byte-identical to running without it.
Resolve
node_resolvers → matched first (SPEC-20)
CouncilResolver → NodeComplete (verdict steers DAG, agent never runs)
Auction / Static → RunAgent
Prep context
PRE interceptors · run_pre
Recovery loop ≤ max_recovery_attempts (default 2)
Emit
The two dispatch seams
All extensibility lives here. Both are split single-method @runtime_checkable Protocols — a POST-only interceptor needn't implement pre.
Seam 1 · NodeResolver chain orchestration/resolvers/
First matches() wins → ResolveOutcome = RunAgent | NodeComplete. Add a node kind = register a resolver through RuntimeServices.node_resolvers, not edit code. Duplicate resolver ids are rejected at construction.
ContextNodeExecutor.resolver_ids lists the chainSPEC-20config["council"] → deliberate, vote, return verdictSPEC-10config["capability"] only when an agent_selector is wired; else falls throughSPEC-09RunAgent(node.ref_id) · universal fallbackbaseSeam 2 · Interceptor spine interceptors/ SPEC-01a
Ordered PRE → execute → POST. Empty = no-op.
pre() → ACCEPT (enrich ctx) | REJECTPREpost() → ACCEPT | REJECT | RECOVERPOSTon_failure = REJECT (block) | RECOVER (retry + hint)POSTPolicyEngine to authorise the node (in-house rules, OPA adapters)PREWhat 4.0.0 changed on this path
collision_policy, SPEC-12). collision_policy=None restores uncoordinated writes.breakingEvalMode.GATE bindings run when DAGExecutor checks them and halt the run; subscribe() alone no longer runs them.breakingRuntimeServices is used by default (SPEC-22).breakingAgentic behaviours
An Agent[GoalT, ResultT] is a typed protocol resolved from the registry. Single agents, competitive auctions, and deliberative councils are three ways the engine decides who answers — plus the self-hosting meta-agents that build the framework itself.
Built-in agentsagents/
Librarian · Researcher · Summarizer · Writer — each a typed Agent[Goal,Result], registered in the AgentRegistry.
Meta-agents (Layer 2)meta/agents.py
ArchitectAgent · AgentSynthesizer · AuditAgent · KnowledgeGraphAgent · DreamAgent · SolutionDesignerAgent — standard Agent[Goal,Result] impls that introspect & extend CEMAF.
Auction selection SPEC-09
N agents bid on a capability; deterministic max-bid wins. Capabilities: RESEARCH · SUMMARIZE · WRITE · LIBRARY · QUALITY.
score = 0.5·match + 0.3·(1−load) + 0.2·budget_headroom
Tie-break is deterministic; absent a selector, nodes resolve statically.
Agent council SPEC-10
N members deliberate on one question; a pluggable VoteAggregator decides. Methods: MAJORITY · WEIGHTED · QUORUM · UNANIMOUS.
Multi-round (rounds=N): round 2+ broadcasts prior opinions; members may revise; early-stops when the tally settles. The verdict becomes the node output and steers the DAG.
The capability substrate
Agents act through Tools (@tool, schema-validated) and Skills (multi-tool kits). The polyglot coding kit runs inside a ShellSandbox (cwd-confined, time/output-bounded, network-screened). A bounded IterationLoop (SPEC-08) parses pytest/ruff/mypy failures into FailureSignals and re-attempts until tests pass — feedback as a first-class control structure.
Context lifecycle
Context is the asset; tokens are the cost; provenance is the audit trail. The Context object is immutable (copy-on-write) — every mutation carries a typed ContextPatch source.
agent.run sees; a ProvenanceLink records it.Selection algorithms
Greedy · Knapsack · Optimal — drop from the bottom of the priority order when over budget. Exclusions are tracked with a reason (BUDGET_EXCEEDED, LOW_PRIORITY).
Memory scopes & tiers
Scopes: SESSION · PROJECT · USER · GLOBAL. Tiered store L0/L1/L2 progressive recall; semantic + episodic; dedup on write.
Context types
RESOURCE · MEMORY · SKILL — each with behaviour rules (cacheable, shareable, compressible, TTL, default priority).
Provenance
Every patch records source · reason · correlation_id; every node run records a ProvenanceLink. Silent mutation is forbidden.
Runtime & the reactive plane
One composition root wires up to 33 injectable dependencies from RuntimeServices; the executor runs the DAG and emits events. Quality, audit, and learning subscribe asynchronously — off the hot path.
create_executor() base root
Requires a clearance: SecurityLevel. Builds the ContextNodeExecutor (incl. max_recovery_attempts, node_resolvers), assembles the resolver chain [your resolvers…, Council, Auction?, Static], subscribes online-eval + quality-police when an event bus is present, wraps in an InstrumentedDAGExecutor when a tracer is present.
create_meta_executor() Layer-2 root
Auto-builds AuditTrail from the EventBus and a KnowledgeGraph from the MemoryManager, registers the meta-agents/tools, then delegates to create_executor — so Layer 2 inherits every base primitive (incl. the RECOVER budget) for free.
TASK_STARTED · TASK_COMPLETED · TASK_FAILED · DAG_STARTED · DAG_COMPLETED · DAG_CHECKPOINT · SYSTEM_ERROR
OnlineEvalPipeline
consumes task events, scores output, re-emits EVAL_COMPLETED. evals/online.py
QualityPolice
subscribes to EVAL_COMPLETED (not raw task events); z-score anomaly + halt gate. evals/police.py
AuditTrail
EventBus → AuditEntry; feeds the KnowledgeGraph. audit/subscriber.py
BlueprintHarvester
distils high-scoring runs into reusable blueprints. blueprint/harvest.py
Memory subscriber
persists memory events. events/memory_subscriber.py
Two-hop chain: the executor emits task events → OnlineEvalPipeline re-emits EVAL_COMPLETED → QualityPolice subscribes to that. recovery_attempts and gate_rejected ride the task payload so audit & harvest correlate recovery without re-walking results.
The architecture in five sentences
If you remember nothing else.
1 Protocol-first
Every integration point (LLMClient, VectorStore, MemoryManager, Evaluator, NodeResolver, Interceptor, KnowledgeGraph, AuditLog) is a @runtime_checkable Protocol; implementations are structural — bring your own.
2 One hot-path, many stations
Features are PRE/POST interceptor stations and resolver entries on a single execute_node flow — not bespoke branches.
3 Immutable data + provenance
Context is copy-on-write; every mutation carries a ContextPatch source; every node run records a ProvenanceLink.
4 Budgeted, priority-selected context
TokenBudget + ContextCompiler drop by priority, not recency, before each agent call.
5 Strict layering
Layer 2 (meta, audit, operator) consumes the base; the base imports it only lazily, in two places — so CEMAF introspects itself without a load-time cycle.