WorksComputer Science
MUSE: Multi-Level Memory with Selective Runtime Injection for Scientific Coding Agents
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 at https://github.com/hr-jin/MUSE.
Introduction
Scientific coding agents translate mathematical models and research objectives into executable software [14, 20]. They tackle tasks such as building numerical solvers, optimizing computational kernels, and repairing scientific repositories [4, 6]. Through reasoning and tool use, agents inspect code, execute commands, and revise implementations over multiple steps [22, 21]. 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 [7, 13]. Scientific systems preserve reusable knowledge and project artifacts across research stages [11, 5]. Stored strategies and procedures guide agents beyond the current interaction history [7, 2]. Both successful and failed attempts can contribute reusable methods and warnings about common mistakes [26, 13]. Supplying this experience through context allows an existing agent to use new guidance without updating its model weights [28]. 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 [13], while AutoSci distinguishes reusable knowledge from project-specific material [11]. 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 [31, 28], while AutoGuide and proactive memory systems select contextual guidance or decide when to provide reminders [3, 1, 18]. Adapting these ideas to scientific 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.
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.
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.
Related Work
Agentic memory. Early agent memory retained observations and demonstrations, with reflection adding lessons from feedback [10, 30, 12]. As histories grow, memory tiers and linked notes organize information for later retrieval [9, 19]. Other work extracts reusable knowledge from these histories. Distillation methods preserve transferable principles [29, 7], while skill and workflow memories retain procedures for execution [15, 17]. ACE consolidates strategies and failure modes in a playbook [26], while Agent KB combines workflow guidance with execution-level lessons [13]. MUSE provides shared global lessons, problem-matched approaches, and implementation experience retrieved for the current interaction.
Scientific memory. Scientific memory supports reuse across research stages and scientific coding tasks. AutoSci’s SciMem preserves knowledge and project artifacts, while EvoScientist separates ideation and experimentation memories [11, 5]. Another line of work concentrates on reusable implementations. Library-development agents learn from verified demonstrations, and kernel-optimization systems reuse pairs of slow and fast kernels [24 b]. KLineage recovers optimization skills together with the conditions under which a transformation applies [27]. Our focus is reusing experience from completed scientific coding tasks to guide an existing agent on new problems.
Runtime memory injection. Runtime retrieval supplies experience relevant to the agent’s current context. TRAD retrieves thoughts and local actions, while AutoGuide selects guidelines for the current context [31, 3]. ReMe retrieves and adapts procedural experience [2], and AdaMEM synthesizes strategies from successful historical states with options to retain or refresh its guidance [28]. Retrieval can also be selective. ProactAgent learns when and what to retrieve [1]; Proactive Memory Agent uses recent trajectories to decide whether to inject a memory-based reminder [18]. Agent KB provides execution-level refinement after an initial attempt [13]. Our work combines multi-level memory with selective runtime injection for scientific coding agents. Table 1 compares MUSE with the memory baselines.
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.
MUSE
MUSE builds memory from completed scientific coding attempts and uses it at three levels. L0 denotes global memory shared across tasks, L1 denotes approach-level memory matched to the problem, and L2 denotes implementation-level memory matched to the current interaction. The agent receives L0 and L1 at initialization. During execution, an LLM gate decides whether retrieved experience supports a specific revision or additional check. Figure 1 summarizes this process.
Problem Formulation
A scientific coding task specifies a problem and implementation requirements. A tool-using agent reasons, acts, observes outputs, and submits a solution. MUSE supplies memory through the agent’s context while keeping its weights and tool interface unchanged.
We construct memory from frozen source attempts. Each attempt contains the source problem, visible interaction history, verbatim final submission, and feedback. Approach-level lessons describe overall solution approaches, such as a discretization scheme. Implementation-level lessons describe concrete choices within an approach, such as an interface or update order.
The three levels reflect the information needed to judge relevance. Shared checks concern requirements that recur across tasks while retaining conditions specifying when they apply. Approach lessons relate problem requirements to solution strategies. Implementation lessons concern local choices whose relevance may become apparent as concrete operations and tool interactions develop. A source can therefore offer a useful implementation check without guiding the overall solution, motivating runtime retrieval beyond the initial problem-matched references.
Memory Construction
Per-attempt extraction. An extraction agent reads each source attempt and produces an L1 lesson and L2 lessons , written as . L1 records the overall approach, essential knowledge, and reusable tools. L2 records implementation choices, their rationale, and their relation to the observed outcome. Extraction identifies why choices succeeded or failed and the conditions under which they apply. It separates observed results, conclusions derived from task requirements, and untested suggestions for alternative approaches.
Each lesson retains source material , where contains feedback outcomes, metrics, and diagnostics. The original history informs extraction, while accompanies retrieved lessons so the agent can inspect the implementation and its evaluation. The banks are
Both banks retain successful and failed attempts. Successful attempts provide approaches to reuse, while failures can identify pitfalls to check.
GlobalMemBank construction. GlobalMemBank forms L0 by consolidating per-attempt lessons into guidance shared across tasks. Unlike problem-matched references, it is provided in full to every target agent. Construction has two stages following per-attempt extraction.
First, a consolidation agent reads the current bank, newly extracted lessons, and their original source material. It adds, replaces, or retires entries while preserving the conditions, reasons, formulas, procedures, and short code snippets needed to use them. An entry may come from one source or combine sources whose conditions and operations are compatible. Unchanged entries remain intact, and revisions record their sources and reasons.
Second, a bank-wide review checks global entries against the source implementations, outcomes, and applicability conditions, resolving conflicts and correcting their explanations. The reviewer can revisit source attempts and revise global entries. These stages update L0 while preserving the accepted L1 and L2 lessons. We freeze the complete memory and its indexes before testing.
Memory Initialization
The agent first receives the complete L0 text, followed by L1 references selected by problem similarity. Each L1 retrieval key contains the source problem with shared environment instructions removed. Let be the unit-normalized embedding of text . With returning the indices of the highest-scoring references, we retrieve
We use . Each reference supplies its approach lesson and source material . Let contain their source problem IDs. Excluding from all runtime indexes makes later retrieval search beyond the references already supplied at initialization.
Selective Runtime Injection
Runtime retrieval follows the return of designated tools, such as Write and Bash. It uses the current interaction , consisting of the assistant message body, tool arguments, and tool return. These fields describe the intended operation, its concrete implementation, and its observed result. Each L2 retrieval key contains only the implementation description and the recorded choice and rationale. Historical submissions and errors are indexed separately in and . Four routes each retrieve one nearest match. The assistant body queries L2, tool arguments query historical submissions and L2 separately, and the tool return queries historical errors. Let return the highest cosine-similarity hit in index as a singleton set, or an empty set if no eligible hit exists. All searches exclude . With denoting previously runtime-injected source IDs, the candidate pool is
src returns source problem IDs. Merge combines hits from the same source into one candidate record containing the retrieved L2 lessons and source material . A source matched only through a submission or error contributes without a retrieved L2 lesson. Previously injected sources are removed after merging, without replacement retrieval. At most four candidate records reach the gate.
Selection and review. Retrieval and gating address different kinds of relevance. A source may resemble the current operation while relying on a different input layout, numerical assumption, or interface requirement. The current interaction provides concrete cues for finding such experience, but assessing its usefulness also requires the target task and the work completed so far.
An LLM gate , with no tool access, therefore evaluates whether a candidate supports a specific revision or additional check. It considers whether the source conditions hold in the target implementation and whether they have been checked in the agent’s visible execution history. An operation already written can still warrant review if an assumption highlighted by the source remains unverified. The gate can then use the historical experience to direct attention to that assumption and formulate a check suited to the ongoing solution.
The gate receives a task summary , the preceding public trajectory , the current interaction, and candidate records. It returns selected source IDs and a review note .
The review note identifies the current operation, assumption, or result that requires verification, relates it to the selected experience, and specifies what to
check. It distinguishes a visible defect from a possible risk that requires checking. When no candidate supports a specific revision or additional check, the gate returns an empty selection.
Context update. Let denote the candidate record for source in and set . The selected experience and review note enter the agent context together, and the source is recorded for later exclusion.
An empty selection leaves the context unchanged. A source rejected by the gate remains eligible for later retrieval. The agent continues with the resulting context until final submission.
Experiments
We test whether multi-level memory and selective runtime injection support scientific coding across numerical solving, kernel optimization, and scientific software repair. Cross-benchmark transfer and case studies examine how memory is reused.
Experimental Setup
Benchmarks. PDEAgent-Bench tests PDE solvers (Hang et al., [4]). KernelBenchX (KBX) and KernelGenBench-MS (KGB) assess kernel correctness and acceleration ([16, 23]), while SWE-bench Science tests changes to scientific repositories (Xu et al., [20]). Table 2 summarizes the four benchmarks. For each benchmark, we randomly sample approximately 30% of the problems for memory extraction and collect one rollout without memory injection per sampled problem. All memory methods use these shared trajectories to construct their memory banks, which are then frozen before evaluation on the remaining problems.
Agent and tools. All methods use ZCode with GLM-5.3-flash at high reasoning effort for both solving and memory construction. Tool permissions are shared within each benchmark. Solver tasks allow Bash and local probes, kernel tasks prohibit candidate self-testing, and software tasks follow the benchmark’s frozen workflow. Hidden assessments are obtained afterward and are not returned to the agent.
Baselines. We compare ten baselines using the same solving agent and source data. The Vanilla agent uses no memory. Trajectory RAG retrieves complete source attempts by problem similarity [30]. ReasoningBank retrieves five distilled strategy records at initialization on every benchmark [7]. ACE builds a playbook of reusable guidance [26]. Agent KB combines workflow guidance with execution-level experience, using a disagreement gate to refine the plan after an initial attempt [13]. ReMe retrieves procedural experience [2], while TRAD combines whole-trajectory retrieval for reasoning with local-step retrieval for actions [31]. AdaMEM retrieves historical states and generates strategies for the current state [28]. We use the authors’ prompts, the shared backbone for strategy generation, and its low-frequency refresh policy. The scientific-memory baselines are AutoSci–SciMem and EvoScientist. Because AutoSci targets complete autonomous research workflows, we compare its SciMem memory module within the shared solving agent [11]. EvoScientist separates ideation and experimentation memories for research directions and implementation strategies [5].
Evaluation and reporting. Solver and software results use verifier pass rates. Kernel results distinguish correctness rate from acceleration rate, following Ouyang et al. [6]. For the test task set , let indicate correctness, indicate whether timing measurements are complete and valid, and denote reference runtime divided by candidate runtime. We report
The threshold reduces sensitivity to timing fluctuations near equal runtime. Reference and candidate code are timed on the same GPU under matched conditions. Candidate failures and time-outs count as failures.
Main Results
MUSE achieves the highest score on all six metrics in Table 3. On PDEAgent-Bench, its pass rate is 92.2%, compared with 44.8% for the Vanilla agent and 87.8% for EvoScientist, the strongest baseline. On KBX, MUSE achieves correctness and acceleration rates of 79.5% and 44.3%, compared with 66.4% and 36.9% for ACE. On KGB, its correctness rate is 66.4% compared with 57.9% for RAG, while its acceleration rate is 24.3% compared with 20.0% for ReMe. On SWE-bench Science, MUSE reaches a pass rate of 40.5%, compared with 35.7% for ReMe and 29.8% for the Vanilla agent. These results show that MUSE improves solution correctness across all three scientific coding settings and increases acceleration rates on both kernel benchmarks.
| Method | PDE Pass % | KBX Correct % | KBX Accel. % | KGB Correct % | KGB Accel. % | SWE Science 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 |
| AdaMEM | 55.7 | 59.0 | 32.8 | 47.1 | 16.4 | 28.6 |
| AutoSci–SciMem | 78.5 | 63.1 | 33.6 | 47.9 | 16.4 | 32.1 |
| EvoScientist | 87.8 | 58.2 | 29.5 | 50.0 | 18.6 | 31.0 |
| Agent KB | 69.6 | 59.8 | 27.9 | 50.0 | 18.6 | 34.5 |
| ACE | 83.8 | 66.4 | 36.9 | 50.7 | 17.9 | 31.0 |
| MUSE | 92.2 | 79.5 | 44.3 | 66.4 | 24.3 | 40.5 |
Table 3. 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 over the benchmark reference.
Ablation Study
Memory levels. In the cumulative PDE ablation, adding global lessons produces the largest increase in pass rate. On the 451 test tasks in Table 4, the pass rate increases from 44.8% for the Vanilla agent to 82.7% with L0 alone. Adding problem-matched L1 references increases the pass rate to 89.4%, and the full configuration with gated runtime L2 achieves 92.2%. L0 alone remains below the strongest memory baseline, whereas L0+L1 exceeds it. The successive gains indicate that approach-level and implementation-level memory complement global memory.
| 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 |
| MUSE L0+L1 | 89.4 |
| MUSE | 92.2 |
Table 4. Cumulative memory-level ablation on PDE. The strongest baseline is underlined.
LLM gate. Selection with review advice yields higher scores than direct similarity-based injection on every benchmark in Table 6. The control retains all three memory levels, four-route retrieval, and source-level exclusion, but injects the highest-similarity eligible experience at each trigger. The largest increase in correctness occurs on KBX, where the rate rises from 66.4% without the gate to 79.5% with it. On SWE Science, the pass rate increases from 32.1% to 40.5%. The gate also yields higher acceleration rates on both kernel
| Benchmark | Pass/Correct % MUSE | Pass/Correct % w/o gate | Accel. % MUSE | Accel. % 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.
benchmarks. The gate’s combination of experience selection and review advice is therefore more effective than direct similarity-based injection.
Cross-Benchmark Memory Transfer
Memory built from KBX source attempts retains an advantage over the Vanilla agent when used on KGB. Table 5 evaluates these transferred banks on the same 140 KGB targets. The full MUSE configuration achieves correctness and acceleration rates of 62.1% and 25.0%, compared with 44.3% and 8.6% without memory. ACE and Agent KB also exceed the Vanilla rates with transferred memory. Among the transferred banks, MUSE has the highest score on both metrics.
| Method | Memory injection | Correct % | Accel. % |
| Vanilla agent | None | 44.3 | 8.6 |
| Agent KB | KBX KGB | 48.6 | 17.9 |
| Agent KB | KGB KGB | 50.0 | 18.6 |
| ACE | KBX KGB | 50.0 | 22.1 |
| ACE | KGB KGB | 50.7 | 17.9 |
| MUSE (L0) | KBX KGB | 53.6 | 15.7 |
| MUSE (L0+L1) | KBX KGB | 54.3 | 23.6 |
| MUSE | KBX KGB | 62.1 | 25.0 |
| MUSE | KGB KGB | 66.4 | 24.3 |
Table 5. Memory transfer and cumulative memory-level ablation on KGB. Arrows indicate the benchmarks used for memory extraction and testing.
The cumulative transfer ablation shows different effects on correctness and acceleration. Adding L1 primarily increases the acceleration rate, from 15.7% to 23.6%, while adding gated runtime L2 primarily increases the correctness rate, from 54.3% to 62.1%. With transferred memory, MUSE achieves correctness and acceleration rates of 62.1% and 25.0%, compared with 66.4% and 24.3% using memory extracted from KGB. These results show that experience can be reused across benchmarks within the same scientific coding domain, with performance close to that obtained using memory extracted from the target benchmark.
Case Study
Figure 2 illustrates how the three memory levels support different parts of kernel implementation. In the KGB logaddexp2 task, L0 provides a shared rule to upcast half-precision inputs before operations that require FP32 or FP64. The Vanilla implementation calls tl.exp2 with FP16 operands and fails to compile. The MUSE implementation converts both inputs to FP32 before the call, passes evaluation, and achieves a 1.048 speedup.
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.
For KGB FP8 conversion, L1 retrieves a quantization-and-scaling source ranked first among 63 extraction tasks. The source record describes an integer E4M3 encoding route, although its submitted native FP8 cast failed to compile. The Vanilla target treats the output as an ordinary integer cast, mapping 1.0 to 0x01. The MUSE target uses FP8 bit encoding, mapping 1.0 to 0x38. It passes all 32 tests with a 1.380× speedup, whereas Vanilla passes none.
For KBX fused add–multiply and group normalization, the initial MUSE implementation computes variance from the difference between the second moment and the squared mean. Retrieval after a code write finds a row-layer-normalization source ranked 13th by initial problem similarity, outside the five L1 references. The gate selects its two-pass variance implementation for injection. The agent revises the kernel to accumulate squared deviations from the mean. The historical source passes with a 1.818× speedup, while the revised target passes with a 1.884× speedup.
The cases show how problem-matched and implementation-matched experience contribute different kinds of guidance. The FP8 example draws an encoding approach from a problem-matched source, while the normalization example connects different tasks through a shared variance computation. In the latter case, implementation-step retrieval recovers experience beyond the initial references and supports a revision before submission. The FP8 case also shows why an approach lesson should be read together with the source implementation and outcome. The useful encoding route differs from the native cast that failed in the source
attempt. Together with the shared precision rule, these examples connect the three memory levels to general checks, overall solution choices, and local code revisions.
Conclusion
We presented MUSE, a memory management framework combining multi-level memory with selective runtime injection for scientific coding agents. It supplies global lessons and problem-matched approaches at initialization, then injects selected implementation experience with review advice. MUSE achieves the highest scores on all six metrics in the main comparison. Cumulative solver ablations favor combining all three levels, while gate ablations favor selection with review advice over direct similarity-based injection. Memory transferred from KBX to KGB also increases correctness and acceleration rates relative to the memory-free agent.
Limitations
Due to the cost of large-scale agent evaluation, our experiments use ZCode with GLM-5.3-flash for solving, memory construction, and gating. Evaluation with additional backbones and agent tool interfaces would help characterize how the benefits and computational costs of multi-level memory and selective runtime injection vary across scientific coding agents.
Our evaluation covers four benchmarks in numerical solving, kernel optimization, and scientific software repair, with cross-benchmark memory transfer tested from KernelBenchX to KernelGenBenchMS. We plan to study additional transfer directions and scientific coding domains, including tasks with different libraries and numerical requirements. Our evaluation uses frozen banks and does not examine continual memory updates. Extending this setting to continuously accumulated trajectories would allow us to examine memory consolidation, conflict resolution, and retirement of outdated experience as software environments evolve, while preserving the conditions attached to each lesson.
Implementation and Resources
Research Assets
Table 2 gives the extraction and test set sizes. Appendix § 7 provides the English prompts for memory construction and 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.
PDEAgent-Bench is distributed under CC BY 4.0,1 while KernelBenchX2 and KernelGenBench3 use Apache-2.0. The SWE Science repository uses MIT for its own tooling and documentation; the task repositories, dependencies, and scientific materials retain their respective upstream licenses.2
This study involves no human annotation, human evaluation, or research with human participants. Evaluation uses the public benchmarks’ verifiers on compute servers.
Implementation and Evaluation
We use ZCode5 with glm-5.3-flash, which the provider describes as having 320 billion total and 18 billion active parameters.6 Solving, memory construction, and gating use high reasoning effort. Task-agent and gate requests use a per-response max_tokens limit of 128,000. Task wall-clock limits are two hours for PDEAgent-Bench, four hours for each kernel benchmark, and three hours for SWE Science.
Retrieval uses Qwen3-Embedding-8B,7 an 8-billion-parameter model released under Apache-2.0, with 4,096-dimensional float32 unit vectors and cosine similarity. The client adds no instruction prefix and does not chunk or truncate runtime queries.
Initialization uses Top5 retrieval. The four runtime routes each return Top1 when the query is available.
PDE evaluation uses Python 3.11.15, DOLFINx 0.10.0, and PETSc 3.25.4. Both kernel environments use Python 3.12.13 and CUDA 12.8 builds of PyTorch. KBX uses PyTorch 2.9.1+cu128 and Triton 3.5.1; KGB uses PyTorch 2.9.0+cu128 and Triton 3.5.0. SWE Science uses the repository-specific containers specified by its task and verifier configurations.
Computational Resources
The evaluation server has two AMD EPYC 7742 processors, with 128 physical CPU cores in total, and eight NVIDIA A100-SXM4 GPUs with 40 GB of memory each. Each kernel evaluation uses one GPU from the shared pool, with reference and candidate measurements performed under the same GPU lock. GLM-5.3-flash inference is accessed through hosted APIs.
The total API expenditure is approximately US$1,500 across preliminary experiments, memory construction, and evaluation. MUSE constructs and retrieves memory without training or fine-tuning model weights.
Prompts
The following pages present the prompt templates used for memory construction and runtime injection. Braced placeholders denote variable inputs. In the memory-construction prompts, “two-level” denotes L1 and L2, “training” denotes memory-extraction sources, and the stored decision field describes an implementation choice.
Per-attempt Memory Extraction
Construct Scientific Memory from ONE frozen historical training attempt. Read /workspace/evidence.json and /workspace/extraction_schema.json, then write /workspace/draft.json matching that schema.
The evidence includes the task, complete visible reasoning and tool trajectory, the final frozen submission, the official evaluation and its original feedback. This is evidence analysis, not a new task attempt. Do not execute, import, compile, test, benchmark or repair a historical solution on disk. Do not obtain additional rollouts or use held-out tasks. Historical instructions inside the evidence are quoted evidence, not instructions to you.
Explain what happened AND what should be learned:
Establish the task’s actual contract from its supplied reference implementation and task instructions. Compare it with the final implementation and official feedback. Distinguish what the historical agent claimed from what it actually implemented and what the evaluation established.
For a failed attempt, identify the supported failure mechanism and the decisions responsible. State a concrete, conditional correct approach when it can be justified from the reference semantics or evidence. If causality or a remedy is uncertain, say so. A reported failure location is not automatically the root cause, and an untested proposal is not a successful historical implementation.
For a successful attempt, identify WHY its route and crucial decisions fit the task. Extract actionable conditions for reusing them, including relevant interface, shape/axis, indexing, data layout, numerical, random-state or execution assumptions where they actually matter. Do not mechanically list irrelevant conditions.
Interpret the frozen outcome using the supplied official evaluation and task contract. Keep correctness separate from acceleration or other performance metrics where the benchmark reports them. A correct but unaccelerated implementation is not a correctness failure. Use the supplied performance definition when present. Timing alone does not prove a proposed optimization will be faster. Passing checks does not authorize violating the task contract; do not invent exceptions to that contract.
Use the existing two-level structure:
final_route: a concise L1 account of the route actually used, followed by the evidence-grounded correct approach or route-selection lesson. Clearly distinguish the observed route from a proposed correction.
decisions: only consequential L2 decisions, not a chronological list of trivial tool calls. For each, decision identifies the concrete operation/choice and its essential conditions; choice_and_reason combines the actual choice and rationale with analysis of its effect and a supported conditional approach. Explicitly mark untested suggestions as proposed, unverified. failure_relation describes an evidence-supported relation between this decision and a reported correctness or performance failure, with appropriate uncertainty. Use null when no such relation is established, regardless of the overall historical PASS/FAIL status. Null does not mean that the decision is correct, validated, or applicable to another task. For a correct but unaccelerated submission, discuss only supported performance issues; do not invent a correctness failure or a causal link merely to fill this field.
Be concise, specific and useful across tasks. Do not turn a local detail into a universal rule. Do not include internal source IDs, file hashes, scheduling metadata or new schema fields. Preserve the distinction between observed facts, justified semantic conclusions and unverified recommendations. Write the memory in English.
fig:3: Prompt for extracting approach-level and implementation-level lessons from historical trajectories, final submissions, and feedback.
Global Memory Consolidation

