Mass Spectrometry Interpretation with AI Agents: Using Skills Orchestration for Structure Elucidation

    This article explains why general-purpose language models struggle with mass spectrometry interpretation and how a three-layer architecture—deterministic domain skills, agent orchestration, and an audit layer—solves the problem. It covers the split between known-compound confirmation and unknown-compound elucidation, the hard numerical constraints behind exact mass calculation, large-scale candidate retrieval, bond cleavage simulation, and evidence traceability, plus sample skill contracts and orchestration code. It also summarizes reported accuracy and token-cost results, evaluation practices, and deployment guidance.

    1. The Problem: A Wide Gap Between a Peak List and a Structure

    Mass spectrometry interpretation can be split into two engineering subproblems with fundamentally different natures. The first is known-compound confirmation: matching a measured spectrum against existing reference spectra or a candidate library, then outputting similarity and confidence scores. The second is unknown-compound elucidation: with no reference answer available, inferring possible molecular formulas and structural fragments solely from the mass, intensity, and fragmentation relationships of fragment ions. The former is a retrieval problem; the latter is a constraint-solving problem.

    The controlled experiment in the source material is convincing. Under fully offline conditions with no additional skills loaded, three general-purpose multimodal/language models all achieved identification accuracy below 4%. When restricted network access was opened, the stronger models still missed one quarter to one third of the spectra, while lightweight models missed more than three quarters. These numbers point to one key fact: language models are good at semantic organization and reasoning expression, not at numerically precise computation or exhaustive candidate filtering. Hand a peak list directly to a model and it mostly “talks like a chemist” rather than performing mass arithmetic.

    2. Why a Language Model Alone Cannot Do It

    Every step of mass spectrometry interpretation carries hard numerical constraints, and an error in any single step collapses every conclusion that follows.

    • Exact mass calculation: requires summing elemental isotope masses, with error typically measured in ppm. Language models have no reliable fixed-point or high-precision numerical core, so multi-element summation easily drifts in the last digits.
    • Large-scale candidate retrieval: near-neighbor filtering across a library of a million compounds requires vectorized indexing and stable ranking operators. This is an engineering-system capability, not a generative reasoning capability.
    • Bond cleavage simulation: requires enumerating bond-breaking paths according to fragmentation rules and verifying mass and charge conservation for each path. It is essentially a constrained combinatorial search.
    • Evidence chain organization: a finalized conclusion must be traceable to “which peak, which path, which library record.” That demands structured intermediate artifacts, not a passage of natural-language narrative.

    So the right architecture is not “make the model smarter” but “teach the model to call deterministic tools.”

    3. Target Architecture: A Domain Skill Set Plus Agent Orchestration

    The design can be abstracted into three layers.

    The first layer is the skill layer. Each skill is a deterministic operator with a clear boundary and an explicit input/output contract, for example:

    1. skill: peak_denoise
    2. input : { spectrum: float[], baseline_mode: "auto" }
    3. output: { peaks: [{mz, intensity, snr}] }
    4. skill: formula_enumerate
    5. input : { precursor_mz, tolerance_ppm, elements: ["C","H","N","O"] }
    6. output: { formulas: [{formula, exact_mass, ppm_error, rdb}] }
    7. skill: library_search
    8. input : { peaks, tolerance_ppm, top_k }
    9. output: { candidates: [{id, score, matched_ions}] }
    10. skill: bond_cleavage_sim
    11. input : { structure, ruleset }
    12. output: { predicted_fragments: [{mz, path, neutral_loss}] }

    The second layer is the orchestration layer. The agent reads the researcher’s natural-language task and the instrument tolerance, compiles the task into a skill invocation graph, and decides when to backtrack, when to widen the candidate set, and when to declare the evidence insufficient. The third layer is the audit layer, which writes the input, parameters, output, and confidence of every step into structured records and finally renders them into a reviewable report.

    A sketch of the orchestration logic:

    1. plan = agent.compile(task=nl_task, tolerance_ppm=5, mode="unknown")
    2. ctx = {}
    3. ctx["peaks"] = skills.run("peak_denoise", plan.input_spectrum)
    4. ctx["formulas"] = skills.run("formula_enumerate",
    5. precursor_mz=ctx["peaks"].precursor,
    6. tolerance_ppm=plan.tolerance_ppm)
    7. ctx["candidates"] = skills.run("library_search", ctx["peaks"], top_k=50)
    8. for c in ctx["candidates"]:
    9. pred = skills.run("bond_cleavage_sim", c.structure)
    10. c.support = evidence_score(pred, ctx["peaks"])
    11. report = auditor.render(ctx, include=["params", "paths", "scores"])

    4. Practical Gains in the Two Scenarios

    For molecules already in the library, the gains come mainly from automating retrieval and verification: candidate ranking, fragment consistency checks, and isomer exclusion can all be completed within a single session, with a clear efficiency improvement.

    For entirely new molecules, the value of the skill set lies in “shrinking the search space”: exact mass and elemental constraints first converge the molecular formula to a small set of candidates, then bond cleavage simulation determines which structural fragments are supported by the available fragment ions, which yields a direction for the next experiment (for example, which polarity of fragmentation conditions needs to be added). What it outputs is a grounded hypothesis, not a final answer, and the report must state this explicitly.

    5. Evaluation Criteria and Cost: Accuracy Is Not the Only Metric

    In the source material, after connecting the skill set, all three models reached roughly 97% accuracy, and the lightweight model matched the precision of the more capable ones. At the same time, generated token consumption per interaction round dropped significantly, with the largest reduction on the lightweight model. Two engineering conclusions follow: first, deterministic tools carry the numerical and retrieval burden while the model only handles planning and explanation, so outputs get shorter and rework decreases; second, the capability ceiling is determined more by the quality of the tool chain than by model size.

    An evaluation design should fix three classes of variables: spectral quality tiers (signal-to-noise ratio, co-elution interference), tolerance settings, and candidate library version. The metrics should report false negative rate, false positive rate, and manual review time together, because missing one spectrum and returning a wrong structure carry entirely different costs.

    6. Deployment Recommendations

    On Baidu AI Cloud, the skill operators can run on a container platform, raw spectra and reports can be stored in object storage, a message queue can decouple long-running tasks, and logging and monitoring with alerting can track the duration and failure cause of each interpretation run. Keep the skill layer stateless and versionable, retain a human confirmation node in the orchestration layer, and enable the audit layer by default. This way, routine small tasks (denoising, peak annotation, isomer comparison) can be reused independently, the full pipeline can run unattended, and a chemist’s review always has evidence to stand on.