MUSE: Multi-Level Memory with Selective Runtime Injection for Scientific Coding Agents
Authors: Haoran Jin, Defu Lian, Xiting Wang, Hong Xie
Organizations: University of Science and Technology of China · State Key Laboratory of Cognitive Intelligence, Hefei, Anhui, China · Gaoling School of Artificial Intelligence, Renmin University of China
Historical experience can guide scientific coding at multiple levels, but task-level retrieval may miss implementation lessons that become relevant during execution. We introduce MUSE, a memory management framework combining multi-level memory with selective runtime injection for scientific coding agents. MUSE builds global, approach-level, and implementation-level memory from historical trajectories. At initialization, the agent receives global memory and problem-matched approach-level memory. During execution, current interactions are used to retrieve implementation-level memory. An LLM gate selects relevant experience and generates specific review advice, or skips injection. Across four benchmarks spanning numerical problem solving, kernel optimization, and scientific software repair, MUSE outperforms retrieval and memory baselines on all evaluation metrics. Ablations support the multi-level design and gated injection, while transfer experiments show that memory remains useful across kernel benchmarks. These results show that multi-level memory and selective runtime injection enable effective reuse of experience in scientific coding. Code is available at https://github.com/hr-jin/MUSE.
Figures & tables
Method
Success & Failure Exp.
Multi-Level Memory
Selective Runtime Injection
Trajectory RAG (control)
✓
–
–
ReasoningBank ( Ouyang et al., 2026 )
✓
–
–
ReMe ( Cao et al., 2026 )
✓
◯
◯
AutoSci–SciMem ( Qian et al., 2026 )
✓
◯
–
AdaMEM ( Zhang et al., 2026c )
–
◯
✓
EvoScientist ( Lyu et al., 2026 )
✓
◯
◯
Table 1: Comparison of memory mechanisms. Symbols denote full ( ✓ ), partial or project-local ( ∘ ), and no explicit (–) support in the compared configurations. Multi-level memory separates approaches from implementation details. Selective runtime injection can skip injection within a trajectory.
Figure 1: Memory construction and injection in MUSE . (a) Approach-level (L1) and implementation-level (L2) lessons are extracted from historical trajectories. Consolidation and review build global memory (L0). (b) The agent receives L0 and problem-matched L1 references at initialization. During scientific coding, the LLM gate selects a retrieved source record and provides specific review advice, or skips injection.
Benchmark
Extract
Test
PDEAgent-Bench
194
451
KernelBenchX
53
122
KernelGenBench-MS
63
140
SWE-bench Science
35
84
Table 2: Task counts for memory extraction and testing.
PDE
KBX
KGB
SWE Science
Method
Pass %
Correct %
Accel. %
Correct %
Accel. %
Pass %
Vanilla agent
44.8
57.4
31.1
44.3
8.6
29.8
RAG
72.3
53.3
29.5
57.9
12.1
28.6
ReasoningBank
63.6
59.8
28.7
47.9
15.7
31.0
ReMe
50.1
50.0
29.5
40.0
20.0
35.7
TRAD
75.8
60.7
29.5
48.6
9.3
31.0
Table 3: Results on four scientific coding benchmarks. Bold and underlined values mark the best and second-best scores in each column. Accel. denotes the percentage of test tasks passing correctness checks with a speedup of at least 1.01× over the benchmark reference.
Method
Pass %
Vanilla agent
44.8
Agent KB
69.6
AutoSci–SciMem
78.5
ACE
83.8
EvoScientist
87.8
MUSE L0 only
82.7
Table 4: Cumulative memory-level ablation on PDE. The strongest baseline is underlined.
Pass/Correct %
Accel. %
Benchmark
MUSE
w/o gate
MUSE
w/o gate
PDE
92.2
90.7
–
–
KBX
79.5
66.4
44.3
37.7
KGB
66.4
62.1
24.3
20.0
SWE Science
40.5
32.1
–
–
Table 6: Gate ablation across four benchmarks. The no-gate variant retains all three memory levels and retrieval rules, but directly injects the highest-similarity eligible source record. Pass/Correct denotes pass rate for PDE and SWE Science and correctness rate for KBX and KGB.
Figure 2: Memory use in three kernel tasks. Global memory (L0) supplies a precision rule, approach-level memory (L1) an FP8 encoding approach, and implementation-level memory (L2) a two-pass variance implementation. Speedups are relative to the corresponding benchmark reference implementations.
Large language model (LLM) agents now autonomously complete long-horizon tasks, such as repository-level coding, through hundreds of think-act steps, yet the experience each run produces is rarely reused on the next. Prior memory systems concentrate on retrieval, finding the most relevant past trajectory. Retrieval cannot observe the running agent, so it cannot decide whether the agent needs an experience, at which point, or for how long. We introduce REM (Reusable Experience Memory), a framework that manages the memory lifecycle from inside the agent's think-act loop through three explicit decisions. What to store: each completed trajectory is consolidated into a phase-structured document, two orders of magnitude smaller than the trajectory. When to recall: the document is injected at the start of the task; the costlier implementation record is withheld until an in-loop gate detects the agent struggling. What to forget: the record is evicted after a single exposure. On repository-level bug fixing (SWE-ContextBench Lite), REM retrieves the related trajectory more accurately than every state-of-the-art memory system (68.7% vs. 55.6% match@1) and improves, in every replicate, end-task resolution (27.6% vs. 24.9%) at 17% lower cost. Injecting the same experience as a summary or raw trajectory, even when oracle-retrieved, does not. Ablating any of the three decisions reduces resolution. Altogether, these results demonstrate that the bottleneck in experience reuse is not retrieval fidelity but how experience is stored and governed across its lifecycle, opening a control-theoretic perspective on agent memory.
Xinyi Lisa Chen, Pedro Herrero-Vidal, Xiaohan Chen +6
Scientific code repositories encode decades of human knowledge in executable models, methods, and tools. Yet fragmented toolchains, implicit domain conventions, and specialized correctness criteria make this knowledge difficult to convert into reliable learning experience-a challenge we call the scientific experience bottleneck. We introduce ScienceIDE, infrastructure for turning the world's scientific code into programmable environments for scientific agents. Guided by expert-defined scientific cases and acceptance criteria, agents transform repositories into executable environments that support task generation, execution, and scientific verification. These environments provide a shared foundation for supervised fine-tuning, reinforcement learning, and evaluation. Using verified interaction trajectories, we train PhAI-IDE-72B, PhAI-IDE-9B, and PhAI-IDE-4B. The model family shows gains in held-out scientific-code repair and across selected general-purpose benchmarks in code, reasoning, and knowledge, providing evidence of positive transfer from scientific experience to broader capabilities. ScienceIDE lays the foundation for an integrated workspace for agent learning and scientific practice, making humanity's scientific software a shared substrate for developing scientific intelligence. Code: https://github.com/aitofound/ScienceIDE
Coding agents operate on real repository coding tasks, and persistent memory systems promise to reuse experience across tasks. Yet existing evaluations do not show whether those systems improve executable repository work. Repository benchmarks test code changes but do not isolate memory, while memory benchmarks score recall without measuring downstream coding outcomes. We introduce VibeMemBench, a benchmark for evaluating memory systems on 111 coding targets from 90 SWE-rebench V2 repositories and 3,634 history trajectories from the target repositories. The targets follow the SWE benchmark style and cover bug fixes, feature requests, interface changes, and configuration work. An agent edits each target codebase under a declared memory condition. Executable tests decide task resolution. Each target is retained only when injected history experience improves its executable outcome in a reference setting, so every target carries a prior experience whose usefulness is verified by execution in that setting. The frozen verified experience is then transferred to five held-out solvers. Direct injection raises observed task resolution on four of them by 1.1 to 4.5 percentage points while lowering agent steps on all five. Yet when four existing memory systems must construct and retrieve experience from the same history, eleven of twelve solver and system pairings fail to exceed the matched memory-off baseline. VibeMemBench exposes the gap between the useful experience that repository history holds and the experience existing memory systems deliver for repository coding tasks.
Liyang Fan, Yingcheng Shi, Yongbin Li +7
Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences · SUAT · Alibaba Token Hub, Alibaba Group +1