Context engineering is managing what information the agent has over time β unlike prompt engineering, which focuses on static instructions. Context includes instructions, knowledge (RAG, memory), tools and their results, conversation history, and user preferences. Strategies: scratchpad (session notes outside the context window), long-term memory, summarization and trimming, multi-agent context sharing, sandboxes for heavy computation, and runtime state objects. Avoid poisoning (validate and quarantine), distraction (summarize), confusion (fewer, relevant tools per task), and clash (prune conflicting instructions).
What goes into the context (and why it matters)
Multiple sources β one context window
Types of context
- Instructionsβ System prompt, few-shot examples, tool descriptions.
- Knowledgeβ Facts, RAG results, long-term memory.
- Toolsβ Definitions + results of tool calls.
- Conversation historyβ Ongoing dialogue (grows over time).
- User preferencesβ Stored likes/dislikes for personalization.
Common context failures & fixes
Example: Book a trip to Paris
Simple agent: "When would you like to go?" Context-engineered agent: checks calendar, recalls preferred airline and budget from memory, sees available booking tools, then says: "Youβre free the first week of October. Shall I search for direct flights on [Preferred Airline] within [Budget]?"