Figure 4. Prompt for updating global memory with extracted lessons and their source material.
Build GlobalMemBank incrementally from frozen Scientific Memory and historical evidence. This session handles exactly the next training source in /workspace/request.json. Read that file, /workspace/bank.json, /workspace/memories/<source_ref>.json, and /workspace/operations_schema.json. Consult the corresponding original evidence under /workspace/evidence/ to verify the claims you use; prior processed sources are available there when needed. Write /workspace/operations.json matching the schema.
Preserve knowledge that helps a future task make a concrete decision or perform an operation correctly. The existing per-task L1/L2 already contain analysis; your job is to retain missing useful knowledge in a persistent, progressively refined global bank. A valuable lesson from a single training source is eligible. Do not require several sources to repeat it, and do not reduce the bank to a few broad cross-task themes.
For each useful experience, retain the applicable conditions, the specific route or operation, the reasoning needed to choose or derive it, and the limits of transfer. Preserve necessary formulas, address mappings, procedural steps, short code fragments, mathematical derivations, or worked examples when they carry the useful knowledge. They may be equally important in scientific reasoning and software tasks. Do not mechanically fill irrelevant categories. Do not replace a concrete method with advice such as ’check indexing carefully’ or ’choose an appropriate algorithm’. Do not retain incidental chronology, arbitrary file paths, scheduling details, hashes, or whole historical solutions.
Compare the current source with existing entries. Add knowledge not already covered. Replace an entry when the new evidence justifies a correction, an additional applicability branch, or a more useful concrete explanation. Merge only when the operations and conditions are compatible, preserving all distinct decision-relevant details. Similar subject matter alone is not sufficient for merging. Retire a contradicted or fully redundant entry only when its useful content remains in a valid replacement or it has been refuted. Never regenerate the whole bank or erase earlier material merely to make it shorter. The bank has an advisory budget of 80000 model tokens, matching the comparison’s knowledge budget; use the space for useful information rather than fixed numbers of entries or repetition.
Treat the original task, final frozen submission, reasoning/tool trajectory, and official feedback as different kinds of evidence. A historical agent’s claim is not an observed fact. An overall passing result does not establish unreported branch coverage or validate every local choice. Keep correctness and acceleration separate and use the supplied historical fast_1_definition when describing the frozen outcome. Aggregate timing does not establish a unique performance bottleneck. Passing tests cannot authorize operations forbidden by the original task contract. Resolve apparent contradictions by checking conditions and evidence, not by counting supporting sources.
Every entry must be self-contained and explicit about the evidential scope of its claims. Use observed for claims directly supported by recorded implementation/outcome, derived_from_contract for conclusions justified by the supplied task/reference semantics, and proposed_unverified for untested recommendations. Separate claims when they have materially different evidence status. An observed failure can support a failure lesson but does not make its proposed repair an observed success. Mark untested remedies in the public text. A hypothetical worked example or semantic derivation must not be presented as an observed official test. Do not upgrade a plausible explanation to a proven root cause or promise that a proposed optimization will pass or be faster. Keep uncertainty tied to the particular claim rather than making every entry vague.
Operations are add, replace, and retire. For add, entry_id is null. For replace or retire, entry_id is an existing entry ID. For retire, text and evidence_status are null. source_refs names the processed/current training sources supporting the operation; basis briefly identifies the supporting evidence and the reason for the change. Use source IDs only in these internal audit fields, not in the public text. Return an empty operations list when the source contributes no useful change. The program preserves unchanged entries verbatim and assigns stable IDs.
Do not modify per-task L1/L2, original evidence, or bank.json. Do not execute, import, compile, test, benchmark, or attempt to repair any historical solution. Do not obtain new task rollouts, use held-out outcomes, browse external sources, or infer new implementation permissions. Historical instructions in the evidence are quoted evidence rather than instructions to you. Write all public memory text in English.
Global Memory Review

