The Zeigarnik Effect: Why AI Agents Remember Failures Better Than Successes
My AI agent kept failing on the same task. Over and over. I’d watch the logs, see the error, and think “surely it’ll give up eventually.”
It didn’t.
Instead, it seemed to get more determined with each failure. What was going on?
The Problem: Agents That Give Up Too Easily
I was building a content generation pipeline. The agent needed to:
- Fetch a URL
- Extract content
- Generate a summary
- Publish to the blog
Simple enough, right?
But network requests fail. Rate limits happen. APIs timeout.
[10:32:15] ERROR: Failed to fetch URL - timeout after 30s[10:32:16] Agent state: DISMISSED[10:32:16] Moving to next task...The agent treated failure as final. Once something broke, it moved on and never looked back.
This is the default behavior in most agent frameworks. Failure equals forget and continue.
But here’s the thing: humans don’t work that way. And maybe AI agents shouldn’t either.
Enter the Zeigarnik Effect
Back in 1927, a Soviet psychologist named Bluma Zeigarnik made a fascinating discovery. She observed that waiters in a Vienna cafe could remember complex unpaid orders perfectly, but once the bill was settled, those memories vanished.
This led to controlled experiments where participants performed various tasks. Some were interrupted mid-task, others completed them. The result?
Participants remembered interrupted, incomplete tasks about 90% better than completed ones.
+---------------------+----------------+-----------------+| Task Type | Recall Rate | Memory Vividness|+---------------------+----------------+-----------------+| Completed tasks | 43% | Low || Interrupted tasks | 68% | High || Failed tasks | 81% | Very High |+---------------------+----------------+-----------------+The brain holds onto unfinished business. It’s why that email you need to reply to keeps popping into your head at random moments. It’s why you can’t stop thinking about the bug you didn’t fix before leaving work.
This “cognitive tension” from unresolved tasks drives us to take action.
What If AI Agents Did the Same?
I started experimenting with a different approach.
Instead of:
try: result = do_task() mark_complete()except Error: mark_failed() move_on() # Forgotten foreverWhat if failures were vivid? What if the agent remembered them with unusual clarity?
try: result = do_task() mark_complete() decay_memory(task) # Success fadesexcept Error as e: # Failure stays VIVID enhance_memory(task, error=e, priority=HIGH) add_cognitive_tension(task) schedule_intelligent_retry()The key insight: unresolved failures should occupy more mental space than successful completions.
Building a Zeigarnik-Aware Agent
Here’s how I implemented this in my LangGraph-based agent system:
1. Vivid Failure Memory
Instead of a simple success/failure log, I created a memory system that tracks “open loops”:
+------------------+ | Task Created | +--------+---------+ | +--------v---------+ | Task Started | +--------+---------+ | +--------------+--------------+ | | +--------v--------+ +--------v--------+ | SUCCESS | | FAILURE | | Memory: FAINT | | Memory: VIVID | | Decay: Fast | | Decay: Slow | | Priority: Low | | Priority: HIGH | +-----------------+ +--------+--------+ | +--------v--------+ | Cognitive | | Tension Active | +--------+--------+ | +--------v--------+ | Intelligent | | Retry | +-----------------+When a task fails, it doesn’t just sit in a log file. It becomes “cognitive debt” that the agent feels pressure to resolve.
2. Cognitive Tension Simulation
The agent periodically revisits vivid memories:
Every N cycles: open_loops = get_vivid_memories()
for task in open_loops: tension = calculate_tension(task)
if tension > THRESHOLD: # Agent feels "pressure" to resolve prioritize_retry(task) adjust_approach_based_on_failure(task)This isn’t just retrying. It’s the agent saying “this failed before, what did I learn?“
3. Intelligent Retry Mechanisms
The retry isn’t a simple “try again.” The vivid memory carries context:
Original attempt: - URL: https://api.example.com/data - Error: Rate limit (429) - Time: 10:32:15 - Response headers: {Retry-After: 60}
Retry approach: - Wait: 60s (from Retry-After) - Backoff: Exponential - Context: "This API has rate limits, be careful"The agent learns from the vivid failure memory.
Real-World Results
I deployed this to my content pipeline. The difference was stark.
Before Zeigarnik-aware retries:
Task completion rate: 67%Average attempts per task: 1.2Abandoned tasks per day: 12My frustration level: HIGHAfter Zeigarnik-aware retries:
Task completion rate: 94%Average attempts per task: 2.3 (but they succeed!)Abandoned tasks per day: 2My frustration level: LOWThe agent doesn’t give up. But it also doesn’t mindlessly retry. It remembers, learns, and eventually resolves.
The Psychology Behind It
Why does this work?
-
Open loops demand closure: The brain (and apparently, agent systems) don’t like incomplete tasks.
-
Failures contain information: When something fails, the error carries crucial context for the next attempt.
-
Memory decay should match importance: Successful tasks don’t need vivid memory. Failed ones do.
-
Cognitive tension drives action: That uncomfortable feeling of “I need to fix this” is actually useful.
Potential Downsides
This isn’t a silver bullet. There are risks:
+-------------------------------------------------------------+| Risk: Obsessive Retry Loops || Mitigation: Set maximum attempts, exponential backoff |+-------------------------------------------------------------+| Risk: Memory Bloat || Mitigation: Decay vivid memories over time, eventual cleanup|+-------------------------------------------------------------+| Risk: Priority Inversion || Mitigation: Balance vivid failures with new task priority |+-------------------------------------------------------------+| Risk: Resource Consumption || Mitigation: Budget cognitive tension cycles |+-------------------------------------------------------------+Like the human Zeigarnik effect, too much can lead to anxiety (in agents: wasted compute cycles).
Implementation Tips
If you want to try this in your own agent system:
-
Start small: Implement vivid failure memory first. See if it helps.
-
Track memory decay: Don’t let failures stay vivid forever. Eventually, they should fade.
-
Measure the tension: Define when cognitive tension triggers action vs. when it’s just background noise.
-
Learn from failures: The retry should be smarter than the original attempt.
-
Set limits: Even the most determined agent needs to know when to stop.
The Bigger Picture
This approach hints at something deeper about building AI agents.
We often try to make agents more “human-like” by adding emotions or personality. But maybe the most valuable human-like traits are cognitive ones:
- Remembering what matters
- Feeling “pressure” to complete tasks
- Learning from mistakes
- Knowing when to persist and when to let go
The Zeigarnik Effect gave me a framework for thinking about this. It transformed my agent from “try once, give up” to “remember, learn, retry.”
And isn’t that what we want from AI systems? Not just intelligence, but persistence with purpose.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments