What is Context Engineering? The Definitive Guide
Context engineering has emerged as the defining discipline of modern AI development. While prompt engineering taught us how to talk to language models, context engineering teaches us how to give th...
What is Context Engineering? The Definitive Guide
Context engineering has emerged as the defining discipline of modern AI development. While prompt engineering taught us how to talk to language models, context engineering teaches us how to give them everything they need to actually succeed.
This guide explains what context engineering is, why it matters more than prompt engineering, and how to implement it in your AI-powered applications.
Context engineering is the discipline of designing systems that provide the right information and tools, in the right format, at the right time, to give an LLM everything it needs to accomplish a task. It's the difference between hoping your prompt works and engineering reliable AI systems.
---
The Shift from Prompt Engineering to Context Engineering
In June 2025, Shopify CEO Tobi Lütke tweeted what would become the canonical definition: context engineering is "the art of providing all the context for the task to be plausibly solvable by the LLM."
A week later, Andrej Karpathy amplified the concept, describing it as "the delicate art and science of filling the context window with just the right information for the next step."
Why the sudden shift in terminology? Simon Willison explains it best:
"I've spoken favorably of prompt engineering in the past, hoping that term could capture the inherent complexity of constructing reliable prompts. Unfortunately, most people's inferred definition is that it's a laughably pretentious term for typing things into a chatbot... The inferred definition of 'context engineering' is likely to be much closer to the intended meaning."
The term "prompt engineering" suggested cleverness in phrasing. "Context engineering" suggests systems thinking—architecture, not wordsmithing.
---
Why Context Engineering Matters Now
The Agent Era Demands More
We've moved from chatbots to agents. Simple Q&A applications could get by with clever prompts. But agents—AI systems that take actions, use tools, and operate over extended interactions—need more.
The key insight: Most agent failures are not model failures. They are context failures.When an AI agent hallucinates, gets confused mid-task, or makes poor decisions, the underlying model is usually capable of better performance. The problem is what it knows at the moment of decision.
Context is Everything the Model Sees
Context isn't just the prompt you send. It's everything the model sees before generating a response:
- System instructions — The persistent guidelines for behavior
- Conversation history — Previous exchanges in the current session
- Retrieved documents — Knowledge fetched from external sources (RAG)
- Tool outputs — Results from previous function calls
- Memory — Persisted information from past sessions
- Agent state — Current task status, plan, and intermediate results
In production agent systems, the actual prompt might represent 5% of the total context. The other 95% is everything else—and managing that "everything else" is context engineering.
---
Context Engineering vs. Prompt Engineering
Let's clarify the relationship between these disciplines.
Prompt Engineering
Prompt engineering focuses on what you say to the model at a specific moment:
- Crafting clear, specific instructions
- Using examples (few-shot learning)
- Structuring output formats
- Chain-of-thought reasoning
- Role-playing and personas
It's a writing skill. You're composing text that elicits good responses.
Context Engineering
Context engineering focuses on what the model knows when you speak to it:
- Designing memory systems for persistence
- Building retrieval pipelines for relevant knowledge
- Managing conversation history effectively
- Orchestrating tool availability and outputs
- Architecting the entire information flow
It's an architecture skill. You're building systems that reliably provide the right context.
title="Prompt Engineering" description="Asking better questions. A subset of context engineering focused on instruction design." /> title="Context Engineering" description="Giving better knowledge. The complete discipline of providing everything an LLM needs to succeed." />
The Hierarchy
Prompt engineering is a subset of context engineering, not the other way around. Good prompts still matter, but they're one component of a larger system.
Think of it this way:
| Aspect | Prompt Engineering | Context Engineering |
|--------|-------------------|---------------------|
| Scope | Single input-output | Entire information architecture |
| Focus | What to say | What the model knows |
| Skill type | Writing | System design |
| Repeatability | Often requires tuning | Designed for consistency |
| Tools required | Text editor | Memory systems, RAG, orchestration |
---
The Context Stack
Effective context engineering requires understanding the components that make up an LLM's working reality. We call this the "Context Stack."
Layer 1: System Instructions
The foundation of your context. System instructions define:
- Who the agent is (role, capabilities, constraints)
- How it should behave (tone, format, safety)
- What tools are available and how to use them
- Rules it must follow
- Be specific about capabilities and limitations
- Include examples of desired behavior
- Define output formats explicitly
- Update as the system evolves
Layer 2: Memory
Memory bridges the gap between sessions and extends the model's effective knowledge.
Short-term memory:- Current conversation history
- Recent tool outputs
- Active task state
- Scratchpad for reasoning
- User preferences learned over time
- Project-specific knowledge
- Historical decisions and their outcomes
- Patterns and conventions
Short-term memory lives in the context window—finite and precious. Long-term memory lives in external stores (databases, vector stores) and is retrieved as needed.
Layer 3: Retrieved Knowledge (RAG)
Retrieval Augmented Generation brings external knowledge into the context window:
- Documentation and reference material
- Codebase content
- User data and preferences
- Real-time information
- Hybrid search (semantic + keyword)
- Graph-RAG for relational knowledge
- Agentic RAG where the model controls retrieval
- Multi-source retrieval and synthesis
Layer 4: Tools and Their Outputs
Tools extend what the model can do. Tool outputs become part of context:
- Function call results
- API responses
- File contents
- Command outputs
Layer 5: Task State
For complex, multi-step tasks, the model needs to know:
- What has been accomplished
- What remains to be done
- Current blockers or issues
- The overall plan
This is especially important for agents that operate over many turns or resume interrupted work.
---
Techniques for Effective Context Engineering
1. Context Compression
The context window is finite. Effective context engineering means keeping it focused:
- Summarization: Condense verbose tool outputs
- Pruning: Remove irrelevant conversation history
- Aggregation: Combine similar information
- Selective retrieval: Only fetch what's needed for the current step
2. Context Prioritization
Not all context is equally important. Prioritize:
- Recent information over older information
- Task-relevant data over general knowledge
- User-specific context over generic instructions
- Error context when debugging
3. Scratchpads
Give the model a designated space to "think out loud":
- Store intermediate results
- Maintain working plans
- Record hypotheses being tested
- Track decision rationale
4. Dynamic Context Assembly
Build context dynamically based on the task:
``
Task: Fix authentication bug
→ Retrieve: auth-related code, recent error logs, auth documentation
→ Include: debugging instructions, testing commands
→ Exclude: unrelated project history, marketing content
`
5. Context Isolation
For multi-agent systems, isolate context appropriately:
- Each agent gets only what it needs
- Shared context for coordination
- Private context for specialized tasks
- Clear boundaries prevent confusion
---
The CAS Approach to Context Engineering
CAS (Coding Agent System) implements context engineering principles specifically for AI-assisted development. Here's how it maps to the context stack:
Unified Memory
CAS provides both short-term and long-term memory:
`
cas_remember: Store learnings, preferences, and facts
cas_search: Retrieve relevant memories semantically
cas_context: Get full session context
`
Memories persist indefinitely and surface automatically when relevant.
Task Tracking
CAS manages task state explicitly:
`
cas_task_create: Create tracked tasks with context
cas_task_start: Begin work with full context restoration
cas_task_notes: Add progress notes as you work
cas_task_close: Complete with resolution notes
`
Tasks maintain context across sessions. Resume exactly where you left off.
Rules and Skills
CAS captures patterns that should persist:
- Rules: Coding standards, project conventions, recurring instructions
- Skills: Learned procedures, command sequences, workflows
These become part of context automatically, improving consistency over time.
Semantic Search
Instead of loading everything, CAS retrieves relevant context:
`
cas_search: "How did we handle authentication?"
→ Returns: Relevant memories, task notes, decisions
``
Only pertinent information enters the context window.
---
Implementing Context Engineering: A Framework
Step 1: Audit Your Current Context
What does your LLM actually see? Map out:
- System instructions (how big? how specific?)
- Conversation history (how is it managed?)
- External knowledge (how is it retrieved?)
- Tool outputs (how are they handled?)
- Memory (does it exist? how is it structured?)
Step 2: Identify Context Failures
When your agent fails, ask:
- Did it have the information it needed?
- Was relevant context present but buried?
- Did irrelevant context cause confusion?
- Did context from earlier get lost?
Most failures trace to context problems, not model limitations.
Step 3: Design Your Context Strategy
For each component of the context stack:
| Component | Questions to Answer |
|-----------|---------------------|
| System Instructions | What does the agent need to know always? |
| Memory | What should persist across sessions? |
| Retrieval | What knowledge needs to be available? |
| Tools | What capabilities are needed? |
| Task State | How is multi-step work tracked? |
Step 4: Build the Infrastructure
Context engineering requires infrastructure:
- Memory stores: Database or vector store for persistent context
- Retrieval pipelines: Search and ranking for relevant content
- Orchestration: Logic for assembling context dynamically
- Monitoring: Visibility into what context is actually provided
Step 5: Iterate Based on Failures
Context engineering is empirical:
- Deploy your system
- Observe failures
- Trace failures to context issues
- Adjust context strategy
- Repeat
---
Common Context Engineering Mistakes
1. Loading Everything
More context isn't always better. Loading entire codebases, full documentation, or complete conversation histories:
- Consumes precious context window space
- Buries relevant information in noise
- Causes "context rot" — degraded performance
2. Ignoring History Management
Conversation history accumulates. Without management:
- Early important context gets pushed out
- Errors compound as the model loses track
- Performance degrades over long sessions
3. Static Context for Dynamic Tasks
Same system prompt for every task. Same retrieved documents. Same tool set.
Fix: Assemble context dynamically based on the current task. Different work needs different context.4. No Persistence Across Sessions
Starting fresh every session means:
- Re-explaining the same things
- Lost learnings
- No improvement over time
5. Underspecified Instructions
Vague system instructions leave the model guessing:
- "Be helpful" — How?
- "Write good code" — What style?
- "Use tools appropriately" — When?
---
The Future of Context Engineering
Context engineering is evolving rapidly:
Longer Context Windows
Models with 1M+ token context windows change what's possible. But more capacity doesn't eliminate the need for engineering—it shifts the challenge from "what fits" to "what helps."
Agentic Context Management
Models are learning to manage their own context:
- Deciding what to retrieve
- Summarizing as they go
- Prioritizing information
- Organizing their workspace
Semantic Context Layers
Moving beyond simple retrieval to semantic understanding:
- Knowledge graphs for relationship-aware context
- Multi-modal context (code, images, diagrams)
- Cross-session context threading
Context Standardization
Emerging standards like MCP (Model Context Protocol) enable:
- Consistent context provision across applications
- Reusable context infrastructure
- Ecosystem of context sources
---
Context Engineering Checklist
Use this checklist when designing AI systems:
Clear, specific, with examples. Updated as the system evolves.
Short-term for current work. Long-term for persistent knowledge. Clear boundaries.
Semantic search. Relevance ranking. Multiple sources if needed.
Summarization strategy. Clearing policy. Context budget.
What to keep. What to summarize. How to integrate.
Current progress. Remaining work. Blockers. Plan.
Observe failures. Trace to context. Adjust. Repeat.
---
Conclusion
Context engineering is not a new term for an old practice. It represents a fundamental shift in how we build AI systems—from hoping prompts work to engineering reliable context.
The core principle is simple: an LLM can only be as good as the context it's given.
As AI agents become more capable, context engineering becomes more critical. The models will improve, but the need for thoughtful context design will not diminish. If anything, more capable models require more sophisticated context to realize their potential.
For developers building AI-powered applications, mastering context engineering is no longer optional. It's the difference between demos that impress and systems that work.
CAS provides a complete context engineering solution for AI-assisted development. Persistent memory, task tracking, semantic search, and automatic context management—everything you need to give your AI agent the context it deserves.
---
Further Reading
- Effective Context Engineering for AI Agents — Anthropic
- Context Engineering for Agents — LangChain
- Simon Willison on Context Engineering
- The New Skill in AI is Not Prompting, It's Context Engineering — Philipp Schmid
- Context Engineering Techniques — LlamaIndex