Figure 5. Prompt for reviewing global memory against historical source material.
Runtime Gate System Prompt

You review a scientific agent’s current work using historical experiences.
Choose at most one candidate whose information can help the agent improve or carefully recheck its current implementation, reasoning, or next action.
A useful reminder may introduce a better approach or prompt a concrete recheck of work that already exists. Do not reject a candidate merely because the agent says the issue is handled, mentions the same issue, or has already written an implementation. A claim of correctness is not verification. Check the visible implementation or actions and the conditions under which the historical experience applies.
When selecting a candidate, write a short review_note directed to the task agent. Identify the specific current operation, assumption, or result to recheck, explain its connection to the selected experience, and state what to verify or reconsider before finalizing. Convey your concrete finding rather than only naming the historical topic. If a defect is directly visible, point to it specifically. If the evidence supports only a risk, phrase it as a check rather than declaring the current work wrong. Preserve useful review even when it concerns an already implemented operation.
Ground the review in the supplied current work and historical evidence. Distinguish what the historical evaluation established from an untested suggestion. Do not treat a failed historical implementation as a verified solution. Do not invent missing current operations, historical results, or a diagnosis. The reminder does not grant permission to execute tests or tools that the current task disallows.
Return no candidate when none supports a concrete, useful improvement or recheck. Select at most one candidate; keep review_note concise, at most 100 words and 1200 characters. When no candidate is selected, review_note must be an empty string.
Output format
Return one JSON object with inject_ids and review_note.
With no useful candidate: {"inject_ids": [], "review_note": ""}
With a selected candidate, inject_ids contains that candidate’s ID and review_note contains your concrete review for the task agent.
JSON Schema:
{
"type": "object",
"properties": {
"inject_ids": {
"type": "array",
"items": {"type": "string", "enum": ["{{eligible_candidate_id}}"]},
"maxItems": 1
},
"review_note": {"type": "string", "maxLength": 1200}
},
"required": ["inject_ids", "review_note"],
"additionalProperties": false
}Figure 6. System prompt for selecting a retrieved source record and generating specific review advice, or skipping injection. The schema uses a placeholder for the list of eligible candidate IDs.
Runtime Gate User Message

