arXiv:2610.38332cs.LGOct 2026

Manuscript Offprint

arXiv:2610.38332

MUSE: Multi-Level Memory with Selective Runtime Injection for Scientific Coding Agents

Haoran Jin, Defu Lian, Xiting Wang, Hong Xie

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

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.

1 Introduction

Scientific coding agents translate mathematical models and research objectives into executable software (Tian et al., 2024; Xu et al., 2026). They tackle tasks such as building numerical solvers, optimizing computational kernels, and repairing scientific repositories (Hang et al., 2026; Ouyang et al., 2025). Through reasoning and tool use, agents inspect code, execute commands, and revise implementations over multiple steps (Yao et al., 2023; Yang et al., 2024). Success requires coordinating these operations with scientific requirements for accuracy, correctness, and performance.

Memory allows agents to draw on previous attempts when solving new problems (Ouyang et al., 2026; Tang et al., 2025). Scientific systems preserve reusable knowledge and project artifacts across research stages (Qian et al., 2026; Lyu et al., 2026). Stored strategies and procedures guide agents beyond the current interaction history (Ouyang et al., 2026; Cao et al., 2026). Both successful and failed attempts can contribute reusable methods and warnings about common mistakes (Zhang et al., 2026a; Tang et al., 2025). Supplying this experience through context allows an existing agent to use new guidance without updating its model weights (Zhang et al., 2026c). For scientific coding, memory can preserve the reasoning behind an overall approach together with the practical knowledge needed to implement it.

However, applying memory to scientific coding presents two problems. First, many memory structures do not explicitly match the levels of experience that scientific coding requires. Agent KB separates planning guidance from execution-level feedback (Tang et al., 2025), while AutoSci distinguishes reusable knowledge from project-specific material (Qian et al., 2026). These divisions serve general problem solving or full research workflows and do not directly distinguish shared scientific checks, problem-specific approaches, and local implementation experience. Second, many methods lack targeted guidance for implementation pitfalls that emerge as scientific coding progresses. A useful warning may come from a historical problem whose relevance is not apparent from the task description alone. In general agent memory research, TRAD and AdaMEM retrieve experience from local thoughts or states (Zhou et al., 2024; Zhang et al., 2026c), while AutoGuide and proactive memory systems select contextual guidance or decide when to provide reminders (Fu et al., 2024; Cai et al., 2026; Wu et al., 2026). Adapting these ideas to scientific

Preprint. Under review.

MethodSuccess & Failure Exp.Multi-Level MemorySelective 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)✓○○
TRAD (Zhou et al., 2024)-✓○
ACE (Zhang et al., 2026a)✓○-
Agent KB (Tang et al., 2025)✓✓-
MUSE (ours)✓✓✓

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.

coding requires queries and memory keys that match specific code operations, implementation choices, and errors rather than broad task context.

To address these problems, we introduce MUSE, Multi-Level Memory with Selective Runtime Injection for Scientific Coding Agents, a memory management framework for scientific coding agents (Figure 1). It extracts approach-level and implementation-level lessons from source attempts and consolidates them into a shared global bank. At initialization, the agent receives the complete global bank and problem-matched approaches. During scientific coding, retrieval finds implementation experience relevant to the current interaction. An LLM gate evaluates this experience against the task and visible execution history, then injects selected experience together with specific review advice, or withholds injection. This design connects overall solution guidance with targeted implementation checks.

Across four benchmarks covering numerical solving, kernel optimization, and scientific software repair, MUSE has the highest scores on all six metrics. Multi-level ablations show gains as memory levels are added, while gate ablations favor selective injection with review advice over direct similarity-based injection. Memory built from source tasks in one kernel benchmark also retains gains in correctness and acceleration rates over the memory-free agent on another. Our contributions are as follows.

  • We propose MUSE, a memory management framework for scientific coding agents that extracts reusable lessons from historical experience.

  • We combine global, approach-level, and implementation-level memory with selective runtime injection to connect overall solution guidance with targeted implementation checks.

  • Experiments on four benchmarks spanning numerical solving, kernel optimization, and scientific software repair show higher scores than the evaluated retrieval and memory methods. Memory built on one kernel benchmark retains its advantage over the memory-free agent on another within the same domain.