DEV Community

Cover image for Teaching a Qwen agent to forget
PRASAD TILLOO
PRASAD TILLOO

Posted on

Teaching a Qwen agent to forget

Every AI photo tool today is an amnesiac critic. Lightroom edits, culling apps, and ChatGPT/Gemini/Qwen will happily critique a single photo — then forget you exist. You re-explain yourself every session, get the same beginner advice forever, and nothing knows whether you're actually improving.

Memory is the difference between a critic and a coach: someone who knows where you started, notices what you've mastered, and moves the goalposts as you grow.

So for the Global AI Hackathon with Qwen Cloud (Track 1: MemoryAgent), I built Engram — an AI photography coach whose most important organ isn't the critique. It's a forgetting-aware memory engine.

Engram Home — a memory, not a dashboard

The loop

Engram runs one loop, forever:

  1. Critique — upload a photo; qwen-vl-max scores five dimensions with glass-box reasoning grounded in real photography principles.
  2. Remember — every critique writes memory: salience-scored facts, skill evidence, a genre identity. The app then tells you what it learned from this photo.
  3. Focus — skills you're working on are watched; three consecutive strong sessions and a skill graduates — celebrated on your timeline, then retired from coaching.
  4. Adapt — the next critique and every chat reply are built from what's still true about you.

Home stops being a dashboard and becomes a memory: a mentor's read of you, genre "memory threads" you step through like a photo-app Memories reel, and a coaching plan that changes as you do.

The hard part wasn't remembering — it was forgetting

Anyone can append facts to a database. The interesting problem Track 1 named is timely forgetting: what happens when a fact stops being true?

You switch from a Canon body to a Sony mirrorless. A memory that remembers everything forever keeps coaching you on a camera you sold last month. So Engram does two things most "memory" layers don't:

  • Supersession. A contradicted fact gets a superseded_by link — excluded from recall, but kept in an audit trail. Forgetting you can't inspect is just data loss.
  • Graduation. A mastered skill is retired from active coaching — forgetting rendered as promotion, not deletion.

The Memory Proof Room — watch a stale fact retire, live

Proving it: the FAMA benchmark

Claims are cheap. I froze 26 scripted photographer histories — gear switches, twice-replaced habits, multi-hop questions, and controls where nothing changes — and scored the engine against two baselines with a metric I called FAMA (Forgetting-Aware Memory Accuracy: rewards recalling every still-true fact, penalizes surfacing outdated ones).

config mean FAMA recall of still-true facts context tokens
Engram (forgetting on) 1.00 100% 1.72× fewer
recency-only (keep the 5 newest facts) 0.64 100% baseline
never-forgets (full history) 0.64 100% baseline

The result worth sitting with: the two baselines tie. Keeping only the newest facts scores exactly the same as keeping everything — because recency can't tell that a newer fact invalidates an older one. The win isn't about trimming context; it's about knowing what's stale. And recall stays at 100% across all three, so the engine isn't trading recall for forgetting — it gets both, at 1.72× lower token cost.

One command reproduces it: python -m eval.run --compare.

Building on Qwen Cloud

Every model call goes through Alibaba's DashScope (OpenAI-compatible) endpoint, across three tiers behind one client:

  • qwen-vl-max — vision critique + genre
  • qwen3.7-max — reasoning / shape repair
  • qwen3.6-flash — mentor chat (SSE streaming), summaries, cheap repairs

Two things I learned building on it:

Qwen trusts your prompt where other stacks enforce a schema. My first live critique came back with the critique as prose, an invented overall score, and dropped arrays. The fix was a defense-in-depth chain: an explicit JSON skeleton in the prompt, then a local deterministic salvage layer that repairs known deviations (near-miss enums, out-of-range scores) in ~0.1ms — replacing a model-based repair loop that once burned 93 seconds and 502'd in front of me. Reliability became a feature.

Sometimes the model is right and your schema is wrong. One early response returned genre: "still_life" — refusing my enum because the photo genuinely was a still life and my taxonomy lacked it. It's in the enum now.

The whole thing — SPA, API, memory engine, and a custom engram-mcp server (so any Qwen agent can mount the same memory over MCP: recall / forget / get_memory_stats) — ships as one Docker image on an Alibaba Cloud ECS instance in Singapore, behind Caddy TLS, with photo storage one env flip from Alibaba OSS.

The takeaway

Users don't care that facts persist. They care that the coaching changes because of them. Committing to a forgetting metric didn't just measure the product — it shaped it: supersession semantics, audit trails, receipts on every reply. Memory is a behavior, not a store.

Try it (no login): https://engram.prasadtilloo.com/?judge=1
Code (Apache-2.0): https://github.com/prasadt1/engram

Built with Qwen Cloud (DashScope) + Alibaba Cloud ECS for the Global AI Hackathon, Track 1: MemoryAgent.

ai #machinelearning #showdev #qwen

Top comments (2)

Collapse
 
topstar_ai profile image
Luis

I found the concept of a "forgetting-aware memory engine" in Engram to be particularly intriguing, as it highlights the importance of timely forgetting in AI systems. The idea of using superseded_by links to exclude contradicted facts from recall while keeping them in an audit trail is a great approach to balancing memory and forgetting. The FAMA benchmark results are also impressive, showing that Engram's forgetting mechanism can achieve 100% recall of still-true facts while reducing context tokens by 1.72×. I'm curious to know more about how the qwen-vl-max model is used in the critique phase and how its output is integrated with the memory engine to inform the coaching plan.

Collapse
 
xm_dev_2026 profile image
Xiao Man

The supersession pattern is the part that deserves more attention. Most memory layers treat forgetting as deletion — but deletion without audit trail is data loss, and data loss makes the system untrustworthy. Keeping a superseded_by chain is the right call because it makes forgetting inspectable.

The FAMA result is clean: recency-only ties with never-forgets at 0.64 because recency cannot detect invalidation. That is exactly the failure mode — the newer fact does not just add to the context, it contradicts the older one. Knowing which facts are stale is a different capability than knowing which facts are recent.

One question on the graduation mechanic: when a skill graduates after three consecutive strong sessions, what happens if the photographer regresses? Is there a re-activation path, or does graduation assume monotonic improvement? The non-monotonic case is where memory systems tend to break down — the user improves, regresses, then the coach is still celebrating an old milestone.