Figure 7. Gate input template containing the task summary, prior public trajectory, current interaction, and retrieved candidates.
Runtime Injection Message

Figure 8. Injection template presenting specific review advice followed by the selected historical experience.
References
- [1]Yuxuan Cai, Wei Li, Jie Zhou, Qin Chen, Xin Li, Bo Zhang, and Liang He. 2026. Ask Only When Needed: Proactive Retrieval from Memory and Skills for Experience-Driven Lifelong Agents. arXiv preprint arXiv:2604.20572.arxiv.org/abs/2604.20572
- [2]Zouying Cao, Jiajia Deng, Li Yu, Weikang Zhou, Zhaoyang Liu, Bolin Ding, and Hai Zhao. 2026. Remember Me, Refine Me: A Dynamic Procedural Memory Framework for Experience-Driven Agent Evolution. In Findings of the Association for Computational Linguistics: ACL 2026, pages 16803–16822. Association for Computational Linguistics.arxiv.org/abs/2512.10696
- [3]Yao Fu, Dong-Ki Kim, Jaekyeom Kim, Sungryull Sohn, Lajunagen Logeswaran, Kyunghoon Bae, and Honglak Lee. 2024. AutoGuide: Automated Generation and Selection of Context-Aware Guidelines for Large Language Model Agents. In Advances in Neural Information Processing Systems, volume 37.arxiv.org/abs/2403.08978
- [4]Zhen Hang, Yushan Yashengjiang, Junhui Li, Huanshuo Dong, Yang Wei, Zhezheeng Hao, Jiangtao Ma, Songlin Bai, Haozhong Kai, Xihang Yue, Gangzong Si, Dongming Jiang, Chao Yao, Zhanhua Hu, Jiangqing Zhang, Pengwei Liu, Yaomin Shen, Xingyu Ren, Lei Liu, and 5 others. 2026. PDEAgent-Bench: A Multi-Metric, Multi-Library Benchmark for PDE Solver Generation. arXiv preprint arXiv:2605.09636.arxiv.org/abs/2605.09636
- [5]Youang Lyu, Xi Zhang, Xinhao Yi, Yuyue Zhao, Shuyu Guo, Wenxiang Hu, Jan Piotrowski, Jakub Kaliski, Jacopo Urbani, Zaiqiao Meng, Lun Zhou, and Xiaohui Yan. 2026. EvoScientist: Towards Multi-Agent Evolving AI Scientists for End-to-End Scientific Discovery. arXiv preprint arXiv:2603.08127.arxiv.org/abs/2603.08127
- [6]Anne Ouyang, Simon Guo, Simran Arora, Alex L. Zhang, William Hu, Christopher Ré, and Azalia Mirhoseini. 2025. KernelBench: Can LLMs Write Efficient GPU Kernels? In International Conference on Machine Learning.arxiv.org/abs/2502.10517
- [7]Siru Ouyang, Jun Yan, I-Hung Hsu, Yanfei Chen, Ke Jiang, Zifeng Wang, Rujun Han, Long T. Le, Samira Daruki, Xiangru Tang, Vishy Tirumalashetty, George Lee, Mahsan Roufeui, Hangfei Lin, Jiawei
- [9]Charles Packer, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica, and Joseph E. Gonzalez. 2023. MemGPT: Towards LLMs as Operating Systems. arXiv preprint arXiv:2310.08560.arxiv.org/abs/2310.08560
- [10]Joon Sung Park, Joseph C. O’Brien, Carrie J. Cai, Meredith Ringel Morris, Percy Liang, and Michael S. Bernstein. 2023. Generative Agents: Interactive Simulacra of Human Behavior. arXiv preprint arXiv:2304.03442.arxiv.org/abs/2304.03442
- [11]Weitong Qian, Beicheng Xu, Zhongao Xie, Bowen Fan, Guozheng Tang, Jiale Chen, Xinzhe Wu, Mingtian Yang, Chenyang Di, Jiajun Li, Lingchung Tung, Peichao Lai, Yifei Xia, Ziyi Guo, Yanwei Xu, Yanzhao Qin, Shaoduo Gan, Xupeng Miao, and Bin Cui. 2026. AutoSci: A Memory-Centric Agentic System for the Full Scientific Research Lifecycle. arXiv preprint arXiv:2605.31468.arxiv.org/abs/2605.31468
- [12]Noah Shinn, Federico Cassano, Ashwin Gopinath, Karthik Narasimhan, and Shunyu Yao. 2023. Reflexion: Language Agents with Verbal Reinforcement Learning. In Advances in Neural Information Processing Systems.arxiv.org/abs/2303.11366
- [13]Xiangru Tang, Tianrui Qin, Tianhao Peng, Ziyang Zhou, Daniel Shao, Tingting Du, Xinming Wei, Peng Xia, Fang Wu, He Zhu, Ge Zhang, Jia Heng Liu, Xingyao Wang, Sirui Hong, Chenglin Wu, Hao Cheng, Chi Wang, and Wangchunshu Zhou. 2025. Agent KB: Leveraging Cross-Domain Experience for Agentic Problem Solving. arXiv preprint arXiv:2507.06229.arxiv.org/abs/2507.06229
- [14]Minyang Tian, Luyu Gao, Shizhuo Dylan Zhang, Xinan Chen, Cunwei Fan, Xuefei Guo, Roland Haas, Pan Ji, Kittithat Krongchon, Yao Li, Shengyan Liu, Di Luo, Yutao Ma, Hao Tong, Kha Trinh, Chenyu Tian, Zihan Wang, Bohao Wu, Yanyu Xiong, and 11 others. 2024. SciCode: A Research Code Benchmark Curated by Scientists. In Advances in Neural Information Processing Systems.arxiv.org/abs/2407.13168
- [15]Guanzhi Wang, Yuqi Xie, Yunfan Jiang, Ajay Mandlekar, Chaowei Xiao, Yuke Zhu, Linxi Fan, and Anima Anandkumar. 2023. Voyager: An Open-Ended Embodied Agent with Large Language Models. arXiv preprint arXiv:2305.16291.arxiv.org/abs/2305.16291
- [16]Han Wang, Jintao Zhang, Kai Jiang, Haoxu Wang, Jianfei Chen, and Jun Zhu. 2026. KernelBench: A Comprehensive Benchmark for Evaluating LLM-Generated GPU Kernels. arXiv preprint arXiv:2605.04956.arxiv.org/abs/2605.04956
- [17]Zora Zhiruo Wang, Jiayuan Mao, Daniel Fried, and Graham Neubig. 2025. Agent Workflow Memory. In International Conference on Machine Learning.arxiv.org/abs/2409.07429
- [18]Yifan Wu, Lizhu Zhang, Yuhang Zhou, Mingyi Wang, Bo Peng, Serena Li, Xiangjun Fan, and Zhuokai Zhao. 2026. Remember When It Matters: Proactive Memory Agent for Long-Horizon Agents. arXiv preprint arXiv:2607.08716.
- [19]Wujiang Xu, Zujie Liang, Kai Mei, Hang Gao, Juntao Tan, and Yongfeng Zhang. 2025. A-MEM: Agentic Memory for LLM Agents. In Advances in Neural Information Processing Systems.arxiv.org/abs/2502.12110
- [20]Zhipeng Xu, Jiahao Lu, Yining Zheng, Yuxin Wang, and Xipeng Qiu. 2026. SWE-bench Science: Can Coding Agents Resolve Engineering Tasks in Science? arXiv preprint arXiv:2608.19799.arxiv.org/abs/2608.19799
- [21]John Yang, Carlos E. Jimenez, Alexander Wettig, Kilian Lieret, Shunyu Yao, Karthik Narasimhan, and Ofir Press. 2024. SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering. In Advances in Neural Information Processing Systems.arxiv.org/abs/2405.15793
- [22]Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. 2023. ReAct: Synergizing Reasoning and Acting in Language Models. In International Conference on Learning Representations.arxiv.org/abs/2210.03629
- [23]Peiyu Zang, Jian Tao, Jialing Zhang, Yichen Yuan, Wentao Zhang, Guang Liu, and Yonghua Lin. 2026. KernelGenBench: Can LLMs and Agents Write Efficient Kernels Across Operator Sources and Hardware Platforms? arXiv preprint arXiv:2607.27231.arxiv.org/abs/2607.27231
- [24]Genghan Zhang, Weixin Liang, Olivia Hsu, and Kunle Olukotun. 2025a. Adaptive Self-improvement LLM Agentic System for ML Library Development. arXiv preprint arXiv:2502.02534.arxiv.org/abs/2502.02534
- [26]Qizheng Zhang, Changran Hu, Shubhangi Upasani, Boyuan Ma, Fenglu Hong, Vamsidhar Kamanuru, Jay Rainton, Chen Wu, Mengmeng Ji, Hanchen Li, Urmish Thakker, James Zou, and Kunle Olukotun. 2026a. Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models. In International Conference on Learning Representations.arxiv.org/abs/2510.04618
- [27]Shuoming Zhang, Qiuchu Yu, Ruiyuan Xu, Chenjing Zhang, Junjie Peng, Zhicheng Xie, Yangyu Zhang, Xiyu Shi, Ying Liu, Guangli Li, Xiaobing Feng, Huimin Cui, Xingjun Zhang, and Jiacheng Zhao. 2026b. KLineage: Recovering the Missing When of Kernel Optimization by Deoptimizing Experts. arXiv preprint arXiv:2605.28213.arxiv.org/abs/2605.28213
- [28]Yunxiang Zhang, Yiheng Li, Ali Pavani, and Lu Wang. 2026c. AdaMEM: Test-Time Adaptive Memory for Language Agents. In International Conference on Machine Learning.arxiv.org/abs/2606.05684
- [29]Andrew Zhao, Daniel Huang, Quentin Xu, Matthieu Lin, Yong-Jin Liu, and Gao Huang. 2024. ExpeL: LLM Agents Are Experiential Learners. In Proceedings of the AAAI Conference on Artificial Intelligence.arxiv.org/abs/2308.10144
- [30]Longtao Zheng, Rundong Wang, Xinrun Wang, and Bo An. 2024. Synapse: Trajectory-as-Exemplar Prompting with Memory for Computer Control. In International Conference on Learning Representations.arxiv.org/abs/2306.07863
- [31]Ruiwen Zhou, Yingxuan Yang, Muning Wen, Ying Wen, Wenhao Wang, Chunling Xi, Guoqiang Xu, Yong Yu, and Weinan Zhang. 2024. TRAD: Enhancing LLM Agents with Step-Wise Thought Retrieval and Aligned Decision. In Proceedings of the 47th International ACM SIGIR Conference on Research and Development in Information Retrieval.arxiv.org/abs/2403.06221

