All guides

Context engineering

What is context engineering?

Context engineering is the practice of putting the right information, tools, and history into a model's context window so it can actually solve the task. As AI moved from single prompts to agents that run for many steps, this - not clever prompt wording - became the thing that decides whether the output is good. Here is what it means and how to do it well.

Last reviewed: July 2026

The short answer

A model can only reason over what is in its context window - the text, tools, and data you place in front of it at inference time. Context engineering is the discipline of assembling that window deliberately: choosing what to include, what to leave out, and how to arrange it so the model has exactly what the task needs and little else.

The term was popularized in 2025 by practitioners across the field who argued that the hard part of building with LLMs had shifted. It is less about the wording of one prompt and more about the system that feeds the model the right context, at the right time, on every turn.

Context engineering vs prompt engineering

Prompt engineering is about how you phrase a single instruction - the wording, examples, and formatting of one message. It still matters, but it treats the prompt as the whole input.

Context engineering zooms out to the entire window. The prompt is just one component; the rest is retrieved knowledge, tool definitions, prior messages, and memory that a system assembles dynamically for each step. In an agent that runs dozens of turns, no static prompt can anticipate what each step needs - so the work moves from writing a prompt to engineering the pipeline that builds the context.

What goes into the context window

A useful way to think about context engineering is as a budget: the window is finite, and every token you spend should earn its place. The main things competing for that space are:

  • Instructions: The system prompt and standing rules that define the model's role, goals, and constraints.
  • Retrieved knowledge: Facts pulled in on demand - documentation, code, records - via search or RAG, so the model is not guessing from training data.
  • Tools: The functions and resources the agent can call, often exposed over MCP, plus the results those calls return.
  • Memory and history: The relevant parts of the conversation and any long-term memory the agent carries between sessions.
  • The user's request: The immediate task - the smallest and most obvious piece, and rarely the reason a system fails.

Why context engineering is hard

More context is not better context. A bloated window is slower, costs more, and - counterintuitively - produces worse answers, because models struggle to find the relevant detail buried in a wall of text. The failures tend to look like this:

  • Poisoning: A wrong fact or hallucination enters the context early and gets treated as ground truth for the rest of the task.
  • Distraction: So much history accumulates that the model loses the thread and over-focuses on the wrong part.
  • Confusion: Irrelevant tools or documents crowd the window and pull the model toward things that do not matter.
  • Clash: Two pieces of context contradict each other - a stale doc and current code - and the model cannot tell which to trust.

How to do context engineering well

Good context engineering is mostly about curation and freshness, not volume. A few principles hold across most systems:

  • Retrieve, do not stuff: Pull in what a step needs on demand instead of pasting whole folders or histories into every turn.
  • Keep the source of truth current: Retrieval is only as good as what it retrieves. Stale docs feed the model confident, wrong context.
  • Prefer cited, structured context: Context that carries a path back to source lets both the model and a human verify it.
  • Compress and prune: Summarize long histories and drop tools and documents a task does not need, so the signal stays high.

Where Moxie Docs fits

For coding agents, the hardest context to get right is your own private codebase. Moxie Docs handles that layer of context engineering: it indexes your GitHub repository into living, source-cited documentation and serves conventions, docs, gaps, and verified commands over an MCP server - so agents retrieve accurate, current context on demand instead of drowning in a dump of stale files.

FAQ

Frequently asked questions

Quick answers to the questions developers ask about What is context engineering?.

Get started

Give your agents real codebase context.

Connect a repository and Moxie Docs generates living documentation and serves it to your agents over MCP. 14-day free trial, no charge today.