Articles / Viewpoints and methods
13 minFor system designers

Four Context Failures—and the Cost Paradox Behind Them

Microsoft's context and memory lessons frame four context failures, mitigation choices, and trade-offs among memory tools, information quality, and cost.

Aaron HuangSystems, product and AI practice

This analysis organizes four Context Failures—and the Cost Paradox Behind Them into a practical comparison of evidence, decisions and current limits.

Read the evidence below as a decision trail: what changed, why it matters, which trade-offs shaped the result, and where the conclusion still depends on context.

Microsoft directly established "Context Engineering" as an independent chapter in Lesson 12 of AI Agents for Beginners - this in itself is a signal: context management has been upgraded from "an extension of prompt engineering" to a core agent capability alongside memory, planning, and tools. This dismantling of Lessons 12 + 13 focuses on 4 types of context failure mitigation, memory layer selection for Mem0/Cognee/Azure AI Search, and 4 trade-offs that are not explicitly stated in the Microsoft version.

Why is this course called "Context Engineering" and not "Prompt Engineering Pro"

The definition given by Microsoft is very clean:Prompt engineering is "designing a set of static instructions to guide the agent"; Context engineering is "managing a set of dynamic information to ensure that the agent always gets what it needs on the timeline". The former is written once and finalized, while the latter requires continuous adjustment. This distinction sounds simple, but in practice the requirements for organizational capabilities vary greatly - prompt engineering can be done by a prompt engineer, while context engineering requires designing pipelines, setting triggers, and managing lifecycles.

What's more worth stopping to look at are the five source categories of context: Instructions (prompt + tool description), Knowledge (facts + RAG + memory), Tools (function / API / MCP server definition), Conversation History (conversation history), User Preferences (user preferences). These 5 categories fall into the context windowdifferent rhythm — Instructions are one-time in the setup phase, Tools are dynamic before the current call, Conversation History is cumulative, and User Preferences are pulled in across sessions. Once the classification is done, you will have a structure to answer the following questions of "what to enter, when to enter, and how to organize."

6 Practical Management Strategies (Lesson 12 Overview)

Microsoft has listed 6 practical strategies. The order of these 6 is worth noting - from light to heavy:

  1. Agent Scratchpad: in context window outsideThe file/runtime object stores the notes of the current session and can be read back when needed. Lightweight and suitable for single session.
  2. Memories: Cross-session storage. It is one layer heavier than scratchpad and requires lifecycle management.
  3. Compressing Context: When the context is close to the upper limit, use summarization or trimming to compress it. Moderate cost (call LLM per compression).
  4. Multi-Agent Systems: Each agent has its own context window and uses dispersion to prevent single window from exploding. Heavy, cross-agent state synchronization is expensive.
  5. Sandbox Environments: When running code or processing a large amount of data, open the sandbox and only read the results back to the context without putting all raw data into the context.
  6. Runtime State Objects: Complex tasks use containers to store the results of each subtask. The context is only connected to the current subtask and is released when it ends.

The implicit order of this list:Use the lightest ones (scratchpad, compression) first if you can solve them; if not, then upgrade to multi-agent / sandbox / state object. Intuition is often reversed - when you see a complex task, you want to use multi-agent, but the result is to use a cannon to kill mosquitoes. For most agents, scratchpad + compression is enough.

4 types of Context Failure and mitigation

This section is the most concrete value of Lesson 12. Microsoft lists 4 types of context failures, each with a Travel Booking case:

Failure 1: Context Poisoning — Cost Paradox

what is: A hallucination occurred in LLM (for example, "A certain small airport has direct flights to Paris" actually does not exist). This piece of false information entered the context and was constantly quoted. The agent kept trying to book this non-existent route.

official mitigation: Validate information before entering long-term memory; quarantine and open a new context thread if contamination is detected.

Unspecified trade-off: The cost of Validation itself - verifying whether a flight exists requires a real-time API or LLM call, and each verification will be very expensive. In practice, it needs to be layered: high-cost actions (irreversible bookings, payments) must be verified before; low-cost suggestions (drafting itineraries) can be postponed to the commit stage before verification. Microsoft has given principles but not a criterion of "when to test" - this judgment is different in each application and must be designed by oneself.

Failure 2: Context Distraction — There is no general rule for choosing and choosing

