Context Engineering
The practice of designing and optimizing all information provided to an AI model—including system prompts, retrieved documents, conversation history, tools, and examples—to get better results.
What is context engineering?
Context engineering is the practice of designing and optimizing all the information provided to an AI model to get better results. It goes beyond prompt engineering to encompass everything the model can "see"—system prompts, retrieved documents, conversation history, tool definitions, examples, and structured data.
Think of it this way: prompt engineering is writing a good question. Context engineering is curating everything the AI needs to give a great answer.
The term gained prominence as practitioners realized that the quality of AI outputs depends not just on how you phrase requests, but on the entire context window: what information is included, how it's structured, and what's omitted.
Why context engineering matters
Models are only as good as their context Large language models don't have persistent memory or real-time knowledge. Everything they need to respond accurately must be in the context window. Poor context = poor output, regardless of model capability.
Context windows are limited Even with context windows reaching millions of tokens, you can't include everything. Context engineering is about strategic selection—including what matters, excluding what doesn't.
Structure affects understanding How information is organized impacts how well the model uses it. A well-structured context helps the model find and apply relevant information; a chaotic context leads to confusion and hallucination.
It's the new competitive advantage Two applications using the same model can have vastly different performance. The difference often comes down to context engineering.
Components of context engineering
System prompts The foundational instructions that define model behavior: role, persona, guidelines, output format, constraints. See system prompt.
Retrieved information (RAG) Documents, data, and knowledge fetched at runtime from vector databases, APIs, and user-specific sources. RAG is a core context engineering technique.
Conversation history Previous messages for continuity, summarized history for longer conversations, key decisions from past interactions.
Tool definitions Function calling schemas, MCP server descriptions, usage examples and constraints.
Examples (few-shot learning) Input/output pairs demonstrating desired behavior. See few-shot learning.
Structured data JSON schemas, tables, metadata, and tags organized for efficient processing.
Context engineering techniques
Prioritization Place critical information at the beginning and end of context—models attend more to these positions.
Chunking and selection Break large documents into chunks and select only relevant portions using embeddings to find semantically similar content.
Summarization Compress information to fit more in context. Summarize conversation history periodically; use hierarchical summarization for very long content.
Metadata enrichment Add source, timestamp, confidence scores, and relationships to help the model evaluate and use information.
Dynamic assembly Build context at runtime based on the specific query. Route to different templates, adjust detail levels, include relevant tools.
Context engineering for agents
AI agents require sophisticated context engineering because they operate autonomously across multiple turns.
Persistent identity files Frameworks like OpenClaw and Clawdbot use configuration files:
- SOUL.md - Agent personality and values (soul file)
- USER.md - Information about the user
- MEMORY.md - Long-term curated knowledge (agent memory)
- AGENTS.md - Workspace conventions
Memory management Working memory for current task, persistent memory across sessions, and memory consolidation and cleanup.
Tool context Which tools are available, when to use each tool, and how to interpret tool outputs.
Context engineering vs prompt engineering
| Aspect | Prompt Engineering | Context Engineering |
|---|---|---|
| Scope | The user message/prompt | Everything in context window |
| Focus | How to ask | What to include |
| Techniques | Wording, structure, examples in prompt | RAG, memory, tools, system prompts |
| Scale | Single interaction | System-wide design |
Context engineering encompasses prompt engineering but extends to the entire information environment the model operates in.
Related Terms
Prompt Engineering
The practice of designing and refining inputs to AI models to get better, more accurate, and more useful outputs.
Retrieval-Augmented Generation (RAG)
A technique that enhances AI responses by retrieving relevant information from external knowledge sources before generating an answer.
Context Window
The maximum amount of text (measured in tokens) that a language model can process in a single interaction.
System Prompt
Special instructions given to an AI model that define its behavior, personality, and constraints before any user interaction.
AI Agents
Autonomous AI systems that can perceive their environment, make decisions, and take actions to achieve specific goals.
Build AI with optimized context
Chipp provides built-in context management including RAG, memory, and structured prompts for your AI agents.
Learn more