TL;DR
Think about how differently you take notes for a legal case versus memorizing how to navigate a new kitchen—one requires structured tables of statutes, while the other needs quick, step-by-step spatial routines. Large Language Model (LLM) agents face the exact same dilemma, yet we usually force them to use a single, one-size-fits-all memory system across every job. This paper introduces M$\star$ (MSTAR), an evolutionary system that writes custom, task-specific Python "memory programs" from scratch, proving that letting an AI invent its own bespoke memory architecture dramatically boosts performance.
What Problem Does This Paper Address?
To learn from past experiences, LLM agents rely on a memory harness—the surrounding scaffolding that decides what information to write down, how to organize it, and when to retrieve it.
Historically, engineers hand-craft generalist memory harnesses (like standard vector databases for semantic search) and hope they work everywhere. They don't. A conversational agent needs a web of people, preferences, and timelines; a household robot needs reusable action sequences; a medical or legal assistant needs strict, verifiable checklists and statutory databases. Because every domain encodes fundamentally different assumptions about what matters, a memory harness built for chatting transfers poorly to embodied planning or expert reasoning. Rather than searching for one mythical "universal memory," the authors ask: how can we automatically discover the best custom memory harness for any given task?
Methods
MSTAR reframes memory design as an evolutionary search over executable Python code. Every candidate memory harness is packaged as a unified Python module containing three jointly optimized parts:
- Schema: Python
dataclassdefinitions dictating the exact structure of stored items and search queries. - Logic: Backend
read()andwrite()methods with access to a whitelisted toolkit (SQLite relational tables, ChromaDB vector search, Python data structures, and secondary LLM calls). - Instruction: Prompt strings telling the task agent how to extract memories, phrase queries, and interpret retrieved results.
While recent work like MemEvolve also treats memory as evolvable code to find a single cross-task generalist, MSTAR optimizes all three components jointly to build task-specialized harnesses. Starting from simple seed programs, MSTAR runs a 20-iteration loop:
- Population Search: Rather than mutating a single program (which easily gets stuck in local optima), MSTAR maintains a pool of candidates and samples parents via a softmax distribution—favoring high scorers while keeping underdogs alive for diversity.
- Dual-Split Evaluation: Candidates are scored on a static validation set to track progress, while execution traces and failures on a rotating mini-batch are handed off for debugging.
- Reflective Code Evolution & Quality Checks: A coding agent (GPT-5.3-Codex) acts as a "reflector," diagnosing failure traces to patch the code and prompts. New child programs must pass syntax checks, a read/write smoke test, and strict runtime limits (≤60 seconds, ≤3000 characters output), with up to 3 automated LLM repair attempts before entering the pool.
Datasets
No new benchmarks are introduced; MSTAR is evaluated across four existing benchmark families spanning seven domain configurations:
- LoCoMo: Long-term multi-session conversational question answering.
- ALFWorld (Seen & Unseen splits): Interactive text-based household task completion (embodied planning).
- HealthBench (Data & Emergency splits): Rubric-graded medical reasoning and clinical QA.
- PRBench (Legal & Finance splits): Rubric-graded professional reasoning.
Key Insights and Ideas
- Convergent evolution doesn't happen here—tasks demand radically different brains: When projected into an embedding space, the winning programs land in completely different architectural neighborhoods. For ALFWorld, MSTAR evolved a compact SQLite action cache with mismatch penalties and execution checklists. For LoCoMo, it built a hybrid ChromaDB semantic search paired with SQLite lexical/metadata scoring.
- Cross-task transfer actively hurts: Taking a champion memory program from one domain and dropping it into another isn't just suboptimal—in 5 out of 6 cross-task tests, transferred programs scored worse than a basic, unoptimized vector-search seed. Specialization isn't a quirk; it's the whole point.
- Prompts and code need to co-evolve: Freezing the Python code and only evolving prompts on LoCoMo caused token F1 to plummet by 0.203. Freezing the prompts and only evolving code dropped F1 by 0.106. Teaching the database how to store data only works if you simultaneously teach the agent how to ask for it.
Key Results
Using GPT-5.4 Mini as the task agent across 20 evolution rounds, MSTAR beat 10 baselines (spanning retrieval systems like Mem0, prompt optimizers like GEPA, and code-evolver MemEvolve) on 7 out of 8 metrics, with relative gains of up to 31% over the strongest baseline on each task:
- LoCoMo: Achieved 0.459 token F1 (vs. Mem0 at 0.373) and 0.610 LLM-judge score.
- ALFWorld: Hit 0.881 success rate on Unseen environments (vs. GEPA at 0.857), raising the worst-performing task category floor to 0.75. ( trailed GEPA+Vector Search on Seen: 0.700 vs. 0.820).
- HealthBench: Scored 0.390 on Data (vs. 0.327 best baseline) and 0.493 on Emergency.
- PRBench: Reached 0.660 on Legal (vs. GEPA's 0.568) and 0.586 on Finance (vs. GEPA's 0.449).
- Stability: Across 15 independent runs (5 random seeds × 3 benchmarks), 14 beat the strongest fixed baseline, with a coefficient of variation ≤10%.
Limitations and Future Work
- Reward hacking & overfitting: Evolution exploits whatever raises the validation score. Because HealthBench and PRBench LLM judges favor verbose answers, evolved prompts explicitly tell the agent to write long responses. Evolution also occasionally hard-codes dataset-specific string literals (especially on PRBench-Legal), hurting generality.
- Expensive search: Because every mutated program requires re-ingesting past episodes from scratch, a 20-iteration run costs up to $90 on rubric-graded tasks and up to 100 wall-clock hours on ALFWorld.
- Uneven category gains & model scope: Aggregate optimization can leave rarer query types behind (e.g., temporal questions in LoCoMo lagged baselines), specialized domain systems like LightMem still score higher on LoCoMo, and evolution was only tested with a single reflector model (GPT-5.3-Codex).
- Future directions: Warm-starting evolution using harnesses from related tasks to slash compute costs, testing resilience against noisy or contradictory memories, and designing search objectives that penalize brittle, benchmark-specific heuristics.
Summary updated