Context Engineering
Context engineering is the discipline of managing the whole context state around an agent: instructions, tools, examples, memory, retrieved documents, scratchpads, conversation history, and compaction.
Prompt engineering asks, "what should the system prompt say?" Context engineering asks, "what should the model be able to attend to right now?" That broader framing matters because agents are not one-shot calls. They loop, call tools, read files, retrieve memory, lose focus, compact, and continue.
The Scarce Resource Is Attention
The context window is not a warehouse. It is an attention budget. Adding tokens creates more pairwise relationships for the model to consider and can degrade recall or reasoning even when the model technically accepts the input. "More context" often means "more places to be distracted."
This is why Kevin's workflow starts with the wiki and qmd rather than dumping everything into the prompt. Search, read, and select before answering. The goal is the smallest high-signal slice that lets the agent act correctly.
The Four Moves
| Move | Meaning | Kevin-stack example |
|---|---|---|
| Write | Persist state outside the window | wiki pages, memory.md, activity logs, timelines |
| Select | Pull only relevant material in | qmd search, _index.md, backlinks, targeted file reads |
| Compress | Summarize or compact older state | conversation summaries, compiled truth, plan files |
| Isolate | Split tasks into focused windows | subagents, worktrees, skill-specific execution |
Good agents deliberately choose between these moves. Bad agents paste more files until the context window starts sounding like a storage unit with opinions.
Latent Briefing is the same "select before stuffing" rule below the text layer: compact the KV-cache state a worker needs instead of re-sending the whole orchestrator trace. The product lesson is unchanged even when the implementation drops into inference internals: choose the relevant context, preserve enough evidence, and do not make every downstream agent pay for every upstream token. Source: X/@RampLabs, 2026-04-10
Context Layers
An agent's context usually has five layers:
- Identity and policy: who the agent is, safety constraints, project rules.
- Procedure: skills, workflows, checklists, expected verification.
- Task state: current goal, plan, files changed, commands run.
- Retrieved knowledge: wiki pages, docs, web sources, code references.
- Working scratch: hypotheses, intermediate outputs, tool results.
Keep these layers separate. When they blur, agents start treating a random web result like policy or a stale task note like durable memory.
Right Altitude
Context should be specific enough to change behavior but general enough to avoid brittle if-this-then-that prompting. "Use token variables from the design system" is useful. "On every button set exactly px-3 py-2 rounded-md" is brittle unless it is truly the component contract.
The altitude test:
- If the information should survive across projects, write a concept or style page.
- If it should govern a procedure, write a skill.
- If it should block a class of bad output, write a rule or doctor.
- If it is only useful for this run, keep it in session context.
Relation to Memory
Agent Memory Patterns is the long-term store. Context engineering is the read/write discipline around it. The wiki's compiled truth is semantic memory; timelines and logs are episodic memory; skills and rules are procedural memory. qmd is the selection layer that decides what enters the current window.
The key point: memory is not useful until retrieval and injection are good. A giant memory store with poor selection is just context rot with a database invoice.
Agent Operating Rule
Before answering, agents should:
- Search the wiki.
- Read the relevant pages.
- Follow 2-3 wikilinks if the question crosses domains.
- Pull external sources only for gaps, freshness, or primary verification.
- Update the wiki when the answer produces reusable synthesis.
That loop keeps context small and makes future context better.
Timeline
- 2026-07-04 | Added Latent Briefing as a representation-level example of context compression: select task-relevant hidden state instead of sending all prior reasoning text. Source: X/@RampLabs, 2026-04-10
- 2026-06-22 | Kevin applies this to himself, not just agents (Treat Yourself Like an Agent): humans have short context windows that degrade with too much info, so he deliberately curates what context to load before a task or day — and what to leave out. Source: User, 2026-06-22
- 2026-06-18 | Expanded with context layers, Kevin-stack examples, right-altitude routing, and the explicit wiki/qmd operating rule for agents. Source: User request, 2026-06-18
- 2026-05-31 | Page created from Anthropic's "Effective context engineering for AI agents," Chroma context-rot research, and LangChain's write/select/compress/isolate taxonomy. Source: Anthropic, https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents, 2026-05-31