Architecture

The architecture behind Context Lattice.

Six-layer agent framework, three-tier memory routing, agent work packet schema, end-to-end OTel observability, and architecture-enforced safety. The technical foundation for a governed enterprise context layer.

1. Context Supply Chain

The Context Lattice supply chain has nine stages, from raw source material to memory writeback. Every stage carries a correlation ID; every transition is auditable.

Sources → Memory writeback
Sources
ContextCapture + ContextBuilder
Processed chunks
ContextCurator
Curated context atoms
Verification workflow
P1 CanonStore facts
LatticeCore
Context packs
LatticeExplorer
Agent work packets
LatticeEngine
Agent execution
Memory writeback
Memory candidates
Human review
Promoted context
↻ back to lattice

2. Six-Layer Agent Framework

The agent framework is the independent variable. Benchmark rankings shift significantly from framework-only changes — making framework design a primary engineering lever, not a model-selection afterthought. The six layers compose in strict order: Safety wraps Orchestration wraps Execution; Context Assembly and Affective Sensing run in parallel; Memory sits beneath all of them.

Safety
Unconditional constraints in middleware. Action Governor, scope isolators, 4-tier intervention ladder. Never in the prompt.
Orchestration
Ralph Loop continuation boundaries, TAO/ReAct cycles, dual-channel cognition (Worker + Regulator).
Execution
Tool invocation, progressive skill disclosure, context compaction, counter-steering against goal drift.
Context Assembly
Pulls from P1/P2/P3 in precedence order. Permission scoping and source-of-truth precedence applied before assembly.
Affective Sensing
Runs in parallel with memory retrieval. Re-senses at every loop boundary. Anchored on P1 for safety. Anthropic 171-vector research baseline.
Memory
P1 CanonStore + P2 LatticeMem + P3 Drop Corpus. Memory writeback promotes through human review.

3. Three Memory Tiers

Production knowledge systems require tiered memory. A single vector store returns semantically proximate but factually incorrect answers for ownership and relationship queries. Context Lattice routes every retrieval through P1 → P2 → P3 in strict precedence.

P1

CanonStore

SPARQL quad store. Exact-match facts, ownership, relationships. Deterministic.

backend: quad store
guarantee: exact match
P2

LatticeMem

Graph-RAG over the company context graph. Session and role aware, permission scoped.

backend: graph-RAG
guarantee: scoped retrieval
P3

Drop Corpus

Vector similarity over raw source material. Last resort. Never for ownership queries.

backend: vector
guarantee: best-effort
Core architectural claim

Semantic search is a last resort, not a first pass. A vector store cannot answer "who owns this?" reliably — semantic proximity is not factual accuracy. Deterministic tiers carry the load.

4. Agent Work Packet Schema

ContextCurator emits agent work packets. Each packet is the structured artifact that wraps a piece of human intent in everything an agent needs to act safely: source context, constraints, acceptance criteria, and readiness score.

// agent_work_packet.json
{
  "packet_id": "awp_2c91",
  "issue_id": "PROJ-482",
  "intent": {
    "goal": "Add rate limit to /api/contact endpoint",
    "actor": "engineer:michael",
    "motivation": "Prevent abuse of strategy session form"
  },
  "constraints": [
    "must not modify auth middleware",
    "backwards compatible with existing clients",
    "latency budget: < 5ms p99"
  ],
  "source_context": [
    "atom_8f3a", // rate limiter design decision
    "atom_a02d"  // API style guide
  ],
  "acceptance_criteria": [
    "returns 429 with Retry-After header",
    "unit tests cover burst + sustained",
    "OTel span emitted on throttle event"
  ],
  "readiness_score": 0.82,
  "readiness_gate": 0.75,
  "agent_authorized": true,
  "trace_id": "7c4f...a912"
}

5. Context Atom Schema

Context atoms are the unit of governed knowledge. Every atom carries provenance, maturity, permissions, and source links. Atoms compose into context packs.

// context_atom.json
{
  "atom_id": "atom_8f3a",
  "title": "Rate limiting standard: token bucket",
  "body": "Internal APIs use token bucket with...",
  "maturity": "verified", // draft | curated | verified | promoted
  "source": {
    "doc_id": "arch-spec.md",
    "section": "3.4 Rate Limiting",
    "hash": "sha256:c4f8..."
  },
  "owner_role": "platform-eng",
  "permissions": ["role:engineering", "role:platform-eng"],
  "links": {
    "supports": ["atom_a02d"],
    "supersedes": ["atom_4421"]
  },
  "confidence": 0.94,
  "last_verified": "2026-04-22T18:11:00Z",
  "reuse_count": 17
}

6. OTel Observability

Every retrieval, every agent session, every committed action carries a trace ID. The v_issue_full_trace view joins Plane issue IDs, Claude session IDs, git commit trailers, and tool call spans into a single chain.

The result: from any deployed line of code, you can trace back through commit → trailer → Claude session → agent work packet → ContextCurator card → source context atoms → originating documents and decisions.

-- v_issue_full_trace view
SELECT
  issue.id              AS plane_issue_id,
  session.id            AS claude_session_id,
  commit.sha            AS commit_sha,
  packet.id             AS work_packet_id,
  atoms.ids             AS source_atoms
FROM plane_issues issue
JOIN agent_sessions session ON session.issue_id = issue.id
JOIN git_commits commit     ON commit.trailer_session = session.id
JOIN work_packets packet    ON packet.session_id = session.id
JOIN packet_atoms atoms     ON atoms.packet_id = packet.id;

7. Safety Architecture

Unconditional constraints belong in framework code, not prompts. Safety guarantees that live in instructions can be reasoned around by the model. Context Lattice enforces action gates, scope isolators, and intervention ladders at the middleware layer.

Action Governor
Pre-execution check on every tool call. Authorizes against the work packet's permission scope and constraint list — not against prompt instructions.
Scope Isolator
Constrains the file paths, repos, APIs, and data sources an agent can touch within a session. Code-enforced; not prompt-enforced.
4-Tier Intervention Ladder
Counter-steer → caution → block → halt. Each escalation is logged with the triggering signal and the intervention taken.
Emotion Governor
Re-senses affective state at every loop boundary. Anchored on P1 CanonStore facts independent of session memory tier.

8. Integration Surface

Context Lattice does not replace your AI platforms. It supplies governed context to them through four interfaces:

# Retrieval API
POST /v1/context/retrieve
  body: { role, query, scope, max_tokens }
  → returns: { atoms[], pack_metadata, trace_id }

# Context pack export
GET  /v1/packs/{pack_id}/export?format=mdx
  → returns: assembled context pack in MDX, JSON, or Markdown

# MCP server
mcp://contextlattice.local/v1
  tools: context.retrieve, atom.lookup, packet.next

# Memory writeback
POST /v1/memory/candidate
  body: { session_id, outcome, candidate_atom }
  → returns: { candidate_id, review_status }