CDX-301g · Module 2

Minimal Context Principle

3 min read

Every token of context you give an agent is a token it cannot use for reasoning. The minimal context principle states: give each agent exactly the context it needs to complete its task and nothing more. This is counterintuitive — more context feels safer — but empirically, agents perform better with focused context than with comprehensive but noisy context. A test-writing agent does not need the full project history; it needs the function signature, the types, and the edge cases.

Minimal context partitioning follows a strict process. First, identify the agent's deliverable. Second, trace backward from that deliverable to the inputs it requires — source files, type definitions, configuration values, test fixtures. Third, strip everything else. The agent does not need the README, the CI configuration, the changelog, or the architectural decision records unless its task directly involves those artifacts.

# Context partitioning for a 3-agent pipeline

AGENT: Implementer (rate limiting middleware)
NEEDS:
  ✓ src/middleware/ directory structure
  ✓ Express types + middleware signature
  ✓ Rate limit config schema
  ✓ Existing middleware patterns (for consistency)
DOES NOT NEED:
  ✗ Test files
  ✗ Documentation
  ✗ Other feature implementations
  ✗ CI/CD configuration

AGENT: Test Writer
NEEDS:
  ✓ middleware.ts (the implementation)
  ✓ Test framework setup (vitest config)
  ✓ Existing test patterns (for consistency)
  ✓ Edge cases from the spec
DOES NOT NEED:
  ✗ Other middleware implementations
  ✗ Database schemas
  ✗ Deployment scripts

AGENT: Documentation Writer
NEEDS:
  ✓ middleware.ts public API
  ✓ config.ts (configuration options)
  ✓ Existing docs format + style guide
DOES NOT NEED:
  ✗ Test files
  ✗ Internal implementation details
  ✗ Other feature documentation
  1. Define the deliverable Write a one-sentence description of what the agent must produce. This anchors the context selection.
  2. Trace inputs backward From the deliverable, identify every file, type, and value the agent needs to read. These are the required inputs.
  3. Strip everything else Remove all context that is not a required input. Resist the urge to include "nice to have" context — it consumes tokens without improving output.