AI/ML

Context Engineering: The Orchestration Layer That Decides What the Model Sees

Prompting tunes words; context engineering tunes the model's evidence.

Image backend outage: the primary visual renderer returned OpenRouter HTTP 402 (insufficient credits). This mobile-first text and CSS card preserves the teaching payload; no PNG was generated and no alternate image backend was used.

The Window Is a Budget

  • Nine sources compete for one finite token window.
  • Pin the system contract and user context.
  • Select retrieval, history, tools, data, memory, constraints, examples.
  • Choose what to admit, order, compress, or drop.
  • Prompt tuning changes one slot; orchestration changes the whole window.

The Worked Trace

  • An invoice question needs fresh billing-tool JSON.
  • It also needs the account id from memory.
  • Add the refund policy from retrieval.
  • Old small talk is not required evidence.
  • Reserve headroom before the tool result arrives.

Exclusion Is the Design

  • Admitting all nine sources every turn is the failure mode.
  • More context helps, peaks, then hurts.
  • Long windows lose the middle; distractors lower accuracy.
  • Position changes behavior, so order is load-bearing.
  • Feedback needs a judge that scores context use.

Falsify Context Quality

  • Ablate retrieval, memory, and examples one at a time.
  • Halve history on a fixed evaluation set.
  • Then inject one irrelevant but plausible passage.
  • A good system's score should drop.
  • If it does not, the evaluation cannot see context quality.
Hafs Ibrahim
𝕏 @hafs_darwish • LinkedIn • GitHub • Blog
30 AI Algorithms Curriculum • Sensei System
© 2026 Hafs Ibrahim. All rights reserved.