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.