Digital Product Engineering6.2 Context Engineering
VOL. VI · CH. 6.2 · AI SYSTEMS

Context Engineering

A broader discipline than prompting alone — what information the model actually has access to, not just how it's asked.

DivisionAI Engineering
DifficultyIntermediate
Prerequisites6.1
Related6.3 6.7
2 min read · 362 words

6.2.1Definition

Context engineering is the discipline of deciding what information — documents, prior conversation, tool outputs, retrieved data — is assembled into a model's context window for a given request. Where prompt engineering (6.1) shapes instructions, context engineering shapes the raw material the model reasons over.

6.2.2Why It Exists

A model can only reason well over information actually present in its context — it cannot retrieve facts it wasn't given, and irrelevant or excessive context can dilute its attention on what matters. Context engineering exists because assembling the right information, in the right amount, in the right order, has a larger effect on output quality than most teams initially assume, and does so within a hard, finite context window budget.

6.2.3Core Considerations

  • Relevance over volume — including only the information genuinely needed for the current task, rather than everything potentially related, since irrelevant context measurably degrades output quality.
  • Ordering and structure — placing the most important context where the model attends to it most reliably, and structuring it (headers, delimiters) so the model can distinguish sources.
  • Context window budget — treating the window as a finite, costed resource shared between system instructions, retrieved data (6.3), conversation history, and the user's actual request.

6.2.4Common Mistakes

  • Dumping an entire document into context when only a section is relevant, wasting budget and diluting the model's attention on the part that actually matters.
  • No clear separation between sources in the context, making it hard for the model to distinguish user-provided data from system instructions from retrieved content.
  • Letting conversation history grow unbounded, eventually crowding out room for the actual task-relevant context in a long-running session.

6.2.5Best Practices

  • Retrieve or select only the context genuinely relevant to the current request (6.3), not everything available.
  • Structure context with clear delimiters or labels distinguishing instructions, retrieved data, and conversation.
  • Budget the context window deliberately, summarizing or trimming history before it crowds out task-relevant material.
Real-World ExampleClaude Code assembles context from the current file, relevant surrounding files, and recent command output rather than the entire repository at once — a working example of relevance-first context engineering at the scale of a real codebase.