what is:context is too long, and the model begins to focus too much on the accumulated history and ignores the ability to learn during training. Maybe the error started before the context window was full. Travel case: You chatted for a long time about the details of the backpacker trip 2 years ago, and then asked "Looking for cheap air tickets next month", but the agent kept going back to ask you "your mountaineering equipment needs" and forgot about the current request.

official mitigation: Regular summarization compresses old history into a summary, retaining the key points and discarding details.

Unspecified trade-off: summarization isLossy compression — There is no general rule about what is important and what is disposable. In the Travel case, the "backpacker details from 2 years ago" need to be lost, butThat user might really want to plan a backpacking trip next time- Losing too much will cause personalization to lose depth. Distraction vs learning (learning preferences from history) is a real tension, not a purely technical issue. In practice, there are two levels of management: "temporary context" (can be aggressively compressed) vs. "persistent memory" (conservative update).

Failure 3: Context Confusion — Cycle risk of Tool Loadout RAG

what is: The agent has too many tools available, the model is confused during selection, and irrelevant tools are called. Small models are particularly affected. Travel case: You asked "How to move in Paris", but the agent called book_flight(I mistakenly thought I had to book a flight to Paris).

official mitigation: Use RAG for tool loadout management - tool descriptions are stored in vector database, and relevant tools are dynamically selected based on the current query. Microsoft mentioned that research suggests limiting the number of tools to less than 30.

Unspecified trade-off: tool loadout RAG itself will hallucinate - the tool captured by vector similarity may not really be the most relevant. Extreme example: User asked "How to move in Paris", tool RAG captured rent_car follow book_flight(Because description contains words such as "Paris" and "travel"), missing what really needs to be grasped public_transport_infoUsing RAG to solve confusion is equivalent to shifting the problem from "LLM to choose tool" to "RAG to choose tool" - the problem does not disappear, just changing layers. So Microsoft’s number “under 30” isBecause RAG is unreliable, there is a hard limit on the total number of tools., not RAG solves everything.

Failure 4: Context Clash — Pruning vs Scratchpad

what is: There is conflicting information in the context (for example, "I want economy class" first, and then "change business this time"). The agent gets the conflicting search results and does not know which one to give priority to.

official mitigation: Use context pruning (new instructions come in, old instructions are explicitly removed) or offload to scratchpad (first align conflicts in scratchpad, and then write back to the main context).

Unspecified trade-off: Pruning is simple, but it will eat up the "conversation context" - users may want to read agent to know that I said economy class before, and now changing it to business does not mean "I will always be in business", it may just be special this time. Scratchpad retains the context, but adds a layer of computational cost (you have to make another decision when you want to pull back the main context from scratchpad). The answer to this trade-off is different in the scenario of "one-time task" vs. "long-term relationship agent".

Lesson 13 — 7 memory types + 3 storage solutions

Lesson 13 breaks down memory very carefully: Working / Short Term / Long Term / Persona / Workflow-Episodic / Entity / Structured RAG 7 types. In practice, it is not necessary to implement each of them, but you must knowMemory is not a single lump — "Retain user preferences across sessions" (Long Term) and "Retain the step sequence of this task" (Episodic) have different needs and need to be designed separately.

