Agent Memory Errors Handbook: Cases 26–30
This installment is part of the Agent Memory Errors: 100 Cases Handbook series.
Case 26: Short-term Memory / Context Errors — In Context Learning Example Contamination
Scenario
The Agent uses few-shot prompting with three fixed examples in the system prompt. In one conversation the user’s input happens to resemble a format from an example (e.g., a JSON schema). The LLM confuses the user input with the examples and treats it as part of a fourth example.
Error Manifestation
The Agent’s output format is contaminated by the “fourth example” and starts mimicking the non-standard format in the user input instead of following the defined output spec.
Solution
- Use explicit example separators such as
=== Example 1 ===…=== End Example === - Isolate examples from user input with special tokens such as
<|endofprompt|> - Use dynamic example selection: pick the most relevant examples from a library rather than using fixed examples
Principle
The strength of in-context learning is also its weakness: LLMs cannot strictly distinguish template examples from user data. Format contamination is a known risk of few-shot prompting.
Case 27: Short-term Memory / Context Errors — Conversation Branch Merged Without Resolution
Scenario
The user and Agent discuss whether remote work should be universal. The user first gives arguments supporting remote work (Branch A), then arguments against it (Branch B), and finally asks, “What do you think?” The Agent’s context contains both branches but does not mark them as opposing assumptions.
Error Manifestation
The Agent replies with both “Remote work indeed improves efficiency” and “But face-to-face collaboration is irreplaceable” without clarifying that these are two different perspectives. The user finds the stance vague.
Solution
- Use a conversation tree rather than linear context, tagging each point with its branch and assumption
- When merging branches, explicitly label “Under assumption X” and “Under assumption Y,” or ask which branch to discuss
- Use belief-state tracking: maintain support/oppose/pending labels for each proposition
Principle
Real conversations are non-linear and include hypotheticals and role-play. Linear context cannot represent branching structure, and merging branches creates logical conflicts. Conversation trees are a more precise model.
Case 28: Short-term Memory / Context Errors — Summarization Induced Fact Substitution
Scenario
After a long conversation, the Agent compresses the context. The user originally said, “I like PyTorch, but company projects require TensorFlow.” For brevity, the summary becomes “User develops with TensorFlow.”
Error Manifestation
Later, the Agent recommends TensorFlow tools and resources based on the summary, ignoring the user’s actual preference for PyTorch. The user feels the Agent was not really listening.
Solution
- Apply a fact-fidelity constraint: instruct the summarizer to compress wording without changing facts
- Use extractive summarization instead of abstractive summarization so key sentences remain verbatim
- Back-translate the summary into a longer text and check factual consistency with the original
Principle
Abstractive summarization may perform semantic approximation during compression. Even when the gist is preserved, small changes in specific facts—preferences, numbers, names—can bias later reasoning.
Case 29: Short-term Memory / Context Errors — Context Window Fragmentation Tool Calls
Scenario
The Agent uses a tool chain for complex tasks. Each tool call includes the tool definition (JSON Schema), parameters, and results. In one data-analysis task the Agent calls ten tools; each call’s schema and result consume 500 tokens, totaling 5,000 tokens. With the system prompt included, less than 1,000 tokens remain for the user’s conversation.
Error Manifestation
The user’s next input is truncated. The Agent sees only the first half of the question, misunderstands the intent, and gives a wrong analysis.
Solution
- Compress tool-call history: keep only tool name, key parameters, and result summary; drop full schemas and redundant output
- Use a tool-memory cache: store frequently used results externally and keep only reference IDs in context
- Allocate an independent context budget for tool calls (e.g., at most 30%) and compress the oldest tool records first when exceeded
Principle
Tool calls consume large amounts of context. Without management, tool history crowds out user content, producing the experience of the user being cut off mid-sentence.
Case 30: Short-term Memory / Context Errors — Temporal Marker Ambiguity Resolution
Scenario
On Monday the user says, “Yesterday I went to the doctor.” The Agent records “User went to the doctor yesterday.” On Wednesday the user asks, “When was my last doctor visit?” The Agent computes “yesterday” from the current context as Tuesday, but the user’s “yesterday” meant Sunday.
Error Manifestation
The Agent answers, “You went to the doctor on Tuesday.” The user corrects, “I went on Sunday.” The Agent appears confused about time.
Solution
- Normalize times when recording: convert relative expressions (yesterday, next Wednesday) to absolute timestamps
- Store both the original expression and the normalized timestamp; choose the appropriate expression when answering
- Set validity periods for time-sensitive records, e.g., automatically archive “meeting tomorrow” after the meeting passes
Principle
Natural-language time expressions are relative to speech time. Agents must anchor them to absolute time; otherwise temporal references drift as the session progresses.
Source: Agent Search