Inspiration

AI coding agents reason from stale training knowledge and don't web-search by default, so they keep using removed or outdated library APIs — from pydantic import BaseSettings, openai.ChatCompletion.create(), a sync Session with async SQLAlchemy. The decisive pain isn't the first mistake. It's that after you correct it once, the next session — or a different tool — has no idea. You fall into the same trap forever.

What it does

A local, host-agnostic memory daemon that, with no manual action from the agent:

  1. Harvests library/API mistakes from a session at compaction time — the one lifecycle event every coding agent supports.
  2. Verifies the fix against the actually-installed package on disk (version-exact, no hallucination), falling back to web search only when the package isn't found.
  3. Stores a scored Lesson in a shared root memory.
  4. Auto-injects the relevant fix into any future session of any tool — once per session.
  5. Self-corrects: outcomes update a confidence score, so wrong lessons demote and are forgotten while good ones rise.

The result is a memory that gets increasingly accurate with use — exactly Track 1's goal.

How we built it

  • Daemon: FastAPI on 127.0.0.1:8787; root memory in SQLite + FTS5 (keyword recall at zero embedding cost), with scored ranking on top.
  • Integration: Claude Code lifecycle hooks (SessionStart / UserPromptSubmit / PreCompact / SessionEnd) through a thin, fail-safe adapter — the host LLM never calls a tool, so injection is automatic and invisible.
  • Qwen Cloud (Alibaba Cloud) is the brain: qwen-turbo extracts mistake candidates, qwen-plus (with enable_search) synthesizes the verified fix, qwen3-rerank ranks recall. OpenAI-compatible via DashScope — provider-pluggable, Qwen by default. Code: qmem/llm/provider.py.
  • Verifier: reads the installed package's version + docs from node_modules / site-packages (project-local and global, resolved dynamically per machine) so corrections are grounded in the exact installed version.
  • Reflect: score = confidence × recency_decay × (success+1)/(success+fail+2) (Beta smoothing, so new lessons start neutral and move both ways).
  • Built test-first (53 tests), packaged to PyPI (qwen-memory-agent), one-command install, CI publishing via GitHub Actions OIDC Trusted Publishing.

Challenges we ran into

  • Making injection host-invisible → solved with lifecycle hooks + additionalContext, not MCP tool calls.
  • Trusting a correction → read the installed package instead of trusting the LLM's memory; Reflect demotes wrong ones.
  • Real-LLM robustness → real Qwen wraps JSON in code fences; we slice the array out before parsing.
  • Machine-agnostic package resolution → ask npm for its own global root (PATH-augmented so it works under a daemon's stripped environment), not hardcoded paths.

Accomplishments that we're proud of

A memory that is version-exact (proven live: generated openai==2.44.0 and pydantic==2.13.4 fixes from the actually-installed versions) and self-correcting — beyond the "store & replay" of existing tools. End-to-end working, one-command install, published on PyPI, 53 tests green.

What we learned

The honest weak link is outcome attribution — success/fail is correlation, not causation. It converges with volume; the installed-package verification is what makes stored knowledge trustworthy in the meantime.

What's next for Qwen MemoryAgent — self-correcting memory for coding agents

A multi-platform auto-detecting installer (Codex / Gemini CLI / Cursor adapters across the hook / MCP / rules tiers), confidence-driven promotion into an always-injected curated layer, and broader package-ecosystem coverage (global pip, pnpm/yarn, Windows).

Built With

  • dashscope
  • fastapi
  • fts5
  • openai-sdk
  • pytest
  • python
  • qwen
  • qwen-plus
  • qwen-turbo
  • qwen3-rerank
  • sqlite
Share this project:

Updates

Submission history