DEV Community

Diego RV
Diego RV

Posted on

Shipping a MemoryAgent on Qwen in a weekend: build notes

Hilo — the agent you never re-explain your project to.

Every AI chat starts with amnesia. Use an assistant across a multi-day project and you pay a re-explanation tax at the start of every session: pasting context, restating decisions, re-answering questions you already answered. For the Global AI Hackathon with Qwen Cloud (Track 1: MemoryAgent), I built the smallest agent that removes that tax entirely.

The design bet: one loop, one file of memory

Hilo is deliberately tiny: a session loop (agent.py) and a memory engine (memory.py). Brief it once. When you leave — /quit, or even Ctrl+C — one extra Qwen call distills the whole transcript into structured memory:

{
  "facts": ["Hilo is a memory agent for the Qwen Cloud hackathon, Track 1 MemoryAgent."],
  "preferences": [],
  "open_threads": ["Which Qwen model gives the fastest demo latency?"],
  "session_count": 1
}
Enter fullscreen mode Exit fullscreen mode

The next session injects that block — not the transcripts — and opens with "Welcome back — session 2. Where we left off: …".

The track asks for three things, and each maps to one design decision. Efficient memory storage and retrieval: distillation compresses a whole session into at most 40 structured items with a single call. Timely forgetting of outdated information: resolved threads are dropped at distill time, stale facts get rewritten instead of appended, and a hard 40-item cap prunes oldest-first. Recalling critical memories within limited context windows: session start costs hundreds of tokens of memory, never a context window of history.

Building on Qwen / Alibaba Cloud: what actually happened

The Beijing trap. Alibaba Cloud has two consoles. The Beijing one (bailian.console.*) demands Chinese real-name authentication and issues keys that don't work internationally. The Singapore console (modelstudio.console.alibabacloud.com/ap-southeast-1) with the dashscope-intl endpoint is the one international builders want. I lost a session to this; the fix is retyping the ap-southeast-1 URL.

OpenAI-compatible mode is real. The whole integration is the standard openai Python SDK pointed at https://dashscope-intl.aliyuncs.com/compatible-mode/v1. No custom SDK, no special cases. Distillation and chat both worked on the first green smoke test.

Model catalogs rotate. Hackathon guides age fast; the model name in a week-old tutorial may already be retired. I stopped hardcoding: my smoke test tries the configured model, then a fallback list, and prints the exact QWEN_MODEL= line to paste into .env. That turned a potential demo-day failure into a 10-second fix.

Memory must be unbreakable. A memory agent that can corrupt its memory is worse than no memory agent. Hilo writes atomically (temp file + rename), quarantines corrupt files instead of crashing, and treats a failed distillation as "memory unchanged", never "memory lost". The demo video deliberately kills a session mid-sentence with Ctrl+C — restart, and it still remembers.

Numbers

Code: ~400 lines total, two modules, zero frameworks. Cost: distillation is one extra call per session on qwen-turbo; the whole build ran on new-user free quota — effectively $0. Latency: the resume greeting is instant (computed locally, zero API calls at startup); distillation at quit takes a few seconds; the live smoke test answered in 1.1s from CI and 2.5s from a home connection in Chile.

What's next

Multi-project memory namespaces, semantic retrieval over long memories, and shared team memory — so a whole team never re-explains the project either.

Repo: github.com/phazon2/hilo

Built solo, on Qwen via Alibaba Cloud Model Studio, in a weekend.

Top comments (0)