arXiv:2608.26198cs.AIAug 2026

Manuscript Offprint

arXiv:2608.26198

Agentic AI for operating scientific instruments for nanoscale characterization

Zahra Ayar, Marcos Penedo, Mahdi Mehdikhani, Nahid Hosseini, Prabhu Prasad Swain, Georg E. Fantner

Abstract

Operating a scientific instrument such as an atomic force microscope (AFM) requires continuous expert decision-making. A trained user defines the experimental intent, translates it into instrument commands, assesses incoming data, adjusts imaging parameters, and post-processes the final image. Existing automation usually addresses only parts of this workflow through hard-coded routines, task-specific controllers, or trained machine-learning models. Here we present an agentic-AI framework that operates the executable part of the AFM workflow using a general-purpose, tool-augmented large language model connected to instrument functions through the Model Context Protocol (MCP). The framework consists of three MCP-based agents: AFM Messenger converts natural-language instructions into checked instrument commands; AFM Pilot assesses image quality through a large language model (LLM) and, if necessary, adapts imaging parameters; and AFM Doctor diagnoses image artifacts and applies transparent post-processing from a pre-approved tool set. Because the language model performs image assessment rather than a fixed scalar objective or external optimizer, the same strategy can be applied across sample types and imaging modes without specific retraining. Safe hardware operation is enforced through an ambiguity check layer before execution. Benchmarking against fine-tuned and off-the-shelf tool-using models shows that this guarded execution layer, rather than model capability alone, reduces wrong-command execution to zero. In live experiments on different samples, AFM Pilot matched expert operators in image quality, iteration count, and tuning time, with no significant difference. These results demonstrate a safe route to agentic operation of scientific instruments, where experimental intent remains human-defined while command execution, image-based tuning, and post-processing are delegated to AI agents.

Keywords: agentic AI, tool-augmented LLMs, Model Context Protocol (MCP), automated microscopy, atomic force microscopy (AFM), closed-loop parameter tuning, failure analysis, ambiguity handling, artifact diagnosis, human-in-the-loop control

1. Introduction

Artificial intelligence is increasingly transforming how experiments are designed and executed, moving from tools that assist single steps toward agents that plan and carry out multi-step scientific work 1−5^{1-5}. This marks a transition from AI for science toward agentic science, in which autonomous systems in chemistry 5−7^{5-7}, materials synthesis 5,8−10^{5,8-10}, and laboratory robotics 11−13^{11-13} can coordinate instruments and interpret their own results. These examples point to a broader opportunity: using AI not only to analyze scientific data after acquisition, but to operate the physical instruments that generate those data.

Microscopy and imaging are natural areas for this transition because acquiring an image is not simply a passive recording step, but an active experimental process. Conventional machine-learning methods have been used in X-ray imaging 14^{14}, optical microscopy 15,16^{15,16}, and electron microscopy 17,18^{17,18}, to support automated acquisition, reconstruction, analysis, or experimental decision-making. In scanning probe microscopy, earlier approaches used trained machine learning models to guide the measurement area 19^{19}, tune imaging conditions 20^{20}, and apply methods to autonomous operation 21^{21} and data analysis 22^{22}. These studies show the potential of automation in microscopy, but most existing systems still address selected parts of the workflow. They typically depend on a task-specific model, reward function, or control routine, and do not fully address the complexity of imaging tasks.

Atomic force microscopy (AFM) 23^{23} exemplifies both the need and the difficulty. Image quality depends on feedback and scan parameters that must be adjusted continuously as the tip, sample, and feedback response change between different experiments. Artifacts such as parachuting 24^{24}, feedback ringing 25^{25}, hysteresis 26,27^{26,27}, creep 26,27^{26,27}, double-tip 28^{28}, and loss of surface tracking require different corrective actions, with trade-offs between image quality, scan speed, and sample safety 29−31^{29-31}. Although conventional automation and task-specific machine learning have addressed parts of this workflow, the image-driven assessment needed to connect command execution, parameter tuning, and post-processing has largely remained human. This makes AFM a natural test case for agentic instrument control.

Large language models (LLMs) have recently begun to be explored for microscopy operation and automated experiment design 32^{32}. Two architectural strategies are particularly relevant. In the first, a model is fine-tuned 33−35^{33-35} on instrument-specific data to generate instrument commands directly. This embeds instrument knowledge in the model weights, but requires preparing large prompt-response datasets and retraining whenever the instrument software or base model changes. It also offers limited protection against silent execution errors 13,32^{13,32}. In the second, a general-purpose model is connected to predefined functions through a structured interface such as the Model Context Protocol (MCP) 36−38^{36-38}. In this architecture, tool selection is explicit. At the same time, unit definitions, required parameters, and clarification rules can be enforced outside the model. The MCP approach needs only a description of the available tools and their parameters, which can be written in hours and reused across models without retraining.

The most comprehensive prior demonstration of LLM-operated AFM is that of Mandal et al. 39^{39}, whose artificially intelligent lab assistant (AILA) used off-the-shelf models with LangChain/LangGraph orchestration. In that system, the LLM interpreted tasks and experimental outputs, while a genetic algorithm optimized image quality by tuning proportional–integral–derivative feedback gains to maximize trace-retrace structural similarity. The study also raised important safety concerns, reporting about 65% of task success for the best model and showing that ambiguous instructions could lead to erratic or incorrect commands. Building on this foundation, we asked whether an LLM-based agent can move beyond workflow coordination to directly assess AFM image quality and select corrective actions from the acquired data.

In this work, we try to replace the human AFM expert in some aspects of the AFM imaging workflow with agentic AI. We present an MCP-based agentic AFM system that translates human natural-language commands into instrument actions, evaluates AFM images and associated experimental data using the multimodal vision-language capabilities of the LLM (hereafter, "AI-vision"), and adjusts imaging parameters without relying on a conventional control model or a fixed scalar optimization metric.

We implemented this framework for AFM through three cooperating agents: AFM Messenger for communicating with AFM hardware, AFM Pilot for closed-loop image parameter optimization, and AFM Doctor for artifact diagnosis and transparent post-processing. We benchmark the execution layer, test live agentic imaging, and compare its operation with expert practice. Because incorrect or ambiguous commands can damage the probe, sample, or instrument, the execution layer checks each request before acting and asks for clarification when the prompt is underspecified. We frame this deliberately as agentic operation of a scientific instrument, not a self-driving laboratory, where the experimental intent remains with the human, but the agentic system carries out command execution, imaging parameter tuning, and post-processing.

References (28)