Deterministic agent-guided scarf analysis - #182
Merged
parashardhapola merged 22 commits intoSep 11, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Gautam8387
marked this pull request as ready for review
September 1, 2026 13:13
Gautam8387
marked this pull request as draft
September 1, 2026 13:48
Gautam8387
marked this pull request as ready for review
September 7, 2026 11:06
Gautam8387
marked this pull request as draft
September 7, 2026 20:59
Gautam8387
marked this pull request as ready for review
September 9, 2026 01:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a bounded, agent-guided workflow for one RNA assay.
analyze_rna()combines study context with measured dataset evidence to:The model cannot generate arbitrary analysis code or call unrestricted
DataStoreoperations. It selects from registered choices whose execution and validation remain controlled by Scarf.Architecture at a glance
flowchart LR API["analyze_rna()"] --> O["AgentOrchestrator"] O --> C["Bounded model control plane"] C --> V["Typed outputs<br/>closed choices<br/>validation gates"] V --> E["Scarf scientific executors"] O --> J["Append-only workflow journal"] E --> A["Immutable Zarr artifacts"] J --> A A --> R["AutomatedWorkflowResult"] R --> U["Final UMAP"] R --> M["Markers"] R --> H["HTML report<br/>no new model calls"]What deterministic means
"Deterministic" describes the execution and replay boundary around the model:
This does not guarantee identical LLM output on a new workflow. Temperature zero and seed 4444 are requested from the provider, but providers may still produce different valid responses. A new destination can therefore follow a different valid branch. The strongest claim is deterministic execution and replay after a decision has been committed, not bit-identical LLM reasoning.
Agent and model inventory
Scarf does not select or construct a provider model. The caller supplies one Pydantic AI model, which is shared across the workflow. Each model invocation creates a short-lived Pydantic AI agent with bounded requests, tools, tokens, retries, and timeout. Thinking is disabled and tool calls are sequential by default.
The automated workflow uses:
DataEnrichmentAgent: inspects species, feature families, controls, and assay roles.ExperimentalContextAgent: establishes captures, independent units, covariates, confounding, QC evidence, and whether Harmony is scientifically licensed.AgentOrchestratorand most ofRnaTuningRunare controllers and executors, not LLM agents.Two domain agents remain standalone and are not part of
analyze_rna():ParameterTuningAgentBiologicalInterpretationAgentAgent hierarchy
flowchart TB M["Caller-supplied Pydantic AI model"] --> O["AgentOrchestrator<br/>deterministic stage controller"] O --> I["Conditional ingest decision"] O --> D["DataEnrichmentAgent"] O --> X["ExperimentalContextAgent"] O --> Q["QC grouping and cell-quality decisions"] O --> T["RnaTuningRun"] T --> S0["Screening assessment"] T --> S1["Optional enlarged-screen assessment"] T --> F["Full-cohort assessment"] I --> K["Shared model execution and validation"] D --> K X --> K Q --> K S0 --> K S1 --> K F --> K subgraph Standalone["Standalone APIs"] P["ParameterTuningAgent"] B["BiologicalInterpretationAgent"] endAutomated workflow
flowchart TD A["Source, model, study context, objective"] --> B{"Matching journal exists?"} B -->|Yes| R["Resume or reuse committed work"] B -->|No| I["Validate and ingest source"] I --> E["Data enrichment<br/>model-guided"] E --> Q["RNA QC metrics<br/>deterministic"] Q --> C["Experimental context<br/>design and correction license"] C --> P["Preprocessing decisions and execution"] P --> S["Seeded screening cohort<br/>10%, bounded to 10k-100k"] S --> T["Compare registered alternatives<br/>HVG, PCA, neighbors, partitions"] T --> D{"Agent assessment"} D -->|Combine or experiment| T D -->|Enlarge| S2["One larger nested screen"] S2 --> T D -->|Defer| N["Pause or fail with unresolved evidence"] D -->|Accept| F["Full-cohort validation"] F --> H["Matched native/Harmony evaluation<br/>when correction is licensed"] H --> Z["Finalize graph, clusters, UMAP, and markers"] Z --> G["Generate report from saved evidence"]Screening compares 1,000, 2,000, and 4,000 variable genes; 10, 21, and 30 PCs; 11, 21, and 41 neighbors; and four Leiden resolutions. Selected settings are then executed and assessed on the complete QC-retained cohort.
Current limitations
score_doublets=Falseskips scoring when Harmony is unavailable or prohibited. Harmony-eligible workflows still calculate matched doublet evidence. Scores are advisory and never remove cells.Future doublet-removal path
A removal workflow should:
A global threshold should not be applied silently because score distributions and expected doublet rates depend on capture conditions.
Accuracy notes found during review:
analyze_rna()call leavesscore_doublets=False; scoring is therefore conditional on Harmony eligibility.execution_status.json, but Scarf itself does not create that file.