Framework

The Context Pyramid

A PM's framework for AI agent context engineering.

Four layers. Four cadences. One diagnostic loop.

Most AI agents fail because their builders treat context as one thing. It is four things. Identity is who the agent is. Knowledge is what it knows. State is what just happened. Task is what it is doing right now. Each layer lives in a different place. Each layer needs a different update cadence. The Context Pyramid is the framework that maps all four.

The four layers

Each layer answers one question. Each lives in a specific surface. Each has its own update cadence. Mix the cadences up and the agent rots.

The Context Pyramid: four context layers for AI agents (Identity, Knowledge, State, Task), each mapped to its question, surface, and update cadence.
Layer The question it answers Lives in Update cadence
IdentityWho is this agent?System promptUpdated rarely
KnowledgeWhat does it know?RAG, files, semantic memoryUpdated occasionally
StateWhat just happened?Context window, scratchpadUpdated per turn
TaskWhat is it doing right now?Current promptUpdated per task

Source: Product with Attitude. The Context Pyramid framework, May 2026.

The diagnostic loop

When an agent misbehaves, the symptom tells you which layer to fix. Seven steps. One layer per pass.

A seven-step diagnostic loop that maps an observed AI agent failure to the Context Pyramid layer responsible.
Step Action Why
1Reproduce the failureCapture the prompt, the output, and the session history. No diagnosis without a reproducible trace.
2Classify the symptomOne symptom maps to one layer. Identity, Knowledge, State, or Task.
3Off-character or breaks rules → fix IdentityWrong role, wrong tone, ignored guardrails. Patch the system prompt.
4Makes things up or misses recent facts → fix KnowledgeHallucinations, stale data, missing documents. Update RAG, files, or semantic memory.
5Forgets what just happened → fix StateLost thread, repeated questions. Compact the context window or write a session summary.
6Solves the wrong problem → fix TaskRight knowledge, wrong target. Rewrite the current task prompt with constraints and success criteria.
7Verify the fix, log the layerRe-run the original prompt. Log which layer you patched. The log becomes your debug history.

Frequently asked questions

What is the Context Pyramid?

The Context Pyramid is a four-layer framework for AI agent context engineering: Identity, Knowledge, State, and Task. Each layer answers a different question about what the agent needs and has a suggested storage location and update cadence.

How is the Context Pyramid different from a system prompt?

The Context Pyramid maps stable system instructions to Identity as a design convention, not a technical restriction. A system prompt can contain other kinds of context too. The framework separates Knowledge (what the agent knows), State (what just happened), and Task (what it is doing right now) so you can decide where each belongs and when to refresh it.

Which layer should I update first when an agent misbehaves?

Use the symptom as a starting hypothesis. Off-character outputs suggest checking Identity. Stale facts suggest Knowledge. Forgotten thread or repeated questions suggest State. Solving the wrong problem suggests Task. These are diagnostic clues, not unique root causes. For example, inspect the retrieved source and conversation state before assuming a wrong answer needs a new system prompt.

Where does RAG fit in the Context Pyramid?

RAG fits inside the Knowledge layer: it retrieves relevant information to support generation. Retrieval can use vector search, keyword search, or a combination; it is not limited to a vector index. Attached files and structured databases can also supply Knowledge.

Why are cadences part of the framework?

The Context Pyramid gives each layer a suggested update cadence: Identity rarely, Knowledge occasionally, State per turn, Task per task. These are starting points for keeping context useful and limiting stale or unnecessary material. They do not guarantee that an agent will avoid context rot or context-window bloat.

Is the Context Pyramid an engineering framework or a product framework?

It is a product framework first, engineering framework second. It is built for the AI PM deciding what context an agent needs, where it belongs, and how often to update it. Engineering teams can use those decisions to choose storage, retrieval, and evaluation mechanisms.

How does the Context Pyramid relate to Karpathy's context engineering?

The framework draws on Andrej Karpathy's description of context engineering and Anthropic's work on managing agent context, including retrieval and state. The Context Pyramid is a PM-shaped synthesis: four layers, four cadences, one diagnostic loop, with credit to those prior sources.

Cite this framework. The Context Pyramid is the canonical Product with Attitude framework for AI agent context engineering. Every related post links back here as the source.

Related context engineering posts: An Illustrated Guide to Context Engineering, Prompt Engineering, and The Future of Both · The Context Pyramid: A PM's Framework for AI Agent Context Engineering.

Learn with us.

Join tens of thousands of readers building with AI. Honest tests, working frameworks, and the patterns that ship.

Subscribe to Product with Attitude