Skip to content

Latest commit

 

History

History
72 lines (50 loc) · 3.27 KB

File metadata and controls

72 lines (50 loc) · 3.27 KB

context-engineering

A beginner-friendly guide to Context Engineering, window budgeting, rule framing, and knowledge snapshot management for AI agents.

context engineering is the art and science of constructing the exact context window payload required for maximum model accuracy and minimal token noise

Table of Contents

The Simple Idea

Prompt Engineering focuses on wording single user instructions.

Context Engineering manages the entire dynamic context payload fed to an LLM on every step of an agentic loop: system rules, workspace snapshots, Knowledge Items (KIs), active document states, tool output summaries, and memory frames.

System Rules + Workspace State + Active Files + KI Knowledge + Step History = Engineered Context

Prompt Engineering vs Context Engineering

Dimension Prompt Engineering Context Engineering
Focus Wording a prompt string Managing total context state & tokens
Scope Single instruction Multi-turn agent execution loop
Data Sources User text input ASTs, Knowledge Items, files, git diffs, logs
Optimization Output clarity Token density, relevance, zero distraction

The Anatomy of a Context Window

  1. System Identity & Constraints: Core agent rules, non-negotiable guidelines, and OS metadata.
  2. Repository Standards: AGENTS.md and repository-specific coding rules.
  3. Knowledge Items (KIs): Relevant architectural summaries retrieved from persistent storage.
  4. Environment State: Active file path, cursor position, git branch.
  5. Condensed Execution History: Concise observations of completed tool calls.

Context Engineering Techniques

  • Rule Framing: Structuring rules with explicit priority hierarchy (CRITICAL RULE: NEVER do X).
  • Dynamic File Slicing: Including exact line ranges (L10-L45) rather than dumping full 5,000-line files.
  • Silent Log Inspection: Processing background outputs silently and injecting concise 2-line summaries into context.
  • Context Compaction: Periodically truncating old tool outputs while preserving core system rules and target goals.

My Learning Notes

Context window bloat is the primary cause of model confusion and high API costs.

Context engineering principle:

every token in the context window must earn its place — maximize signal, eliminate noise

Common Misunderstandings

"Just throw the whole codebase into a 2M token window."
Massive context windows increase latency, cost, and introduce attention degradation ("lost in the middle"). Precise context engineering yields significantly better accuracy.

Related Concepts

Previous: graph-engineering
Next: capability-engineering
Related: agent-memory, tool-calling