A synchrotron beamline is a strange place to spend a Tuesday at three in the morning. Beam time is precious, booked months ahead, and the clock does not stop for a tired researcher nudging motors a fraction of a degree at a time to line up a crystal no wider than a hair.
That lining up, working out how a crystal is oriented before any real measurement can even begin, can eat hours of an experiment nobody gets back. A team from Stanford, the SLAC accelerator laboratory, and half a dozen universities decided to hand the job to a language model, and then let it loose on a real machine.
Key points
- The team built an agent driven by a large language model that autonomously aligns a single crystal on a synchrotron beamline, planning actions, issuing instrument commands, reading the results, and iterating toward the goal.
- It reaches the instrument through the Model Context Protocol, the same structured tool use mechanism that lets modern agents call external functions, so the model never touches the hardware directly.
- Developed and tested first in a virtual beamline simulator, the agent was then deployed on a real machine at the SLAC synchrotron, where it correctly found reference reflections and determined the crystal orientation.
- When it hit an unexpected motor offset of about one and a quarter degrees, caused by an uneven sample holder, it noticed the discrepancy, corrected for it, and reused that correction in later steps.
- Across benchmarks, the approach aligned samples reliably in most runs, though performance dropped when the agent was given a smaller reasoning budget, which is a pointed lesson about where the intelligence actually lives.
The unglamorous bottleneck of big science
Facilities like synchrotrons and free electron lasers are among the most powerful scientific instruments ever built, and they are chronically oversubscribed. Researchers compete for slots measured in hours, travel across the world to use them, and then spend a frustrating slice of that time on setup rather than science. One of the most common setup chores is sample alignment, figuring out the orientation of a crystal so the beam can be aimed at the exact atomic planes a measurement needs.
This is fiddly, expert work. A crystal arrives in an unknown orientation, and the scientist has to navigate a space of possible angles using several motorized stages, hunting for the sharp diffraction peaks that reveal how the lattice is turned. Motors have limits, some positions risk collisions, and real samples come with quirks like hidden offsets and uneven mounting. It is exactly the kind of multi step task under uncertainty that resists a simple script, because every crystal misbehaves in its own way.
That is what makes it a good testbed for an agent. The problem has a clear goal, real physical constraints, and enough surprises that a fixed recipe fails. If a language model can handle this, it can plausibly handle a great deal of the routine operation that currently ties up human experts. The wider push toward autonomous laboratories and self driving experiments has been building for years, and this work plants a flag squarely on the hard, practical end of it.
How the agent reaches the instrument
The design keeps a clean separation between thinking and doing. The language model does the reasoning. A structured tool layer does the acting. The two are joined by the Model Context Protocol, an increasingly common way to give an agent a menu of external functions it can call in a controlled, predictable format. If you have followed the recent wave of agent tooling, our explainer on where agentic AI reliability still lags covers the same protocol and the same tension between autonomy and trust that runs through this paper.
Through that protocol the agent gets a small, well defined toolbox. It can read the current motor positions and limits, move motors to chosen angles, take a detector image with a set exposure, run a linear scan of a motor, calculate the motor angles for a given lattice reflection, and register a found peak as a reference. In the virtual setup these commands run against a simulator. On the real machine they map to the actual beamline control software, the same command language a human operator would type.
One detail matters more than it first appears. The agent does not receive raw numbers from the detector. It is handed the detector image as a picture and the scan results as rendered plots with fitted curves, and it interprets them qualitatively, the way a person glancing at a screen would. The model reasons over what it sees, decides the next move, and issues the command, then looks again. That loop of look, reason, act, and look again is the whole method.
The language model never drives the hardware directly. It reasons, then calls tools through a structured protocol, and reads back images and plots rather than raw data. The intelligence sits in the interpretation and the choice of the next action, not in any new learning algorithm.
Learning to walk in a simulator first
Turning a language model loose on a machine that can physically crash its own motors is a bad idea, so the team did the sensible thing and built a virtual beamline first. The simulator mirrors a six circle diffractometer, a standard instrument with two motors that move the detector and four that rotate the sample, and it generates realistic detector images and scan results in response to the agent commands. Inside this safe sandbox the agent could fail, learn the workflow, and be tested across many randomized situations without any risk to real equipment.
The workflow the agent follows has three stages. Set up by reading the sample and instrument information, find and optimize a first reference reflection, then find and optimize a second one. With two reference reflections pinned down, the orientation of the crystal is fully determined. Crucially, this workflow is a scaffold, not a script. The high level goal and the available tools are specified, but the agent decides on its own which peaks to chase, when to move between stages, and how to configure each scan based on what it is seeing.
The geometry the agent is reasoning about
Underneath the friendly commands sits real crystallographic geometry. The orientation of the sample is a product of rotation matrices, one for each sample motor, and the detector has its own pair.
A diffraction peak appears when the beam meets a lattice plane at the right angle, which happens when the scattering vector lines up with a direction in the crystal. That vector is fixed by the beam and the detector geometry.
To score how well the agent did, the authors compare the orientation it found against the true one and measure the angle between them.
What the benchmarks showed
In the simulator the team tested two different language models, an Anthropic model and a Google one, across ten randomized runs each, with hidden motor offsets thrown in to make life hard. Both aligned the sample successfully in the large majority of cases, keeping the orientation error below five degrees for most runs, and both estimated the trickier lattice parameter accurately in more than half the trials.
| Scenario | Model | Successful alignments |
|---|---|---|
| Baseline, virtual | Claude Sonnet 4 | 10 of 10 |
| Baseline, virtual | Gemini 2.5 Flash | 10 of 10 |
| Larger motor offsets | Gemini 2.5 Flash | 3 of 5 |
| Multiple grains | Gemini 2.5 Flash | 5 of 5 |
| Reduced reasoning budget | Gemini 2.5 Flash | 4 of 5 |
| Real beamline | Claude Opus 4 | Aligned two crystals, adapting to a hidden offset |
The stress tests are where it gets interesting. The agent held up well against multiple competing crystal grains, a genuinely confusing situation. It struggled more when motor offsets grew large, and, most tellingly, its success rate dropped when the reasoning budget was cut down. Give the model less room to think and it makes worse decisions, which is a blunt reminder that the capability here comes from the reasoning, not from any clever wrapper around it. The failures also clustered around the hardest single step, centring a broad diffraction peak, rather than the bookkeeping that follows once a peak is found.
The moment on the real machine
A simulator can be gamed. A real beamline cannot, and this is where the work earns its keep. The team deployed the agent on an operational instrument at the SLAC synchrotron, using a more capable model to maximize robustness, and gave it a magnetic crystal to align. The only human involvement was a safety intermediary who relayed each proposed command to the control terminal without changing it, then told the agent to read the log and continue. Every decision was the agent own.
The agent reasoned its way in from first principles. Noting that the crystal had one much longer axis, it guessed that this axis pointed along the surface normal and picked a sensible first reflection to hunt for, then moved the motors to the calculated angles and took an image. Standard so far. Then reality intervened.
The peak was not where it should have been. Because the crystal sat on a slightly uneven copper holder, there was a hidden offset of about one and a quarter degrees in one of the motors. A brittle script would have missed the peak and stalled. The agent instead found the peak nearby, recognized that the gap between expected and actual position was a real offset, corrected for it, and, importantly, remembered that correction and applied it in the steps that followed. It then found a valid second reference reflection and completed the alignment. It repeated the feat on a separate silicon crystal that had an even larger offset and extremely sharp peaks.
Our AI X-ray scientist responded effectively to unexpected experimental conditions, demonstrating adaptive problem solving and readiness for addressing practical experimental situations. Chen and colleagues, Nature Machine Intelligence, 2026
That short term experimental memory, holding onto a discovered quirk and reusing it, is the behaviour that separates a genuine assistant from a lookup table. It is the same capability that agent researchers probe in controlled settings, as our look at benchmarking the memory of learning agents explores, showing up here in a messy real world task rather than a game.
Where it falls short
The authors are careful not to oversell, and a fair reading has to sit with the limits.
The real beamline demonstration, striking as it is, was a small number of runs rather than a controlled statistical study. It shows the behaviour is possible, not how often it succeeds across many samples and conditions. The virtual benchmarks give firmer numbers, but a simulator is always a simplification, and the gap between the two is exactly where surprises live. The single successful adaptation to a hidden offset is a proof of concept, not an established reliability figure.
The safety story also deserves honesty. A human stayed in the loop to relay commands, precisely because letting a language model send unfiltered instructions to motors that can collide is not yet safe. The agent had autonomy over decisions but not over execution, and closing that last gap for genuinely unattended operation is a serious engineering and safety problem, not a detail. The command parsing itself leaned on keyword matching that the authors admit can be brittle.
Finally, the intelligence is rented, not owned. The system rides on general purpose models developed elsewhere, and its behaviour inherits their strengths and their failure modes, including the sharp drop in quality when reasoning is constrained. The paper is candid that it introduces no new learning algorithm. Its contribution is showing that existing reasoning models, wired to an instrument through disciplined tool use and good guidance, can carry out a real multi step experiment. That is a systems achievement rather than a modelling one, which is both its charm and its ceiling.
Why it matters
Step back and the significance is less about crystals than about a template. The recipe here, wrap a reasoning model in a safe tool interface, teach it the workflow through documentation rather than code, test it exhaustively in simulation, then deploy it with a human safety net, is not specific to beamlines. It could point at any complex instrument that currently demands an expert babysitter, from electron microscopes to neutron sources to chemistry robots. The authors frame their agent as a collaborator that lowers the barrier to using these rare, expensive facilities, and that framing feels right.
The deeper appeal is that the hard part was made boring on purpose. Rather than invent new machinery, the team operationalized what already exists, and in doing so they surfaced the practical questions that actually gate autonomous science, questions about safety, reliability under stress, and how much of the outcome hinges on the reasoning budget you are willing to pay for. Those are the questions the field has to answer before an agent can run an experiment unattended, and this work asks them on a real machine rather than a whiteboard. For a broader view of how language models are moving into materials research specifically, our piece on multimodal models for materials science covers a complementary front.
A reference implementation
Because this system uses existing language models and trains no network of its own, a fabricated neural network with a training loop would misrepresent the work. The code below instead implements the paper genuine computational core in plain Python, the six circle diffractometer geometry, the scattering vector, the alignment error metric, and a simulated agent loop that scans a motor, finds the peak, and moves to it, mirroring the look, reason, act cycle. The authors full code is linked under the block.
# Agentic X-ray alignment, faithful reference for the paper computational core # Six circle diffractometer geometry plus a simulated peak seeking agent loop. # No neural network is trained. The real system wraps an existing LLM in tools. import numpy as np def rot_z(a): c, s = np.cos(a), np.sin(a) return np.array([[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]]) def rot_y(a): c, s = np.cos(a), np.sin(a) return np.array([[c, 0.0, s], [0.0, 1.0, 0.0], [-s, 0.0, c]]) def sample_orientation(phi, chi, eta, mu): # product of the four sample motor rotations, R_sample = M H X Phi return rot_y(mu) @ rot_z(eta) @ rot_y(chi) @ rot_z(phi) def scattering_vector(two_theta, wavelength): # Q = (2 pi / lambda) (k_out - k_in), beam along x, scattering in the xz plane k_in = np.array([1.0, 0.0, 0.0]) k_out = np.array([np.cos(two_theta), 0.0, np.sin(two_theta)]) return (2.0 * np.pi / wavelength) * (k_out - k_in) def alignment_error(R_pred, R_true): # rotation angle between two orientation matrices, in degrees m = 0.5 * (np.trace(R_pred @ R_true.T) - 1.0) m = np.clip(m, -1.0, 1.0) return np.degrees(np.arccos(m)) def detector_intensity(eta, peak_center, width=0.05, hidden_offset=0.0): # a synthetic peak the simulated detector would report during an eta scan return np.exp(-0.5 * ((eta - (peak_center + hidden_offset)) / width) ** 2) def agent_align_eta(expected_center, hidden_offset, span=2.0, points=81): # mimic the look, reason, act loop, scan eta, read the plot, move to the peak grid = np.linspace(expected_center - span, expected_center + span, points) signal = detector_intensity(grid, expected_center, hidden_offset=hidden_offset) found = grid[int(np.argmax(signal))] # the fitted peak centre offset = found - expected_center # the agent notices the gap return found, offset if __name__ == "__main__": wavelength = 0.7749 # angstrom, as at the real beamline two_theta = np.radians(20.4004) # the (0, 0, 6) reflection q = scattering_vector(two_theta, wavelength) print(f"scattering vector magnitude {np.linalg.norm(q):.4f}") # the crystal sits on an uneven holder, a hidden 1.22 degree eta offset expected_eta = 10.2002 hidden = 1.22 - (10.2002 - 8.9845) # matches the reported case found, offset = agent_align_eta(np.radians(expected_eta), np.radians(1.22)) print(f"agent moved eta to {np.degrees(found):.4f} deg, offset {np.degrees(offset):.4f} deg") # score a nearly aligned prediction against the truth R_true = sample_orientation(0.1, 0.2, 0.15, 0.0) R_pred = sample_orientation(0.1, 0.2, 0.15 + np.radians(1.0), 0.0) print(f"alignment error {alignment_error(R_pred, R_true):.3f} deg")
Go to the source
Read the peer reviewed paper and run the authors own code and data.
Read the paper Code on ZenodoConclusion
The core achievement here is a language model agent that ran a real scientific instrument. It planned an alignment, issued the commands, read the detector images and scans, adapted to a hidden offset it was never told about, and determined the orientation of a crystal on an operational synchrotron beamline. It did this by reasoning over what it saw and calling tools through a structured protocol, with no new learning algorithm underneath.
The conceptual shift worth remembering is that the interesting engineering was in the plumbing and the guidance, not in the model. By pairing a capable reasoning model with a safe tool interface, teaching it the workflow through documentation rather than hard coded steps, and validating it in simulation before touching real hardware, the team turned a general purpose model into a competent operator for one demanding task. The moment it caught its own motor offset and carried the correction forward is the clearest sign that it was reasoning about the experiment rather than replaying a recipe.
The approach travels because nothing about it is specific to crystals. Any oversubscribed instrument that currently needs an expert to babysit setup is a candidate, and the template of simulate, then deploy with a human safety net, is a responsible path to get there. The authors are right to frame their agent as a collaborator that widens access to rare facilities rather than as a replacement for the scientists who use them.
The honest limits keep the excitement measured. The real world evidence is a handful of runs rather than a reliability statistic, a human still relays every command for safety, the command parsing is brittle in places, and the whole system inherits the strengths and weaknesses of the borrowed model, including a sharp fall in quality when its reasoning is starved. These are not fatal flaws, but they are exactly the gaps that stand between a promising demonstration and an instrument you would trust to run unattended overnight.
Future directions follow naturally. Harden the tool interface so a human no longer has to relay commands, gather enough runs to turn anecdote into a reliability figure, and build meta agents that help write and refine the guidance for new instruments. If those steps hold up, the tired researcher squinting at a detector at three in the morning might finally get to sleep, and the beam time they fought for could go to the science instead of the setup.
Frequently asked questions
What does the AI agent actually do?
It autonomously aligns a single crystal on a synchrotron beamline. It plans the steps, issues instrument commands to move motors and take detector images, reads the results, and iterates until it has determined how the crystal is oriented, which is a prerequisite for many scattering experiments.
Does the language model control the hardware directly?
No. The model reasons and then calls a small set of tools through the Model Context Protocol, a structured way to expose external functions. On the real beamline a human also relayed each command to the control terminal as a safety measure, without changing the agent decisions.
What happened when it met an unexpected offset?
A crystal sat on a slightly uneven holder, creating a hidden offset of about one and a quarter degrees in one motor. The agent found the peak nearby, recognized the discrepancy as a real offset, corrected for it, and reused that correction in later steps, showing adaptive reasoning and short term memory.
Which language models were used?
In the virtual benchmarks the team tested an Anthropic model and a Google model across many randomized runs. For the more demanding real beamline demonstration they used a more capable Anthropic model to maximize robustness.
Is this a medical X-ray system?
No. The X-rays here come from a synchrotron and are used to study the atomic structure of materials through scattering. The work is about autonomous scientific experimentation, not medical imaging or diagnosis.
Can the code and data be reproduced?
Yes. The authors released their source code and data on Zenodo under an open licence, so the virtual beamline experiments and the analysis can be reproduced and extended.
