What Is Context Engineering?
Definition
Context engineering is the practice of deliberately constructing the information environment an AI system operates within — shaping what it knows, what it is instructed to do, what constraints apply, and what examples it can draw on.
Where prompt engineering focuses on how individual instructions are written, context engineering addresses the broader question of what surrounds those instructions. A well-engineered context gives an AI system the background knowledge, scope boundaries, priorities, and examples it needs to interpret your intent accurately — not just your literal words.
AI systems do not have independent knowledge of your project, your preferences, your previous decisions, or your constraints. Everything they know in a given session comes from what you provide. Context engineering is the discipline of providing that information deliberately and effectively.
Context Engineering vs. Prompt Engineering
Prompt engineering is about how you write an individual instruction. Context engineering is about what information surrounds and informs that instruction.
| Dimension | Prompt Engineering | Context Engineering |
|---|---|---|
| Scope | A single instruction or exchange | The full information environment across a session or project |
| Focus | Wording, structure, and clarity of a request | Background, constraints, examples, priorities, and boundaries |
| Question answered | How do I ask this well? | What does the AI need to know to answer correctly? |
| Failure mode | Ambiguous or poorly structured request | Missing background, conflicting priorities, no constraints |
Both disciplines are complementary. A well-structured prompt inside a poorly engineered context will still produce misaligned output. A rich context with a vague prompt will still produce imprecise results. Effective AI direction requires both. AI prompt engineering and behavior is covered in depth in the MMP prompt engineering reference.
What Is a Context Window?
Definition
A context window is the total amount of information an AI model can hold in active memory during a single session — including your instructions, the conversation history, any documents or data you have provided, and the AI's own responses.
Every AI model has a finite context window, measured in tokens (roughly equivalent to word fragments). When a session exceeds this limit, earlier content is dropped from active memory. This is one reason AI systems appear to 'forget' earlier instructions or decisions in long sessions.
- Instructions given early in a long session may no longer be in active memory by the time they are relevant.
- Approved decisions and constraints need to be restated or reinforced as a session progresses.
- Large documents or code blocks consume significant context space, leaving less room for instructions.
- Summarising earlier context periodically can help maintain alignment in extended workflows.
For techniques to evaluate whether AI is following your instructions across long sessions, see AI reliability and evaluation.
What Is Instruction Design?
Definition
Instruction design is the practice of writing AI instructions that are specific, bounded, and verifiable — giving the AI a clear objective, a defined scope, explicit constraints, and a way to confirm the outcome.
Weak instruction
"Fix my website."
No objective, no scope, no constraints, no verification expectation. The AI must guess what 'fix' means, what is in scope, and what a successful outcome looks like.
More structured instruction
"Correct the mobile navigation issue without changing the approved desktop layout. Verify the navigation at the defined mobile breakpoints and report what changed."
- Objective: Correct the mobile navigation issue
- Constraint: Without changing the approved desktop layout
- Scope boundary: Mobile navigation only
- Verification expectation: Verify at defined breakpoints
- Reporting requirement: Report what changed
Why Constraints Matter in AI Instructions
Constraints tell an AI what it must not do, what it must preserve, and what falls outside the scope of a given task. Without explicit constraints, AI systems optimise for completing the stated objective — often at the expense of things you assumed were protected.
Preservation constraints
Explicitly protect approved work, decisions, or design elements from being changed.
"Do not modify the approved hero section layout."
Scope constraints
Define the boundaries of what the AI is authorised to change in this task.
"Only update the contact form — do not change any other page."
Behavioural constraints
Specify how the AI should approach the task, not just what to do.
"Make the minimum change necessary. Do not refactor unrelated code."
Output constraints
Define the format, length, or structure of the expected response.
"Provide a summary of changes made, not the full file."
The Role of Examples in AI Context
Examples are one of the most effective ways to communicate intent to an AI system. A concrete example of the output you want — or do not want — is often more precise than a written description alone.
When you provide an example of a previous output you approved, a format you want matched, or a style you want preserved, you give the AI a concrete reference point rather than asking it to interpret abstract instructions. This is sometimes called few-shot prompting — providing a small number of examples to establish a pattern.
- Show an example of approved output when you want the AI to match a specific style or format.
- Show an example of rejected output when you want the AI to avoid a specific pattern.
- Use examples to establish tone, structure, and level of detail — not just content.
- Be selective: too many examples can consume context window space and introduce conflicting signals.
Setting Priorities in AI Instructions
When an AI instruction contains multiple objectives, the AI must decide which to prioritise if they conflict. Without explicit priority ordering, the AI will make that decision itself — often not in the way you intended.
Explicit priority statements reduce ambiguity in complex instructions. When you tell an AI that preserving an approved design takes priority over implementing a new feature, you are not just giving it a task — you are giving it a decision rule for resolving conflicts it encounters during execution.
Priority statement examples
- "Prioritise preserving the existing navigation structure over implementing the new dropdown."
- "If the two requirements conflict, the accessibility requirement takes precedence."
- "Complete the minimum viable change. Do not optimise or refactor unless explicitly instructed."
Maintaining Project Context Across Sessions
AI systems do not retain memory between separate sessions. Each new session starts with no knowledge of previous decisions, approved work, or established constraints unless you explicitly provide that information.
Session summaries
Begin each session with a brief summary of relevant decisions, approved work, and active constraints.
Explicit state declarations
State what has been approved, what is in progress, and what must not be changed at the start of each session.
Versioned references
Reference specific approved versions of work rather than relying on the AI to remember previous outputs.
Constraint reinforcement
Restate critical constraints periodically in long sessions, particularly before tasks where they are most relevant.
This is one of the most common sources of AI misalignment in ongoing projects. The AI is not being disobedient — it simply has no memory of what was established in a previous session unless you provide it.
When AI repeatedly deviates from established constraints across sessions, this is a pattern known as AI behavioral drift. Addressing it requires both better context engineering and structured AI behavioral training.
More Context vs. Better Context
Adding more information to an AI context does not automatically improve results. Poorly organised, contradictory, or irrelevant context can reduce performance. The goal is relevant, well-structured context — not maximum volume.
- Include background information that is directly relevant to the current task.
- Remove or summarise information that is no longer relevant to avoid consuming context window space.
- Resolve contradictions before they enter the context — conflicting instructions produce inconsistent output.
- Structure context so the most important constraints and objectives are clearly identifiable.
- Avoid including sensitive information that is not necessary for the task.
Frequently Asked Questions
- What is context engineering in AI?
- Context engineering is the practice of deliberately constructing the information environment an AI system operates within — including instructions, background knowledge, constraints, examples, and priorities — to keep the AI aligned with your intent.
- What is the difference between context engineering and prompt engineering?
- Prompt engineering focuses on how individual instructions are written. Context engineering addresses the broader information environment surrounding those instructions — what the AI knows, what constraints apply, and what examples it can draw on.
- What is a context window in AI?
- A context window is the total amount of information an AI model can hold in active memory during a session. When a session exceeds this limit, earlier content is dropped, which can cause the AI to appear to forget earlier instructions.
- Why does AI ignore constraints I set earlier in a session?
- In long sessions, earlier instructions may have been pushed out of the AI's active context window. Restating critical constraints periodically — especially before tasks where they are most relevant — helps maintain alignment.
- How do examples improve AI output?
- Examples give the AI a concrete reference point rather than asking it to interpret abstract instructions. Showing an approved output, a preferred format, or a rejected pattern is often more precise than a written description alone.
- What is instruction design for AI?
- Instruction design is the practice of writing AI instructions that include a clear objective, defined scope, explicit constraints, and a verification expectation — reducing ambiguity and improving the reliability of AI output.