A LangGraph-orchestrated agentic pipeline that runs a complete single-cell RNA-seq (scRNA-seq) analysis from raw count matrix to annotated cell types and a self-contained HTML report. What makes it technically interesting is the combination of a stateful multi-node graph (LangGraph), three embedded LLM decision points where the model reasons over biological data and recommends analysis parameters, a CellTypist automated annotation layer that the LLM adjudicates against marker gene evidence, and a human-in-the-loop (HITL) CLI gate that lets you override any LLM recommendation before execution continues.
The pipeline is a 14-node StateGraph. AnnData objects are never held in memory between nodes; each node reads a checkpoint from disk, transforms it, and writes the next checkpoint. This keeps state JSON-serializable and makes mid-run crash recovery trivial.
START
-> data_loader load .h5ad or download PBMC 3k
-> qc_metrics compute per-cell QC statistics
-> qc_advisor [LLM 1] recommend min/max gene and count thresholds
-> human_review_qc CLI gate: accept or override thresholds
-> filter_cells apply thresholds, remove low-quality cells
-> normalize normalize to 10k counts, log1p, store raw
-> hvg_select select 2000 highly variable genes, scale
-> dim_reduction PCA(50), neighbor graph, UMAP
-> cluster Leiden clustering at configured resolution
-> cluster_advisor [LLM 2] evaluate cluster count, recommend resolution
-> human_review_clustering CLI gate: accept or override resolution
-> marker_genes Wilcoxon rank-sum, top-10 markers per cluster, dotplot
-> annotate_celltypist CellTypist automated cell type prediction
-> annotate_llm [LLM 3] adjudicate CellTypist vs marker gene evidence
-> human_review_annotation CLI gate: review uncertain clusters
-> report_generator final AnnData, UMAP, HTML report, summary.json
-> END
Three LLM decision points:
- QC advisor (node 3): receives distribution statistics for n_genes, total_counts, and pct_mito; recommends biologically justified filter thresholds with written reasoning.
- Cluster advisor (node 9): receives cluster count and current resolution; recommends whether to increase or decrease resolution and by how much.
- Annotation adjudicator (node 13): cross-references CellTypist predictions with top Wilcoxon marker genes per cluster; produces a final label, confidence score, and an uncertainty flag for human review.
Every LLM call is logged with its full prompt, raw response, parsed output, and whether the recommendation was accepted or overridden. The complete audit trail is written to summary.json.
Prerequisites: Docker and Docker Compose. An Anthropic API key (or an OpenRouter key pointed at the same endpoint).
Step 1: Clone and configure
git clone https://github.com/YOUR_USERNAME/scrna-agent.git cd scrna-agent cp .env.example .env # Edit .env and set ANTHROPIC_API_KEY=your-key-here
Step 2: Build the container
docker compose build
Step 3: Run the pipeline on PBMC 3k
docker compose run --rm scrna-agent
The pipeline downloads the PBMC 3k dataset automatically on first run and caches it in data/raw/. It pauses three times for HITL review; press Enter each time to accept the LLM recommendation. Outputs land in outputs/reports/report.html and outputs/reports/summary.json.
Run the complete pipeline with deterministic pre-scripted LLM responses and no stdin prompts:
docker compose run --rm scrna-agent --mock-llm --no-hitl
This is useful for verifying the pipeline structure, testing the output format, and running in CI without spending API credits.
The pipeline is configured via a YAML file. The default is config/pbmc3k.yaml:
llm: qc_advisor_model: "claude-haiku-3-5-20251001" cluster_advisor_model: "claude-haiku-3-5-20251001" annotation_model: "claude-sonnet-4-6" qc: max_mito_pct: 5.0
Pass a different config file with --config path/to/config.yaml. To analyze your own dataset, pass --input path/to/your_data.h5ad.
| File | Location | Description |
|---|---|---|
final.h5ad |
outputs/checkpoints/ |
Fully annotated AnnData |
umap.png |
outputs/figures/ |
UMAP colored by cell type |
violin_qc_prefilt.png |
outputs/figures/ |
QC distributions before filtering |
violin_qc_postfilt.png |
outputs/figures/ |
QC distributions after filtering |
dotplot_dotplot.png |
outputs/figures/ |
Marker gene dot plot |
report.html |
outputs/reports/ |
Self-contained HTML report (no external requests) |
summary.json |
outputs/reports/ |
Full pipeline summary with LLM audit trail |
run.log |
outputs/ |
Structured log including all LLM prompts and responses |
- LangGraph: graph-based pipeline orchestration; each node is a pure function on
AgentState - Scanpy: QC metrics, normalization, HVG selection, PCA, UMAP, Leiden clustering, Wilcoxon marker genes
- CellTypist: pretrained immune cell type classifier (Immune_All_Low model)
- Anthropic API: LLM backend for the three advisory nodes; prompt caching enabled on all static system prompts
- Jinja2: HTML report templating with base64-embedded figures (no CDN dependencies)
- Docker: reproducible containerized execution
docker compose run --rm --entrypoint pytest scrna-agent tests/ -v
139 tests covering all 14 nodes, the LLM client, mock responses, HITL edge cases, and state validation.