[D] The agent memory ordering problem loading past context before current evidence creates anchoring bias
Ran into something subtle while building a diagnostic agent for LLM quality monitoring that I haven't seen written about much. Posting because it might be useful for others building similar systems.
The agent investigates why LLM quality dropped. It has access to past investigation episodes stored in a database — what the agent found last time quality dropped, what the fix was.
My first implementation loaded these past episodes into the system prompt before the agent ran. The idea was to give the agent context about what it had seen before.
The problem: the agent would read "we saw this pattern 3 weeks ago, root cause was prompt structure" before looking at any current evidence. Then it would run fetch_recent_traces, see the current failing cases, and anchor its analysis on the past pattern even when the current regression was a completely different bug class. It was essentially "we've seen this before" before it had looked at "what are we actually seeing now."
This is the same anchoring bias humans exhibit — first information you receive disproportionately influences interpretation of subsequent information. I had accidentally baked it into the agent's context loading order.
The fix was simple once I understood the problem: inject episodic memory into context AFTER the first tool call completes, not before. The agent collects fresh evidence first, then has access to historical patterns for comparison. The ordering changed from:
[past context] → [current query] → investigate
To:
[current query] → investigate → [first tool result + past context] → continue investigation
After this change the agent stopped misidentifying new failure modes as previously-seen patterns. Diagnoses became noticeably more accurate on cases where the current regression was superficially similar to a past one but had a different root cause.
The broader principle: for agents that use episodic memory, the insertion point of historical context into the reasoning chain matters as much as whether you include it at all. Historical context is most useful as a reference AFTER gathering current evidence, not as a frame BEFORE examining current evidence.
Curious whether others have run into this. Is there a principled way to decide when to inject different memory types? I've been thinking about it as: in-context and project context at the start (defines the task and scope), semantic search results and episodic memory after first tool call (reference after fresh observation), never in the system prompt for anything time-sensitive.
Does that hold up? Or are there cases where historical context should come first?