Using LLM Agents for Scientific Computing: Single-Cell Data Analysis in Practice

    This article explains how large language model (LLM) agents can organize a complete single-cell transcriptomics analysis, from data loading and quality control to cell annotation, trajectory inference, and differential expression. It covers the agent's role in task planning, tool orchestration, and result interpretation, presents a pseudocode framework with validation and logging, reviews common risks such as hallucinated annotations, over-automation, and data security, and outlines a phased rollout plan for research teams.

    1. Background: A New Stage of AI for Science

    AI for Science refers to applying artificial intelligence methods across the stages of scientific research, including hypothesis generation, experimental design, data analysis, and result interpretation. In recent years, the reasoning and planning abilities of large language models have improved. This allows them to receive research questions in natural language and call specialized tools to complete multi-step tasks. Such systems are commonly called research agents.

    For R&D teams, the focus has shifted from “Can the model answer the question?” to “Can it reliably complete an entire analysis pipeline?” Scientific data involves long workflows, many intermediate outputs, and sensitive parameters. An error at any stage propagates to the final conclusion. Solution design therefore needs to balance automation efficiency with process traceability.

    2. The Role of Agents in Research Workflows

    In a typical research analysis, an agent mainly handles three types of work:

    • Task understanding: converts the researcher’s natural language goal into a structured analysis plan that specifies the data type, analysis objectives, and expected outputs.
    • Tool orchestration: calls data processing, statistical analysis, and visualization modules according to the plan, and schedules execution based on dependencies.
    • Result interpretation: summarizes outputs from each step, drafts conclusions related to the research question, and labels the source of each piece of evidence.

    An agent should not replace expert judgment. Its output is an intermediate conclusion that can be reviewed, and researchers must still confirm the final interpretation.

    3. A Typical Single-Cell Analysis Workflow

    Single-cell transcriptomics analysis is a good example of how agents add value. These datasets often contain thousands or even tens of thousands of cells, with each cell corresponding to expression counts for thousands of genes. The analysis steps are highly standardized, but parameter choices at each step still have a large effect. A typical workflow includes the following stages:

    1. Data loading and format checks: confirm that matrix dimensions, gene identifiers, and sample metadata are complete.
    2. Quality control: filter abnormal cells based on the number of genes per cell, total counts, and mitochondrial gene proportion. Thresholds should be adjusted for tissue type and experimental batch rather than applied as fixed values.
    3. Normalization and feature selection: remove differences in sequencing depth and select highly variable genes for downstream dimensionality reduction.
    4. Dimensionality reduction and clustering: use principal component analysis for initial dimensionality reduction, then partition cells into populations using a neighborhood graph and community detection algorithms.
    5. Cell type annotation: combine known marker genes, reference databases, and literature to assign biological labels to each cell population.
    6. Trajectory inference: follow the continuous direction of cell state changes to build a pseudotime sequence that describes developmental or differentiation processes.
    7. Differential expression and candidate gene selection: compare expression between key populations or time points, and rank genes using both statistical significance and effect size.

    Each step produces intermediate files and parameter records. Without these records, results are hard to verify and difficult to reproduce when applied to new data.

    4. An Illustrative Implementation Framework

    The pseudocode below shows how an agent can organize the workflow above into an auditable task chain. It illustrates structure only. Each function should be replaced with the team’s own analysis modules.

    1. function run_single_cell_pipeline(matrix, metadata, question):
    2. plan = agent.parse_goal(question) # Break the research question into a list of steps
    3. state = {"input": matrix, "params": {}, "log": []}
    4. for step in plan.steps:
    5. params = agent.propose_params(step, state) # Propose parameters based on data characteristics
    6. result = tools.run(step.name, state["input"], params)
    7. check = validate(result, step.expected) # Check dimensions, missing values, and distributions
    8. state["log"].append({"step": step.name, "params": params, "check": check})
    9. if not check.passed:
    10. state = pause_for_review(step, result) # On failure, pause and let researchers decide
    11. continue
    12. state["input"] = result.output
    13. report = agent.summarize(state["log"], state["input"])
    14. return report

    This structure has three design principles. First, the agent proposes parameters, but every run is written to a log for later traceability. Second, the validation function is separate from the execution function, which prevents the assumption that a program that runs to completion has passed. Third, when an anomaly occurs, the pipeline pauses rather than bypassing it automatically, so critical decisions stay in the human review step.

    5. Validating Results and Ensuring Reproducibility

    Conclusions generated by agents should pass several layers of verification:

    • Technical validation: check whether data dimensions, distribution shapes, and batch effects are reasonable, and whether key statistics match past experience.
    • Biological validation: check whether candidate genes are supported by literature and consistent with known pathways or marker genes.
    • Independent reproduction: rerun key steps with different random seeds or parameter combinations to see whether conclusions remain stable.

    Reproducibility depends on three records: the data version, the code and parameter version, and the runtime environment information. Missing any one of them makes later audits difficult.

    6. Common Problems in Practice

    1. Hallucination risk: the model may produce cell type annotations that look plausible but lack supporting evidence. Require each conclusion to include data evidence or a reference source, and mark anything that cannot be traced as pending verification.
    2. Over-automation: a pipeline that runs successfully does not mean its conclusions are correct. Key checkpoints, such as quality control thresholds and cell type annotations, should require human confirmation.
    3. Data security: research data often includes unpublished results or protected personal information. Deployments should limit data access scope and reduce leakage risk through permission management and data de-identification.
    4. Cost and time: agents make many calls and produce long outputs. Set call budgets and caching strategies based on task priority to avoid repeated computation.

    7. Practical Recommendations

    We recommend that teams proceed in three stages. In the first stage, select historical datasets with clear boundaries and verifiable results, and test whether the pipeline can reproduce known conclusions. In the second stage, formalize the validation and logging mechanisms as templates, then extend them to new data. In the third stage, with researchers involved, define review standards that specify which steps can run automatically and which require manual confirmation.

    The value of AI for Science lies in shortening the path from data to hypothesis. Efficiency gains and the credibility of research conclusions can only hold together when agents operate within a framework that is auditable, pausable, and reproducible.