Series 1 of 4 · Agentic Stack · Level 1 · Topic 03

The CONTEXT Stack

Context Engineering
In This Note You Will Learn
  • 01. The seven layers that make up every AI product's context -- named as a mnemonic so you never forget them.
  • 02. How missing one specific layer creates one specific failure -- and how to read the failure backwards to find the missing layer.
  • 03. Why this framework works as both a design checklist when you're building and a diagnostic tool when something has gone wrong in production.
  • 04. The minimum viable context for the simplest AI products and the full seven-layer stack for the most complex ones.

The Story

Within a week of shipping a wealth-advisor AI to 200 advisors, three failures showed up — each one tracing back to a different missing layer of context. The engineering team had done everything right by conventional standards: a detailed system prompt, a RAG pipeline that retrieved research reports, tools that could look up portfolio positions and run risk calculations. None of it was enough.

The assistant launches to 200 advisors. Within a week, three patterns emerge.

First, the assistant keeps recommending investment strategies that the firm's compliance department has flagged as unsuitable. The system prompt says "follow regulations," but no specific compliance rules are loaded. Second, when an advisor asks a follow-up question referencing something discussed five minutes earlier, the assistant responds as if hearing the topic for the first time. Third, the assistant gives beautiful narrative responses when the advisor needs a specific table of portfolio allocations.

Three failures. Three missing layers. The team had instructions (Constitution) and knowledge (kNowledge) and tools (Equipment). They were missing specific compliance constraints, conversation memory (Tracks), and output structure (Template). Each missing layer produced a distinct, predictable failure.

The Core Idea

Once you understand that context is a system (Topic 1) with a container that degrades (Topic 2), the next question is practical: what actually goes into the context window? The CONTEXT framework provides that list. Seven layers, named as a mnemonic so they stick.

The CONTEXT framework is a seven-layer architecture -- Constitution, Observations, kNowledge, Tracks, Equipment, eXecution, Template -- that maps everything in an AI product's context window.

-- The working definition

When an AI product gives wrong answers, the instinct is to blame the model. But tracing the failure through CONTEXT layers reveals that the root cause is almost always a context problem, not a capability problem.

Missing Constitution means the model improvises rules. Missing Observations means it guesses the format. Missing kNowledge means it makes things up. Missing Tracks means it forgets. Missing Equipment means it can't act. Missing eXecution means tool results vanish. Missing Template means the output is unparseable.

Fig 1. The Seven Layers
Seven Layers. Seven Failure Modes.
One Diagnostic.
C
Constitution
System identity, constraints, priority hierarchies
Model invents its own rules. Contradictory behaviors across runs.
O
Observations
Few-shot examples, good/bad output demonstrations
Correct format by accident. Inconsistent quality across inputs.
N
kNowledge
RAG results, domain documents, reference data
Confident hallucination. Plausible-sounding answers with no factual anchor.
T
Tracks
Memory, conversation history, user preferences
Goldfish brain. Repeats questions already answered. Loses thread.
E
Equipment
Tool schemas, API definitions, function calls
Can describe the answer but can't produce it. No action capability.
X
eXecution
Tool outputs, post-processing results from prior steps
Tools fire but results vanish. Model re-derives what it already computed.
T
Template
Output format rules, XML tags, JSON schemas
Right content, wrong shape. Downstream systems can't parse the output.
Baseline (C only): 11,800 tokens, 6.2/10 quality. Full stack: 18,900 tokens, 9.3/10 quality. +50% quality for +60% cost.

Where This Hits in Production

The audit advantage. When the CONTEXT framework is shared across the product team, it creates a common vocabulary for diagnosing AI quality issues. Instead of "the AI is giving bad answers," the team can be precise: "the kNowledge layer is returning stale documents" or "the Template layer isn't constraining the output for mobile."

Regulated industries and the Constitution layer. In healthcare, finance, and legal, the Constitution layer isn't just a product decision -- it's a compliance artifact. A regulator asking "how does your AI ensure it doesn't give unsuitable investment advice?" can be answered with the constitution: specific rules loaded into every inference call, in priority order.

Multi-tenant layer customization. In enterprise B2B, different customers need different context layers. The CONTEXT framework gives the harness architecture a clean interface: each layer can be swapped per tenant without redesigning the entire pipeline.

!

The Trap

Treating the framework as a checkbox.

Teams learn CONTEXT, audit their product, find they're using all seven layers. Checkbox checked. But filling all seven layers without measuring whether each one actually improves output quality is like adding every spice in the kitchen to every dish.

A knowledge layer that retrieves 10 documents when 2 would suffice adds 8 documents' worth of noise. An observations layer with 5 examples when the model performs just as well with 1 wastes tokens.

The fix: incremental layer testing. Start with Constitution + kNowledge + Template. Measure quality. Add each layer with measurement, not faith.

In Practice: The Quality Ladder

Each CONTEXT layer is an investment with a measurable return. The curve is steep at first and levels off -- the first four layers do 80% of the work.

Fig 2. Layer-by-Layer Quality Gains
Each Layer Earns Its Tokens.
Quality Score
+0.8 6.2
+0.6 7.0
+0.9 7.6
+0.4 8.5
+0.2 8.9
+0.1 9.1
+0.1 9.2
+C3,800The foundation
+O5,200Examples teach fast
+N9,400Biggest single jump
+T10,800Memory prevents repeats
+E13,600Knowledge into action
+X16,200Results compound
+T18,900Structured output
+50% quality improvement for +60% token cost. The first 4 layers deliver 80% of the gains.

Remember This

1. Seven layers, one mnemonic: Constitution, Observations, kNowledge, Tracks, Equipment, eXecution, Template. Miss a layer, and the model compensates badly -- hallucinating facts, improvising rules, forgetting context, or producing unparseable output.

2. The framework is diagnostic, not just descriptive. When the AI fails, trace the failure to the specific CONTEXT layer. That's where the fix lives.

3. Not every product needs all seven layers. Start with the minimum viable context and add layers with measurement.

Connecting the Dots

The framework's deepest leverage shows up when you cross it with evaluation. Most eval failures are context engineering failures. When an eval fails, the lazy response is to record the model gave a wrong answer. The right response is to ask: which CONTEXT layer failed? Cited an out-of-date regulation → kNowledge. Ignored the user's stated preference → Tracks. Violated a business rule → Constitution. Produced unstructured text when JSON was expected → Template. A team that knows kNowledge layer failures account for 60% of our eval misses knows exactly where to invest: improve retrieval, not rewrite prompts.

On the autonomy spectrum. At Levels 1-3 (autocomplete, chatbot, assistant), the PM designs each layer by hand. At Level 4-5 (copilot), the harness automates assembly. At Levels 6-7 (autonomous agent), the agent itself manages some layers -- deciding what to retrieve, choosing which tools to invoke, even adjusting its own constitution within predefined boundaries. The framework stays the same. Who manages it changes.

The moat connection. A team that uses all seven layers thoughtfully owns institutional knowledge a competitor cannot copy by reverse-engineering the prompt. The Constitution embeds your firm's compliance posture. The Observations encode your team's taste. The kNowledge retrieval pipeline encodes years of corpus curation. The Tracks memory model encodes your understanding of how your customers actually use the product. None of this is in the visible output. All of it shapes every visible output.

References

1. Building Effective Agents -- Anthropic Engineering Blog

2. Context Engineering for AI Agents -- Anthropic Engineering Blog

Previous Topic Back to the Deep Dive