Context engineering is the practice of selecting, organizing, and providing the background information generative AI needs to do useful work. OpenAI’s API documentation describes model inputs as including developer instructions, user messages, tools, and other context that shape model output.[1] If prompt engineering designs the instruction, context engineering designs the working document set.
What Context Is
Section titled “What Context Is”Context is the information available to the AI when it creates an answer.
Examples:
- User instructions
- Conversation history
- Document text
- Code files
- Error logs
- Design policies
- Output formats
- Safety rules and prohibitions
Humans also need more than a request. They need history, related documents, current constraints, and completion criteria. AI needs the same kind of working context.
Prompt vs. Context
Section titled “Prompt vs. Context”| Viewpoint | Prompt | Context |
|---|---|---|
| Main role | Tell the AI what to do | Provide judgment material |
| Example | ”Summarize this” or “Compare these” | Meeting notes, specs, past logs |
| Design focus | Clarity of instruction | Selection and organization of information |
| Failure mode | Vague instruction | Missing information or too much noise |
Even a good prompt leads to guessing when context is missing. On the other hand, dumping too much material can bury the important parts.
Basics of Context Design
Section titled “Basics of Context Design”1. Provide Only Needed Information
Section titled “1. Provide Only Needed Information”Passing an entire long document is not always best. Selecting the task-relevant parts can work better. A large context window helps, but important information can still be missed when surrounded by noise.
2. Add Priority
Section titled “2. Add Priority”Not all context has the same weight. Mandatory rules, reference notes, and past discussion have different importance.
Priority:
1. Security requirements
2. Current specification
3. Existing code style
4. Past discussion notesPriority helps the AI decide what to follow when information conflicts.
3. Clarify Sources
Section titled “3. Clarify Sources”When providing documents, keep track of where each piece of information came from: which file, date, or statement.
References:
- product-spec.md: current official specification
- meeting-2026-05-01.md: undecided discussion notes
- error.log: latest failure logThis makes verification easier.
4. Remove Stale Information
Section titled “4. Remove Stale Information”Old specifications, fixed bugs, and outdated hypotheses can lead to wrong assumptions. In long tasks, separate current facts from historical notes.
Common Failures
Section titled “Common Failures”Too Little Information
Section titled “Too Little Information”Fix this error.Without the error message, command, environment, and related code, the AI can only answer generally.
Too Much Information
Section titled “Too Much Information”Read the whole repository and fix it nicely.The scope is too wide. Target files, reproduction steps, and expected behavior make the task more stable.
Contradictory Information
Section titled “Contradictory Information”One spec says "use A" while a note says "A is prohibited."When context conflicts, the priority rule must be explicit.
Relationship to RAG
Section titled “Relationship to RAG”RAG (Retrieval-Augmented Generation) retrieves related information from external documents or databases and provides it to the AI before answering.
RAG is part of context engineering, but context engineering is broader. It includes retrieval, prioritization, summarization, history management, and constraint design.
Connection to Harness Engineering
Section titled “Connection to Harness Engineering”Context engineering designs what the AI sees. Harness engineering also designs what the AI can do, how results are checked, and what happens after failure.
For code changes, context may include the specification, related files, and error logs. The harness adds test execution, diff review, permission control, and review steps. Practical work needs both.
Summary
Section titled “Summary”- Context engineering designs the background information given to AI
- It organizes documents, history, constraints, and priority, not just instructions
- Missing, excessive, or contradictory context reduces answer quality
- RAG is one part of context engineering
- The next step is harness engineering, which includes tools and verification
Frequently Asked Questions
Section titled “Frequently Asked Questions”Q: Is context organization unnecessary with a large context window?
A: No. The Transformer made long-context sequence processing a core part of modern language models, but important details can still be missed if they are not organized clearly.[2]
Q: Does adding RAG complete context design?
A: No. RAG retrieves related information, but priority, source-of-truth rules, and verification still need design.
Q: Should all conversation history be kept?
A: Not always. Keeping a summary of current decisions, unresolved issues, and constraints is often more stable.
References
Section titled “References”- OpenAI, OpenAI API documentation
- Ashish Vaswani et al., Attention Is All You Need, June 12, 2017