TOPIC #278Intermediate 12 min read

Context Engineering: The Discipline Behind Every Good Agent

AI
AI & ML Editorial
Report an issue
Key takeawayCore Concept Summary

Context engineering is the art of curating what fills a model's finite attention window at each step: instructions, retrieved code, memory, tool schemas, and message history. It explains why agent IDEs index repos, why CLAUDE.md works, and why long sessions rot.

01.The Problem: The Model Only Remembers What You Put In Front of It

A language model has no permanent memory of your project.

It cannot walk over and peek at a file. It cannot "remember yesterday." It cannot even see your screen.

Every time an agent calls the model, it must hand the model everything up front: the instructions, the relevant code, your earlier messages, the latest tool results. All of it, as one big block of text.

And there is a limit to how big that block can be. That limit is the context window.

So every single agent step forces a decision

Insight

Of everything that could go into the window, what should actually go in?

That decision is the job. And it now has a name: context engineering.

Let us feel the pressure with tiny numbers. Say the window holds 128,000 tokens (a token is a chunk of text, roughly three-quarters of a word). That sounds huge. It is not, for an agent:

  • System prompt: about 2,000 tokens
  • 20 tool descriptions: about 5,000
  • One relevant source file: about 15,000
  • Message history after 40 back-and-forth turns: about 60,000

That is 82,000 gone before a single new fact gets in.

And here is the sting: filling the window does not just cost money — it makes the model worse. Researchers found models miss information sitting in the middle of long windows (the famous "lost in the middle" effect), and long sessions visibly rot ("context rot"). More context ≠ better answers.

Prompt engineering optimized a single input string for a single question. Agents changed the game: the model is now called dozens-to-hundreds of times per task, and each call needs its own freshly assembled window of system instructions, tool definitions, project memory, retrieved code, prior messages, and fresh observations.

By 2025 the term "context engineering" (used by Karpathy, Tobi Lütke, and Anthropic's engineering team in their agent-lessons posts) described this systems discipline. Its question, in one sentence:

Insight

Given the finite attention budget of a context window, what symbols should occupy it, sourced from where, at what fidelity, and in what order?

The Per-Step Context Assembly Problem

PRO Architecture Blueprint

The Per-Step Context Assembly Problem

Every agent turn is a budgeting decision: assemble the smallest high-signal set of instructions, memory, retrieved evidence, and history that lets the model take the right next action.

The Per-Step Context Assembly Problem
100%
Touchpad: Pinch to zoom • Drag to pan
Rendering visual architecture flowchart...
PRO & LIFETIME CURRICULUM

Unlock Topic #278: Context Engineering: The Discipline Behind Every Good Agent

You are viewing a preview. The full in-depth technical walkthrough, worked derivations, and code notebooks for this concept, along with self-assessment quizzes, are available with Pro or Lifetime Access.

Production Deep Dive

Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.

Interactive Blueprints

Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.

Knowledge Assessment

Staff-level multiple-choice quiz questions with instant feedback and answer explanations.

Cross-Device Progress Sync

Firebase Google authentication automatically syncs your completed topics and quiz scores.

Rate This Architecture ChapterFeedback & Rating

How clear and actionable was this distributed systems breakdown?