v3/docs/adr/ADR-358-automem-memory-rl-training-loop.md
Status: Proposed Date: 2026-07-03 Authors: claude (dream-cycle agent, 2026-07-03) Source: Dream Cycle research — Issue #[TBD], arXiv 2607.01224 (AutoMem) Tracking: [Dream Cycle 2026-07-03] memory deep-dive
AutoMem (Wu et al., arXiv 2607.01224, July 1 2026) demonstrates that memory management is an independently learnable RL skill: treating memory operations (store, retrieve, update, summarize, discard) as first-class RL actions and training a dedicated memory-specialist agent from its own episode traces yields 2x–4x improvement on long-horizon tasks (Crafter, MiniHack, NetHack), bringing a 32B open-weight model to frontier-competitive performance without changing the task policy at all.
Ruflo's AgentDB currently provides:
consolidate background worker (heuristic scheduling, no trajectory feedback)None of these train the management strategy itself — which facts to store, when to discard, how to structure retrieval keys. SONA adapts weights; it does not optimize the memory scaffold or proficiency. The consolidate worker fires on a timer, not on outcome signals.
This is the single highest-leverage unimplemented memory optimization identified in the July 2026 SOTA sweep.
Add an AutoMem-compatible two-phase RL training loop to AgentDB:
memory-scaffold-optimizer)A meta-LLM loop that iteratively refines how AgentDB is used:
hooks_post-taskscaffold-vN in the memory-config namespacenpx ruflo memory optimize-scaffoldhooks_intelligence_trajectory-start/-step/-end pipeline (ADR-074)memory-specialist agent)A dedicated background agent trained from successful episodes:
+1 per retrieved fact that contributed to success, -1 per write that went unretrieved or preceded failurememory-specialist LoRA adapter (reusing existing ContrastiveTrainer from ADR-086)npx ruflo memory proficiency-statusPer AgenticSTS (arXiv Jul 2 2026): add a MemoryContract option to AgentDB that enforces typed retrieval (semantic_search, key_lookup) as the only access path, blocking raw transcript appending beyond a configurable token budget (default: 2048 tokens/session). This prevents ghost-memory accumulation (A-TMA finding) and bounds context growth.
| Component | Change | Risk |
|---|---|---|
@claude-flow/memory | Add scaffold-optimizer.ts + proficiency-trainer.ts | Medium |
@claude-flow/hooks | Wire post-task hook to emit trajectory reward signal | Low |
@claude-flow/cli | Add memory optimize-scaffold, memory proficiency-status subcommands | Low |
| AgentDB | Add scaffold-vN namespace, reward-signal schema | Low |
ContrastiveTrainer (ADR-086) | Extend to accept memory-op triplets | Low |
Files to keep under 500 lines each. No changes to task-policy paths.
Positive:
@claude-flow/performance benchmark --suite memory-long-horizon before/afterNegative / Risks:
Not in scope:
consolidate worker scheduling. Rejected: doesn't learn from outcomes, still heuristic.hooks_intelligence_trajectory-start/-step/-end)ContrastiveTrainer)