Inspiration

Most AI assistants have amnesia. Every session starts from zero, or they cram the entire chat history back into the prompt until it overflows. We wanted an agent that remembers like a person: it holds onto what matters, quietly lets small talk fade, and never loses your core facts — with that memory living locally, under your control.

What it does

Aegis gives any LLM a durable, salience-weighted memory, separated into three kinds:

  • Facts — durable, never decay ("I run Northwind Labs").
  • Preferences — last-write-wins ("call me Ben, never Commander").
  • Episodes — timestamped, decay over time, pruned below a salience floor.

Recall is budgeted by tokens, not row count. Candidates are ranked by a weighted salience score:

$$\text{salience} = 0.65 \cdot \text{similarity} + 0.20 \cdot \text{recency} + 0.15 \cdot \text{importance}$$

and packed highest-first until the budget is spent. So a brand-new process, started cold over the same on-disk memory store with no chat-history replay, instantly recalls your company and how you like to be addressed — because those facts win the budget, not the last thing you said.

How we built it

100% on Qwen Cloud via Model Studio / DashScope's OpenAI-compatible endpoint (dashscope-intl.aliyuncs.com/compatible-mode/v1): qwen-plus / qwen3.7-plus for chat, text-embedding-v4 for retrieval. Because it speaks the OpenAI protocol, we skipped the SDK entirely. The client is stdlib urllib, the deploy container is tiny, and cold-starts fast.

A dependency-light Python core (runtime is stdlib-only) with a FastAPI service variant. Everything except the two network calls (qwen.embed, qwen.chat) is pure local logic, which lets us test the entire memory engine — salience scoring, budget packing, decay, pruning, last-write-wins, consent/safety — with 124 keyless pytest cases in ~1 second, no API key required.

Deployed and proven on Alibaba Cloud ECS (Ubuntu): the cross-session demo runs end-to-end from the cloud, not just against the API from a laptop.

Challenges we ran into

Getting forgetting right was the hard part, and the build hit real bugs along the way — every one is now pinned by a targeted test:

  • A forget() pass that decayed but never pruned — salience dropped correctly; memories never left the store.
  • A crash that could corrupt the whole store if a process was killed mid-flush (fixed with atomic write-and-rename + tolerant load that drops schema-incomplete records).
  • An unbounded importance value and a falsy-zero recall budget that quietly corrupted ranking — clamped and guarded at every boundary.
  • A username that could escape its per-user memory folder via path traversal.
  • A fuzz-found UTF-8 crash on invalid bytes in the store load path.

And the biggest non-code challenge: proving real deployment — standing the agent up on an ECS instance and running the cross-session demo live from the cloud, not just calling the API from our laptop.

What we learned

Memory is a ranking problem, not a storage problem. The hard part is deciding what to keep and surface. We measured this directly: on 8 probe queries under the same token budget, *naive most-recent recall scored 0/8; the salience budget scored 8/8. That gap *is the project.

Qwen Cloud's OpenAI-compatible endpoint made the model + embedding layer a clean drop-in, so we could focus entirely on the memory engine instead of gluing SDKs together.

What's next

  • Compaction over pure pruning — distill an episode into a durable fact before forgetting it, so the lesson survives even after the raw memory is pruned.
  • ANN vector index past tens of thousands of memories (current linear scan is fine for demo scale but won't hold at real scale).
  • Ship Aegis as a local-first operator with its own persistent memory — the memory engine becomes the substrate for a resident AI, not just a hackathon submission.

Built With

  • alibaba-cloud
  • alibaba-model-studio
  • dashscope
  • ecs
  • fastapi
  • git
  • github
  • openai-compatible-api
  • pytest
  • python
  • qwen-cloud
  • qwen-embedding
  • qwen-plus
  • qwen3.7-plus
  • text-embedding-v4
  • ubuntu
  • uvicorn
Share this project:

Updates