Inference and generation

Context engineering

stable definition
Machine-readable Download Markdown

Definition

Context engineering is the design of what a model receives for a particular step, how that material is arranged, and how it changes over the life of a task. The context can include instructions, conversation history, retrieved documents, examples, tool definitions, tool results, working state, memory, and feedback. The work also includes deciding what to omit.

The unit of design is larger than a single prompt. A production system may retrieve a source, remove irrelevant sections, preserve its provenance, place trusted instructions above untrusted content, keep a stable prefix for caching, and replace stale state before the next model call. Each choice can change behavior even when the model and user request stay the same.

How the term entered current usage

The available primary record does not support a single inventor for the present LLM usage. Andrej Karpathy helped popularize it in a June 25, 2025 post endorsing "context engineering" over "prompt engineering." He described the work as filling the context window with the right information for the next step and did not claim to have invented the term.

Yichao "Peak" Ji's July 2025 account of building Manus documented the same idea as a production discipline. His examples included cache-stable prefixes, append-only interaction history, restorable compression, tool masking, and deliberate variation in repetitive traces. These are implementation choices around the model, not changes to its weights.

Operational significance

More context is not automatically better context. Extra material consumes tokens, can bury relevant evidence, can mix instructions with untrusted text, and may invalidate a reusable prefix. Context engineering therefore owns selection, ordering, trust boundaries, freshness, compression, and the path back to original evidence.

The quality test is whether the model received enough current, authoritative information to take the next action without hiding conflicts or exceeding the task's budget. A large context window raises the capacity limit. It does not make those decisions disappear.

Distinguish it from nearby terms

  • Prompt engineering edits the instructions and examples sent to a model. Context engineering owns the larger assembly and delivery process.
  • Retrieval-augmented generation fetches candidate material. Context engineering decides whether, where, and in what form that material enters the model's context.
  • Memory preserves information across steps or sessions. Context engineering decides when to load it and how much authority to give it.
  • Harness engineering includes context management but also owns execution loops, permissions, retries, tool runtimes, and verification.

Check your understanding

An agent has a 200,000-token window and three conflicting policy documents. Explain why concatenating all three documents is a capacity decision, not a context strategy.