Choice of 3 storage options:

  • Mem0: Two-stage pipeline (extraction + update). First use LLM to extract new memories from the conversation summary; then use LLM to decide whether to "add/modify/delete" existing memories. The storage layer is hybrid (vector + graph + key-value). The key to this architecture is update contains delete — Many self-made memory systems only perform add but not delete. As a result, the memory accumulates to the point that it cannot be used. Mem0 also outsources "deciding whether to delete" to LLM.
  • Cognee: dual-store (vector + graph) + hybrid retrieval. The advantage is that "it not only remembers the similarity, but also the relationship between entities" - suitable for scenarios where you need to understand "why these two things are related". The price is that building + maintaining a graph is heavier than a pure vector.
  • Azure AI Search does Structured RAG: Suitable for scenarios where enterprise data is large and high precision/recall is required. Microsoft says that Structured RAG has "superhuman precision and recall" compared to traditional chunk + embed, but it must first organize the data into a structured form (you can't use it just by throwing away a bunch of files).

Selection judgment:Personalized preferences are the main → Mem0; entity relationship reasoning is required → Cognee; enterprise-level structured data → Azure AI Search. It's not that which one is stronger, but that the applicable scenarios are different.

Knowledge Agent — the standard model for self-improvement

The “knowledge agent” pattern introduced in Lesson 13 is worth remembering: use aindependent The agent observes the main conversation, decides what is worth remembering, extracts the summary, stores it in the knowledge base, and retrieves it back to supplement the context the next time the user queries.

The core of this pattern is"Deciding what to remember" and "Executing the conversation" are divided into two agents. — The main agent concentrates on serving users, and the knowledge agent concentrates on memory curation. The optimization mentioned by Microsoft: the knowledge agent can use the cheaper fast model to do triage first, determine whether it is worth further processing, and only use the trigger to call the expensive model. This optimization has a great impact on costs.

My observations — 4 trade-offs that Microsoft’s version doesn’t explicitly mention

Trade-off 1: Context engineering is an ops capability, not a prompt capability

The full text of Lesson 12 focuses on "strategy", but in practice, does context engineering run well?Mainly depends on ops capabilities — How to set the summarization trigger, how to write the memory delete policy, and how to manage the version of tool loadout. These are not solved by writing prompt, but by writing pipeline. If the team only has prompt engineer and no platform engineer or context engineering, it will be stuck in "the design is very good, but it can't run".

Trade-off 2: All four failure mitigations push costs elsewhere

Poisoning → validation takes more API calls; Distraction → summarization takes more LLM calls; Confusion → tool loadout RAG takes more vector query; Clash → scratchpad takes more layers of operations.No free context management- Each mitigation pushes the cost from token to latency or to external calls. This cost must be taken into account when designing, and it is not "just to add relief."

Trade-off 3: At the memory level, "should I remember" is more difficult than "how to remember"

Mem0 outsources this to LLM, Cognee uses structure prompts, and Azure AI Search uses schema enforcement - all three.Not solving problems, shifting problems. In the end, you still have to write a policy somewhere about "this kind of information is worth remembering and what kind of information should not be remembered." If the policy is not well written, no matter how much it is memorized, it will just be noise. In practice, most teams underestimate the amount of work involved.

Trade-off 4: Multi-agent is a means of context isolation, not a panacea

Lesson 12 lists multi-agent as one of the six context management strategies. This framing is very important - the value of multi-agent is not only "division of labor", but also "context isolation" (each agent has its own window and does not contaminate each other). However, multi-agent brings coordination overhead, and state synchronization between agents itself is also a context engineering problem. Be careful about using multi-agent as an antidote: it solves the context size problem and introduces context fragmentation. I myself have gone through this path when implementing multi-AI tool collaboration, and the final design I adopted was "not sharing conversation context, sharing data through the file system, and people bridging the middle." The core is to treat context isolation as an explicit design and not assume that "seamlessness" between agents is a good thing.

Practical questions and boundaries

Are Context engineering and RAG the same thing?

No. RAG is a type of "pull data from external knowledge base into context"technology;context engineering isWholeThe knowledge of managing context in and out - including RAG, prompt design, memory, tool loadout, compression, conversation history management, etc. RAG is one of the tools of context engineering, not all. Among the five context types in Lesson 12, the Knowledge type mainly uses RAG, and the other four types each have their own management strategies.

Can you do context engineering without an Azure subscription?

Absolutely. The core of Context engineering is design judgment and not tied to a specific platform. Mem0 is an independent open source tool, Cognee is an independent open source, and Agent scratchpad / Runtime state object is a design pattern that does not require any service. Azure AI Search is only necessary in scenarios where enterprise-level structured RAG is required. Most teams can get pretty far starting with Mem0 or a homemade sqlite-based scratchpad.

How to design the policy of "Should I remember it or not?"

In practice, it is divided into 3 levels: (1) Must remember — Preference clearly stated by the user ("I am a vegetarian" "I don't like early flights"); (2) condition note — The preference recommended by the agent ("I chose business this time, maybe it is a business trip and not a personal preference") needs to be confirmed twice or marked with low confidence; (3) Don't remember — One-time context (special needs of this trip, expired after business trip). Mem0's LLM-driven update can help determine, but the policy prompt must be clear, otherwise LLM will make random decisions.


Original source: Microsoft AI Agents for Beginners — Lesson 12 Context EngineeringLesson 13 Agent Memory

Extended reading: existing articles on this site Why I deliberately made two AI tools unaware of each other’s existence — Context isolation principle for multi-tool collaboration(2026-05-10 gwarket revision actual combat, four-tool collaboration and three elements of context isolation)

What to take away

The article's value is in the evidence and trade-offs behind four Context Failures—and the Cost Paradox Behind Them, not in treating the conclusion as universal.