Inspiration
DiversiFi is an autonomous treasury agent that protects people who earn in one currency and must hold or spend in another — a Ghanaian importer paying USD invoices, a Nigerian diaspora member whose family savings sit in naira, a UK business settling Eurozone supplier bills. An agent like that runs for months across thousands of sessions, and it has a memory problem that nobody talks about in fintech demos: every conversation, every market signal, every user preference piles into context until either the token bill explodes or the model forgets the thing that actually mattered.
Track 1 — efficient storage, timely forgetting, recalling critical memories within limited context — is literally the problem we had to solve to ship our own agent. We were running Cognee locally and hitting the wall the prompt describes. So we rebuilt the memory layer on Qwen Cloud + Alibaba Cloud Tablestore Agent Memory, with Qwen long-context models doing the consolidation.
What it does
DiversiFi is a risk-aware, values-driven treasury agent with a three-stage memory pipeline:
Store — Every user interaction and Guardian market observation is written to Tablestore Agent Memory (
addMemories) with automatic long-term extraction, scoped by app/tenant/agent/session. Vector search (searchMemories) handles semantic recall across sessions.Forget — Soft decay penalizes recall score for memories older than a 30-day TTL, reaching zero at 2×TTL; a
sweepStaleMemoriesjob hard-evicts anything below threshold viadeleteMemory. After consolidation, absorbed raw memories are evicted so the store doesn't grow unbounded.Recall within limited context — Qwen long-context models (
qwen-long, 1M-token window) consolidate up to 40 raw memories into 3–7 distilled profile statements, stored back as a high-priorityconsolidated_profilememory. The advisor's context window then sees durable signals, not ephemeral chatter.
The agent itself routes capital between Celo (regional stablecoin savings), Arbitrum (RWA yield), and 0G (verifiable evidence), recording every decision on-chain. The memory layer is what makes it improve over sessions instead of resetting each time.
How we built it
- Qwen Cloud (DashScope / Bailian) —
dashscope-provider.tscalls the OpenAI-compatible endpoint;qwen-plusfor default consolidation,qwen-longfor large memory pools,qwen-maxfor highest-quality distillation. Plugged into our multi-provider AIService failover chain. - Alibaba Cloud Tablestore Agent Memory —
tablestore-memory-service.tsimplementssearchMemories,addMemories,deleteMemory, andlistMemoriesover the HTTP JSON protocol. Instancediversifi-memoryincn-beijing, CU mode, ZRS. - Alibaba Cloud Function Compute —
alibaba-cloud/fc-memory-consolidation/index.jsis a Node.js 18 HTTP-triggered function that runs the full consolidation pipeline on Alibaba infrastructure: search → Qwen consolidate → addMemories → deleteMemory. - Orchestration —
memory-consolidation-service.tsdelegates to Function Compute whenALIBABA_CLOUD_FC_ENDPOINTis set, falling back to local Tablestore/Cognee otherwise. The Guardian cron on Hetzner triggers consolidation per active user every ~6 hours. - Frontend — Next.js app; the AI chat drawer is the agent's front door, with real SSE streaming from Qwen.
Proof of Alibaba Cloud Deployment: alibaba-cloud/fc-memory-consolidation/index.js (Function Compute + Tablestore + DashScope, all three in one handler). Full runbook in docs/alibaba-cloud-deployment.md.
Challenges we ran into
- Tablestore Memory Storage is invitation-only beta. The Memory Storage sub-service returns
OTSAuthFailed: The user is disabledeven with the root AccessKey — it's an account-level allowlist gate, not a permissions issue. Activation requires joining the Tablestore DingTalk group (36165029092). We built the complete adapter and Function Compute handler anyway, with a Cognee fallback that provides identical semantics so the app ships today and upgrades to Tablestore the moment the account is allowlisted. DashScope (Qwen) and the Tablestore instance itself are both live and verified. - Context window discipline. Consolidating 40 raw memories into 3–7 statements without losing durable signals (user currency, risk tolerance, philosophy archetype) took several iterations on the Qwen prompt — the model wanted to summarize rather than distill.
- Forgetting without amnesia. Naive TTL deletion erased long-term user preferences. We split soft decay (score penalty) from hard eviction (threshold sweep) so a six-month-old "user is Muslim, avoid interest-bearing yield" survives while a six-week-old "USDC depegged 0.3% yesterday" does not.
- Cross-region latency. Tablestore Memory Storage is only available in
cn-beijing; our Guardian cron runs on Hetzner. We co-located Function Compute incn-beijingand delegated over HTTP instead of calling Tablestore directly from Europe.
Accomplishments that we're proud of
- Real Qwen API calls verified against the DashScope MaaS endpoint with valid end-to-end consolidation output.
- Three-stage memory pipeline (store → forget → recall) mapped directly onto the three Track 1 requirements instead of being bolted on afterward.
- 880 tests passing, including dedicated suites for the Tablestore adapter, memory consolidation, and Cognee decay.
- Production-grade optionality — every Alibaba Cloud service is behind environment variables; the application works with zero Alibaba configuration and accelerates when configured.
- The agent this memory serves is real: RecommendationLedger deployed on Arbitrum, Celo, and 0G; ERC-8004 agent identity minted on Celo; Guardian cron running on Hetzner.
What we learned
- Memory is the moat, not the model. A cheaper model with good memory beats a frontier model that resets every session. For a long-running financial agent, the distilled profile is more valuable than raw reasoning.
- Forgetting is harder than remembering. The key design question isn't "what do we keep?" but "what do we evict, when, without losing identity-level preferences?"
- Beta-gated cloud services are a deployment risk. Building a fallback that preserves semantics taught us to architect against interfaces rather than implementations — swapping Cognee for Tablestore behind the same contract.
- Qwen long-context is genuinely useful for consolidation. A 1M-token context lets us feed the full raw memory pool in a single call and receive a clean distilled profile without chunking.
What's next
- Get the Tablestore Memory Storage account allowlisted and flip the environment variable — the adapter is complete, and this is the only blocker to a pure Alibaba memory stack.
- Add per-philosophy memory profiles — consolidate differently for Islamic Finance users (Sharia constraints never decay) versus Buen Vivir users (community-weighted signals).
- Build memory-aware proactive nudges — the Guardian should surface insights like "last time the cedi dropped 5%, you moved to cUSD; a similar pattern is forming now" using recalled history rather than only current prices.
- Open-source the memory layer as a standalone package — the store / forget / recall contract is general enough to support any long-running Qwen agent, not just DiversiFi.
Built With
- celo
- next
- qwen
- react
Log in or sign up for Devpost to join the conversation.