lockstep

Context Engineering

Context engineering is deliberately assembling the information an AI model needs — instructions, constraints, decisions — and keeping it true over time.

Updated

Context engineering is the discipline of getting the right information in front of an AI model at the right time — and keeping it true as reality changes. For coding agents, the highest-value context is often the set of approved decisions the agent would otherwise never see.

Why it beats prompt engineering alone

You can phrase a prompt perfectly and still get wrong output if the model lacks a constraint the team agreed on last week. Context engineering treats that constraint as a first-class input — delivered via MCP, retrieval, or memory — not an afterthought.

What goes into an agent's context

For a coding agent, context engineering decides what fills the context window on each run. The usual sources:

  • Standing instructions: files like CLAUDE.md or AGENTS.md that load at the start of every session.
  • Retrieved text: passages pulled from docs or code by search, the RAG pattern.
  • Tool results: live answers fetched mid-task over MCP.
  • Memory: what the agent kept from earlier sessions, covered under agent memory.

The work is choosing which of these reach the model for a given task, in what order, and making sure none of them is stale.

An example

An engineer asks an agent to add a discount field to checkout. With no context engineering, the agent reads the code, picks a sensible design, and opens a pull request. It doesn't know the team decided two weeks ago, in a Slack thread, that discounts are calculated server-side only. With context engineering, that decision is captured, approved, and returned when the agent calls a tool like get_product_context for the checkout area, so the first draft already respects it.

Context engineering vs prompt engineering vs RAG

Prompt engineering is phrasing a single instruction well. RAG is one technique for fetching text into a prompt. Context engineering is the wider job: deciding every input the model sees, across instructions, retrieval, tools, and memory, and keeping each input true over time. The full playbook for coding agents is in context engineering for coding agents, and persistent memory for AI coding agents covers the memory side.

Learn more

Is context engineering the same as prompt engineering?
No. Prompt engineering is about how you phrase an instruction. Context engineering is broader: it's about what information reaches the model — retrieval, memory, tool results, injected decisions — and keeping it accurate over time.

Related