ICLR 2025Memory for scientific reasoning

ChemAgent: Self-updating Library in Large Language Models Improves Chemical Reasoning

Xiangru Tang1*, Tianyu Hu1*, Muyang Ye1*, Yanjun Shao1*, Xunjian Yin1, Siru Ouyang2, Wangchunshu Zhou, Pan Lu3, Zhuosheng Zhang4, Yilun Zhao1, Arman Cohan1, Mark Gerstein1

1 Yale University · 2 UIUC · 3 Stanford University · 4 Shanghai Jiao Tong University · * Equal contribution

ChemAgent turns solved chemistry subproblems into reusable memory, helping an LLM plan, calculate, and refine new solutions with experience retained outside its model weights.

Result
Average accuracy over four SciBench chemistry sets with GPT-4: 57.16% for ChemAgent vs 47.66% for StructChem.
New vs prior
StructChem structures chemical reasoning into formula generation, step-by-step reasoning and confidence-based review; this work adds a self-updating library of solved sub-tasks that is retrieved for each new sub-task.
Limitation
Evaluation and refinement nearly double the cost, from about 0.012 to 0.023 million tokens per problem, excluding library construction.
Scroll sideways to read the figure. ChemAgent's framework: (a) library-enhanced reasoning, in which a test problem is decomposed into sub-tasks with the help of plan and knowledge memory, each sub-task retrieves relevant memories from the library (which is updated as sub-tasks are solved), and the sub-solutions are summarized into the final answer; (b) library construction from the development set, in which conditions are split and verified, only correct sub-task solutions are kept as execution memory, and plan memory is added to the library. Original Figure 2 from the paper. Full size ↗

Reuse the part of a solution that transfers

Two chemistry questions may share a calculation even when their full solutions differ, and retrieving a whole worked example can bury that step under irrelevant conditions. ChemAgent therefore stores smaller units, each holding a sub-task’s conditions, the sub-task and its solution, so earlier work is available where a new calculation needs it.

The library is not fixed. Solutions from development-set problems seed it, and the agent adds new experiences as it solves problems. The question is whether this growing memory of sub-tasks helps on chemistry problems it has not seen.

Closest prior work

StructChem (Ouyang et al., 2024), the main baseline, structures chemical reasoning into formula generation, step-by-step reasoning and confidence-based review, but the paper notes that it still struggles with highly complex problems. Agent self-evolution frameworks with memory, such as Agent Workflow Memory (Wang et al., 2024) and Investigate-Consolidate-Exploit (Qian et al., 2024), mainly reuse past workflows in daily tasks. ChemAgent instead decomposes solved chemistry problems into planning and execution memories, retrieves them for each sub-task, and adds newly solved sub-tasks to the library.

Memory must support both execution and replanning

The initial library comes from development-set problems with supplied solutions: conditions are extracted and checked, solutions are decomposed, and low-confidence units are filtered out. Planning memory keeps high-level strategies; execution memory keeps solved sub-tasks. Knowledge memory, the formulas and principles generated for the current problem, is not added to the shared library.

Published example · Figure 2, memory examples from Figure 3

How the library is used on a test problem, and how it is built

Figure 2’s two panels as a step-through. In (a) a test problem splits into sub-tasks, each retrieves its own memories, and the library grows while the problem is being solved; in (b) a development-set solution is split, verified and filtered into memory. The physics is computed; the branch buttons show the paper’s alternatives.

Figure 2(a) · library-enhanced reasoning on a test-set problem

  1. Test-set task
    Calculate the de Broglie wavelength for (a) an electron with a kinetic energy of 100eV. The unit of the answer should be nm.
  2. Decomposition · LLM, with plan memory Mp and knowledge memory Mk
    Sub-task 1: Use kinetic energy formula to calculate velocity of electron · Sub-task 2: Use de Broglie wavelength formula to compute wavelength · Sub-task n: ……

    Plan memory supplies stored strategies; knowledge memory, formulas and principles the LLM generates for this problem, is created now.

  3. Sub-task 1 · retrieve
    retrieve → Library → Find relevant memories

    Execution-memory units whose sub-task embedding has cosine similarity above a threshold θ with this sub-task are retrieved (Llama3 embeddings, Section 2.5), together with the problem’s knowledge memory.

  4. Sub-solution 1
    [Formula 1] p = m * v where p is …. [Step 1] Identify the given values:

    Computed v = √(2·KE/m) = √(2 × 1.60 × 10⁻¹⁷ J / 9.109 × 10⁻³¹ kg) = 5.93 × 10⁶ m/s

  5. Library update
    LLM → (Updated) Library

    The solved sub-task enters execution memory at once, Me = Me ∪ {(C₁, T₁, O₁)} (Section 2.5), and its answer joins the conditions of the next sub-task (the arrow from Sub-solution 1 to Sub-task 2).

  6. Sub-task 2 · retrieve from the (Updated) Library
    retrieve → (Updated) Library → Find relevant memories

    Retrieval now also sees the unit just added, so later sub-tasks of the same problem can reuse it.

  7. Sub-solution 2
    [Formula 1] The kinetic energy can be calculated: KE = ½mv², where…

    The LLM adds this unit to the library too, before any remaining sub-task (Sub-task n: …… in the figure).

    Computed p = m·v = 5.40 × 10⁻²⁴ kg·m/s; λ = h/p = 0.123 nm

  8. Summarize and generate → Final answer
    Final answer ✓

    Plan memory gains a summary of the strategy used, Mp = Mp ∪ {(T, K)} (Section 2.5). Knowledge memory is discarded with the problem; it is not kept in the library.

    Computed λ = 0.123 nm for KE = 100 eV; v/c = 0.0198 (the sub-tasks’ nonrelativistic formulas assume v ≪ c)

