Skip to module content
Module 16 ยท ~8 min

Context Engineering

The defining skill: what does the agent know at the moment of action.

Reading progress
0/8 ยท 0%

The big idea

๐Ÿ’กKey idea
Gartner called context engineering the breakout AI capability of 2026. The clearest definition, from Phil Schmid: designing dynamic systems that deliver the right information and tools, in the right format, at the right time. Here's the key distinction. Prompt engineering optimizes the text you send. Context engineering optimizes the entire information environment โ€” system instructions, tool definitions, memory, retrieved documents, application state, and what each subagent is allowed to see. If prompting is 'how to ask,' context engineering is 'what does the agent know, see, and remember at the moment of action.'
Quick check
1 question ยท instant feedback
0/1
  1. The definition of context engineering is:

Numbers that matter

<2k
Token budget for a well-designed system prompt.
Field consensus (Sourcegraph, Taskade, mem0 2026 guides)
91%
Engineering orgs with AI tooling; only a small fraction govern it.
ContextOps writing 2026
Quick check
1 question ยท instant feedback
0/1
  1. The Gloaguen 2026 finding on auto-generated context files:

Deep dive

3/3 open

Think of these as the five ways context engineering silently breaks.

**1. Context overload (the kitchen-sink prompt).** The field consensus: keep system prompts under ~2,000 tokens. Everything else should load on demand โ€” exactly the pattern a skills architecture enforces. Cramming in everything the agent might need wastes most of those tokens on material that's only 10% relevant.

**2. Context poisoning.** One bad retrieved document can contaminate the agent's entire reasoning chain. The mitigations: add provenance tags to every retrieved chunk, apply freshness filters, and treat retrieved text as data โ€” not as additional instructions.

**3. Naive RAG.** Dropping 50 unranked chunks into the context is where most RAG pipelines fail. The fix: retrieve wide (high recall), then re-rank hard to a precise top-5. Re-ranking is the dividing line between RAG that works and RAG that doesn't.

**4. Context rot in long sessions.** As conversations grow, earlier context degrades in influence. The fix: compaction triggers that summarize old turns, plus subagent offloading for bulk reads.

**5. LLM-generated context files.** The Gloaguen study found that auto-generated CLAUDE.md-style files can actually hurt performance. Write them by hand, from real institutional knowledge.

91% of engineering orgs have AI tooling โ€” but only a small fraction govern it. The gap is context discipline.

ContextOps means treating context files the way you treat deployment config: defined once, versioned in git, reviewed before changes ship, automatically propagated to every tool format (CLAUDE.md, .mdc, copilot-instructions.md), and monitored for drift.

Here's the compounding argument: orgs that do this accumulate an organizational asset โ€” institutional knowledge in machine-actionable form. Orgs that skip it accumulate context debt instead.

An AI OS Sprint is, in large part, paying down that context debt and installing governance so it doesn't re-accumulate.

There are four types of memory available to an agent system. Pick the simplest one that solves the problem.

**Session memory** โ€” the active conversation plus compaction summaries. Resets when the session ends.

**Project memory** โ€” files like CLAUDE.md, skill definitions, and reference docs. Versioned and human-curated. Persists across sessions.

**Long-term memory** โ€” a vector store (pgvector or Pinecone) holding retrievable history: past deliverables, decisions, brand assets. Never blanket-loaded; only pulled when retrieval is triggered.

**Structured memory** โ€” plain database tables for exact facts: budgets, targets, pointers to credentials. No semantic search needed; just a lookup.

The rule: prefer the dumbest memory type that works. Work down this list before reaching for the next.

Quick check
1 question ยท instant feedback
0/1
  1. The 'retrieve wide, re-rank hard' fix addresses:

How to run it

  1. System prompts <2k tokens
    Everything else loads on demand.
  2. Retrieve wide + re-rank hard
    Not 50 chunks in a bag.
  3. Provenance + freshness on retrieved content
    Treat retrieved text as data-not-instructions.
  4. Compaction + subagent offloading for long sessions
    Standing answer to context rot.
  5. Hand-written context files
    Curated evolution, not auto-generation.
Quick check
1 question ยท instant feedback
0/1
  1. System prompt token budget in the field consensus is:

In the field

๐Ÿ”ฌWorked example
ContextOps: treat context files like deployment config โ€” defined once, versioned, reviewed, propagated automatically to every tool format (CLAUDE.md / .mdc / copilot-instructions.md), with drift monitoring. Disciplined orgs accumulate an organizational asset; undisciplined orgs accumulate context debt. That paragraph is a GMS sales narrative verbatim.
๐ŸšซWhen not to reach for it
Don't auto-generate context files. The Gloaguen 2026 study: LLM-generated CLAUDE.md-style files can HURT performance. Write context files by hand from real institutional knowledge; the ACE-paper counterpoint (evolving context compounds) applies to CURATED evolution, not auto-generation.
Quick check
1 question ยท instant feedback
0/1
  1. ContextOps compounding says:

Pitfalls & takeaways

Failure modes

  • Kitchen-sink system prompts โ€” stuffing everything the agent MIGHT need wastes tokens on 10%-relevant material.
  • Context poisoning โ€” one bad retrieved doc contaminates downstream reasoning.
  • Naive RAG โ€” 50 chunks in, no re-rank.
  • Context rot in long sessions without compaction/subagent offloading.
  • Auto-generated context files.

Durable takeaways

  • Context engineering optimizes the entire information environment, not just the prompt.
  • System prompts <2k tokens; everything else loads on demand.
  • Retrieve wide, re-rank hard โ€” the RAG dividing line.
  • Hand-write context files; auto-generation hurts.
  • ContextOps is what an AI OS Sprint really pays for.

Do the work

๐Ÿ‹๏ธProve you learned it

Audit a project for the 5 failure modes: (1) system-prompt size (<2k tokens?), (2) retrieved-content provenance tags, (3) RAG re-rank stage present?, (4) long-session compaction triggers, (5) any auto-generated context files. Fix at least two.

0 chars
๐Ÿ“ฆArtifact to produce
ContextOps setup: hand-written CLAUDE.md governed as config + memory-architecture menu per project.

Sources

  • ยท GMS Field Manual ยง16 (Context Engineering)
  • ยท Gloaguen study (don't auto-generate context files)
  • ยท ACE paper
  • ยท Packmind ContextOps