PRISM Context Engine

6-layer context assembly that stacks information from Constitution (L0) to Keyword-level (L5), giving each agent exactly the knowledge it needs. Budgets scale with the provider's context window and increase as memory degrades.

The AI Forgets Everything

LLMs have a fixed context window. In long sessions, critical decisions made early get pushed out of memory. The agent that built your auth system has no idea what conventions were established. Every new agent starts from scratch, repeating mistakes and contradicting earlier decisions.

How Chati.dev solves this

Context Assembly Flow

When an agent activates, the PRISM engine hook reads the current Context Bracket, determines which layers to load, and assembles the complete prompt.

PRISM context assembly: bracket determines layer depth, hook assembles the final agent prompt.

How PRISM Works

1

Layer Resolution

The prism-engine.js hook reads agent definitions, workflow context, and keyword rules from chati.dev/. Each layer maps to a specific source: constitution.md for L0, global rules for L1, agent .md files for L2, and so on.

2

Bracket Filtering

Progressive Reinforcement: FRESH injects only L0-L1 (Constitution + Global) since the LLM still has full memory and does not need reinforcement. As context degrades, more layers are injected to compensate. MODERATE adds Agent and Workflow context (L0-L3). DEPLETED injects all 6 layers (L0-L5) to fight memory loss. CRITICAL also injects all 6 layers and forces a handoff or session spawn to prevent quality degradation.

3

Context Injection

The prism-engine.js hook intercepts agent activation, assembles filtered layers into a single context block, and injects it into the system prompt before the agent starts work.

Context Bracket Degradation

As tokens get consumed, the bracket degrades automatically. Token-based estimation (prompt length / 4) determines the bracket. FRESH needs minimal injection (LLM remembers). As brackets degrade, more layers are reinforced to compensate for memory loss. CRITICAL triggers maximum reinforcement plus forced handoff.

Context bracket degradation: forced handoff at CRITICAL prevents quality loss.

Priority Resolution

When rules conflict across layers, lower-numbered layers win. Constitution (L0) overrides everything, so governance is never accidentally bypassed by task-level context. Resolution is deterministic, enforced by the PRISM engine at assembly time.

L0 Constitution>L1 Global>L2 Agent>L3 Workflow>L4 Task>L5 Keywords

Adaptive Governance

Traditional systems just cut context when memory runs low. PRISM does the opposite: as the bracket degrades, the system injects more governance rules to compensate. Weaker memory, stronger reinforcement.

Adapts automatically across providers (Claude, Gemini, Codex), scaling proportionally to each provider's context window.

Prompt Cache Optimization

PRISM splits the assembled prompt into a static prefix (L0 Constitution + L1 Global rules) and a dynamic suffix (L2-L5, changes per turn). The static prefix is marked with a boundary separator, enabling prompt cache reuse across turns within the same governance mode. Cache is invalidated on mode transitions (planning to build to deploy).

Governance Hooks

Runtime hooks that enforce constitution compliance, mode restrictions, and context injection.

Constitution Guard

Validation

Enforces Constitution Article compliance at runtime

constitution-guard.js

Mode Governance

Guard

Enforces mode-based write scope restrictions

mode-governance.js

Model Governance

Validation

Model tier enforcement per agent

model-governance.js

PRISM Engine

Engine

Context injection and layer management

prism-engine.js

Read Protection

Guard

File read access control enforcement

read-protection.js

Session Digest

Event

Per-turn memory extraction, daily digest, and pre-compaction state capture

session-digest.js

Undercover Guard

Guard

Sanitizes framework terms from deliverables

undercover-guard.js

Style Guard

Guard

Blocks em-dashes and emojis in output

style-guard.js

License Guard

Event

License validation with 5-minute throttle

license-guard.js

Rate Limiter

Guard

Handles API rate limits and model fallback on 529 errors

rate-limiter.js