Quoted from Figure 2: the tasks, solution excerpt, conditions, sub-tasks, sub-solution excerpts and labels; Figure 2 prints no retrieved memory and no numerical answer. Memory examples are excerpts from Figure 3, written for the related task “Calculate the momentum of the electron.” Explanations follow Sections 2.4 and 2.5. Computed here: the physics, with 1 eV = 1.602 × 10⁻¹⁹ J (Figure 2(b)), m = 9.109 × 10⁻³¹ kg (Figure 3), h = 6.626 × 10⁻³⁴ J·s and c = 2.998 × 10⁸ m/s. The computed lines follow the sub-task descriptions; the figure’s two sub-solution excerpts appear exchanged, since Sub-solution 1 opens with the momentum formula and Sub-solution 2 with the kinetic-energy formula. The branch buttons show the paper’s alternatives; they do not reproduce a logged run.

In the framework figure, finding the wavelength of an electron with 100 eV of kinetic energy splits into two sub-tasks: the velocity from the kinetic-energy formula, then the de Broglie wavelength. Each sub-task retrieves its own memories, so an earlier velocity calculation helps even if no earlier question matches as a whole.

Review can revise the current answer or the remaining plan. A unit error needs a corrected sub-solution, but a sub-task that computes energy when the question asks for wavelength needs the later steps restructured, because fixing arithmetic cannot rescue a plan aimed at the wrong quantity. Without a suitable execution memory, the agent writes related practice problems itself.

  1. 01

    Build reusable memory

    Decompose worked problems into planning strategies and structured subproblem solutions.

  2. 02

    Retrieve and solve

    Retrieve related experiences and generate task-specific chemistry knowledge to guide each subproblem.

  3. 03

    Refine and retain

    Evaluate intermediate solutions, revise the plan when needed, and add new experiences to the library.

Memory and review both contribute, at roughly twice the token cost

Both components contribute: the GPT-4 average drops without evaluation and refinement, and drops further without memory, so stored examples alone do not explain the gain. Review roughly doubles the token cost per problem, not counting the one-time library construction.

The self-updating experiment on MATTER removes review, keeps only experiences judged correct and excludes a problem’s own earlier memory, so memory quality is part of the result. Figure 7 shows retrieval failing: for a gas compressed reversibly and adiabatically, where entropy does not change, the plan ignores that condition and applies ΔS = n·C_V,m·ln(T_final/T_initial), while the retrieved memories, on reaction entropy and cell potentials, do not apply. Flawed decomposition and irrelevant retrieval compound each other.

Table 1 (GPT-4 rows). Accuracy (%) on the four SciBench chemistry test sets (an answer counts as correct within 1% relative tolerance), higher is better; all rows use gpt-4-1106-preview, and Avg. is the unweighted mean of the four datasets. Few-shot + Direct reasoning and Few-shot + Python scores are taken from StructChem and SciBench, respectively, rather than rerun in this paper. The table's Llama 3.1-7b, Llama 3.1-70b, and Qwen 2.5-72b blocks are omitted; with those backbones ChemAgent raises the average over direct reasoning but trails it on ATKINS for Llama 3.1-7b (19.63 vs. 22.43) and Qwen 2.5-72b (56.07 vs. 57.01). Source ↗

MethodCHEMMCMATTERATKINSQUANAvg.
Few-shot + Direct reasoning28.2114.2920.6914.7119.48
Few-shot + Python38.4634.6957.0144.1243.57
StructChem58.9730.6759.8141.1847.66
ChemAgent74.3648.9861.1844.1257.16
w/o Evaluation & Refinement61.5444.8957.9444.1252.12
w/o Memory, Evaluation & Refinement58.9738.7857.9441.1849.22

Method proposed in the paper

Scope. Evaluation uses four SciBench textbook chemistry sets; the paper suggests, but does not test, applications such as drug discovery or materials design. Read the study ↗

Further reading in the paperMemory construction and refinement · Sections 2.2–2.6 ↗Ablations, repeated exposure, and errors · Sections 2.8–3 ↗
Research summary

Chemical reasoning usually involves complex, multi-step processes that demand precise calculations, where even minor errors can lead to cascading failures. Furthermore, large language models (LLMs) encounter difficulties handling domain-specific formulas, executing reasoning steps accurately, and integrating code effectively when tackling chemical reasoning tasks. To address these challenges, we present ChemAgent, a novel framework designed to improve the performance of LLMs through a dynamic, self-updating library. This library is developed by decomposing chemical tasks into sub-tasks and compiling these sub-tasks into a structured collection that can be referenced for future queries. Then, when presented with a new problem, ChemAgent retrieves and refines pertinent information from the library, which we call memory, facilitating effective task decomposition and the generation of solutions. Our method designs three types of memory and a library-enhanced reasoning component, enabling LLMs to improve over time through experience. Experimental results on four chemical reasoning datasets from SciBench demonstrate that ChemAgent achieves performance gains of up to 46% (GPT-4), significantly outperforming existing methods. Our findings suggest substantial potential for future applications, including tasks such as drug discovery and materials science.

Full paper ↗
Citation BibTeX
@inproceedings{tang2025chemagent,
  title={ChemAgent: Self-updating Library in Large Language Models Improves Chemical Reasoning},
  author={Tang, Xiangru and Hu, Tianyu and Ye, Muyang and Shao, Yanjun and Yin, Xunjian and Ouyang, Siru and Zhou, Wangchunshu and Lu, Pan and Zhang, Zhuosheng and Zhao, Yilun and Cohan, Arman and Gerstein, Mark},
  booktitle={International Conference on Learning Representations},
  year={2025},
  url={https://openreview.net/forum?id=kuhIqeVg0e}
}