How it is built
Architecture overview
An automated ML research system lets language-model agents do the loop a human researcher does: read the literature, propose a hypothesis, change code, run an experiment on GPUs, look at the numbers, decide what to try next, and write up what held. The agent part is the cheap part. The system around it is what turns an agent that writes plausible code into one that produces trustworthy results: a sandbox that contains it, a scheduler that gives it GPUs, a tracker that records exactly what ran, an experiment manager that spends the compute budget on promising branches, and an evaluator that does not trust the agent's own report. The one idea that makes it work is that every claim must trace back to a recorded run; an agent's text is a proposal, a logged metric from a hermetic run is evidence.
Published systems differ in how much of this they have. The AI Scientist (v1) ran a fixed pipeline from idea to LaTeX paper at a reported cost under $15 per paper. Its v2 dropped the human-written code templates and added an experiment manager agent steering a tree search. AIDE treats ML engineering as a tree search over code. Benchmarks such as MLE-bench, RE-Bench and PaperBench measure the result (see Sources).
Parts:
- Agent core — the loop that plans, calls tools and keeps its context useful — agent-loop (no page yet), task-planning (no page yet), subagent-orchestration (no page yet), Tool calling, Context window management, Prompt caching, Constrained decoding, JSON Schema validation, json-rpc (no page yet)
- Knowledge — literature search, citations, long-term memory of what was tried — Hybrid search and rank fusion, HNSW, Inverted index, Cross-encoder reranking, citation-grounding (no page yet), Text chunking, Text classification, agent-memory (no page yet), Memory consolidation, time-decay-scoring (no page yet), Entity resolution, record-linkage (no page yet), Near-duplicate detection (MinHash)
- Code workbench — understand a codebase and change it without breaking it — code-context-retrieval (no page yet), Code symbol indexing, trigram-index (no page yet), Regex engine, Incremental parsing, lossless-syntax-trees (no page yet), Language Server Protocol, edit-application (no page yet), Myers diff, Three-way merge, failure-bisection (no page yet)
- Sandbox — runs model-written code with no way out — agent-sandboxing (no page yet), microvm-isolation (no page yet), Process sandboxing, egress-proxy-filtering (no page yet), hermetic-execution (no page yet), Prompt injection defense, Human-in-the-loop approval
- Compute scheduler — queues experiments and places them on GPUs — Durable job queue, gang-scheduling (no page yet), priority-and-preemption (no page yet), topology-aware-placement (no page yet), Bin packing, GPU cloud, Graceful draining, resource-usage-accounting (no page yet), Leases, Fencing tokens
- Experiment manager — decides which runs to start, continue or kill — successive-halving-hyperband (no page yet), population-based-training (no page yet), scaling-laws (no page yet), levenberg-marquardt (no page yet), Monte Carlo tree search, Multi-armed bandits, Top-k selection, distributed-checkpointing (no page yet)
- Tracking and provenance — the append-only record of every run — experiment-tracking (no page yet), Segmented log, Object storage, Content-addressed storage, merkle-dag (no page yet), lttb-downsampling (no page yet)
- Workflow engine — keeps a long research campaign alive across crashes — Durable workflow execution, Topological sort, Event sourcing, record-replay (no page yet), Idempotency keys
- Evaluation — judges ideas, results and papers independently of the agent — LLM as judge, bradley-terry-model (no page yet), annotator-agreement (no page yet), Calibration, pass-at-k (no page yet)
literature index ─► idea generator ─► novelty check ─► plan (task DAG) ─┐
▲ ▲ ▼
agent memory ◄──── results + notes experiment manager (tree / halving / PBT)
▲ ▲ │ proposes run configs, kills weak runs
│ │ ▼
│ tracker (metrics, code hash, seeds) ◄── code workbench (edit, diff, test) ──► sandbox
│ ▲ │ job spec
│ └──────────── metrics, logs, checkpoints ◄── scheduler ◄─────────────────┘
│ (gang scheduling, GPU cloud)
└──── writer (grounded citations) ◄── judge / reviewer ◄── only logged results are citable
How the parts fit together
Agent core
The core is a loop: the model emits a structured tool call, the harness executes it, and the result goes back into the context. Calls must parse, so arguments are checked against a schema (JSON Schema validation) and, where the model server supports it, generation is forced to match (Constrained decoding). Tools reach the workbench and scheduler over a JSON-RPC style protocol (json-rpc, no page yet). A research run lasts hours to days, so the context fills up long before the work is done: context window management summarises and prunes old steps, and prompt caching keeps the stable prefix (system prompt, task description, tool schemas) cheap to resend. Planning splits the campaign into tasks with dependencies (task-planning, no page yet); subagent-orchestration (no page yet) gives literature search, coding and analysis to separate agents whose summaries the planner holds. The loop itself (agent-loop, no page yet) is thin.
Knowledge: literature and memory
Idea generation needs the literature, and novelty checks need it more. Search is hybrid: a keyword index (Inverted index with BM25) catches exact method names, a vector index (HNSW over embeddings) catches paraphrases, and rank fusion merges the two lists. A cross-encoder re-scores the top candidates. Long papers are cut by chunking along sections so a passage keeps its context.
The writer must not invent support. citation-grounding (no page yet) attaches each claim to a source passage and verifies that the passage supports it, with text classification (entailment-style labels) and the reranker as checkers. Duplicate and variant papers collapse with MinHash and entity resolution.
Memory (agent-memory, no page yet) stores what the system itself has tried: hypotheses, outcomes, dead ends, in a vector index with time-decay-scoring (no page yet) so recent notes rank higher. Memory consolidation merges near-duplicates so the agent does not rediscover the same failed idea. Every note references run ids in the tracker, so memory stays tied to evidence.
Code workbench
The agent edits real repositories, so it needs the tools of a code editor. code-context-retrieval (no page yet) finds the code worth showing: symbol indexes (definitions and references from name resolution), a trigram-index (no page yet) for fast substring and regex search, and an inverted index underneath both. Because files change with every edit, parsing is incremental over lossless-syntax-trees (no page yet) that keep comments and whitespace, and a language server gives diagnostics and go-to-definition over one JSON-RPC conversation.
Applying a model's edit is where agents break files. edit-application (no page yet) accepts search/replace blocks or diffs and locates the target with fuzzy anchoring (fuzzy-string-matching and edit-distance, no page yet) when the model's quote is slightly off, then reports a precise error if it cannot. Myers diff shows the change back to the agent and to the reviewer, and three-way merge combines parallel branches of the same code, which tree search produces. When a run regresses, failure-bisection (no page yet) searches the sequence of changes for the commit that broke it.
Sandbox
Model-written code runs on machines with data and GPUs, and the model reads web pages and papers that may contain hostile instructions (Prompt injection defense). The sandbox (agent-sandboxing, no page yet) therefore has layers. Process sandboxing is the baseline: a separate process with namespaces, cgroup limits and a syscall filter, least privilege by default. Stronger isolation uses microvm-isolation (no page yet): a minimal KVM virtual machine with a tiny device model, as in Firecracker, so a kernel exploit by the agent's code does not reach the host. Network access is closed by default and opened through an egress-proxy-filtering (no page yet) allow-list of domains, which also logs what the agent fetched. Execution is hermetic (hermetic-execution, no page yet): declared inputs, pinned environment, so the same code and seed reproduce the same run. Irreversible actions wait for human approval.
Compute scheduler
An experiment is a job that needs N GPUs together or none: a distributed training run that gets half its GPUs deadlocks. gang-scheduling (no page yet) starts all tasks or none, placed by topology-aware-placement (no page yet) so that GPUs of one job share a fast interconnect, with bin packing to avoid fragmenting the cluster. priority-and-preemption (no page yet) lets urgent runs evict low-priority sweeps; a preempted job receives a termination signal and drains gracefully, writing a checkpoint (distributed-checkpointing, no page yet) so it can resume. Jobs are entries in a durable job queue with leases, retries and a dead-letter path, and each worker holds a lease with a fencing token, so a presumed-dead worker cannot write results over its replacement. Capacity comes from rented GPUs or an owned cluster; resource-usage-accounting (no page yet) attributes GPU-hours to each run for the manager's budget.
Experiment manager
The manager turns a fixed compute budget into the best decisions. Three tools, in the order of how much they assume:
- Early stopping of weak runs. successive-halving-hyperband (no page yet) starts many configurations on a small budget, keeps the best fraction and gives them more, repeating; ASHA runs it asynchronously so workers never wait for a rung. It is a bandit allocation of compute, with top-k selection picking survivors.
- Population methods. population-based-training (no page yet) trains a population in parallel and periodically copies the weights of good members to bad ones with perturbed hyperparameters.
- Tree search over solutions. AIDE and the AI Scientist-v2 treat each candidate program or experiment as a node, expand promising nodes with an LLM and keep a frontier; this is best-first search in the family of MCTS, with the experiment result as the value.
Before spending a large run, scaling-laws (no page yet) extrapolate the outcome from small ones; the fit is a nonlinear least-squares problem (levenberg-marquardt, no page yet) and tells the manager whether a small-scale trend is worth scaling.
Tracking and provenance
Every run logs parameters, a hash of the code and data, seeds, metrics over time and artifacts (experiment-tracking, no page yet). The metric stream is an append-only segmented log; artifacts (checkpoints, plots, outputs) go to object storage addressed by hash (Content-addressed storage), so identical files are stored once and a result can be traced to the exact bytes. A merkle-dag (no page yet) links a run to its parent runs and code commits, the same structure as git. Long metric curves are downsampled for the dashboard with lttb-downsampling (no page yet), which keeps their shape.
Workflow engine
A campaign is a graph of steps (read, propose, implement, run, analyse, write) that may be restarted many times. Durable workflow execution logs each step's result, so after a crash the campaign resumes without redoing completed steps or repeating side effects; record-replay (no page yet) of model and tool outputs makes a failed campaign reproducible for debugging. Steps are ordered by topological sort of the dependency graph, and each side-effecting call carries an idempotency key. The event history is event sourcing in effect: the audit log of what the system did and why.
Evaluation
The evaluator is independent of the agent. A judge model grades ideas, results and drafts against a rubric; judges are noisy and biased, so they are validated against human labels (annotator-agreement, no page yet) and their scores calibrated. To rank many candidates, pairwise comparison with a bradley-terry-model (no page yet) is more stable than absolute scores, and it is the idea behind tournament-style ranking of hypotheses. Task-level success is measured with pass-at-k (no page yet). PaperBench uses such a judge against rubrics co-developed with paper authors; MLE-bench and RE-Bench score against leaderboards and human expert baselines.
Data and control flow
One idea, end to end:
- The idea generator reads the literature index and memory, proposes N hypotheses, and the novelty check searches hybrid retrieval for prior work; near duplicates are dropped.
- The judge ranks the survivors; the planner turns the top one into a task DAG: baseline, change, ablation, analysis.
- The code workbench retrieves the relevant files, the agent writes edits, applies them (fuzzy anchor, diff shown), and runs tests in the sandbox. A small smoke run (minutes) checks that the code trains at all.
- The experiment manager submits runs to the scheduler as a gang of GPUs with a time limit and priority. Rungs of successive halving or branches of the tree decide which to continue.
- Workers run in the sandbox, stream metrics to the tracker, and checkpoint on schedule. A preempted run is drained and resumed.
- The analysis step reads tracker data, not the agent's memory of the logs: plots and tables come from logged metrics, with seed variance. Surviving effects are replicated with fresh seeds before they count.
- The writer drafts with grounded citations and run ids for every number; the reviewer checks both, and an unsupported sentence is cut. Time goes mostly to step 5.
A failure and recovery: a worker disappears. Its lease expires, the queue reassigns the job with a new fencing token, and the new worker restores the last checkpoint. The workflow engine sees the step as still running and starts no duplicate.
Scaling
Limits in the order they bite:
- Evidence quality, not throughput. Many runs on many ideas produce false positives by selection. Levers: replication of winners, held-out evaluation the agent cannot see, pre-registered metrics.
- GPU supply. Experiments queue for GPUs. Levers: early stopping, small-scale proxies and scaling-law extrapolation, preemptible capacity with checkpointing, packing small jobs onto one GPU.
- Agent context and cost. Long campaigns exhaust the window. Levers: memory, prompt caching, narrow subagents, cheaper models.
- Scheduler fragmentation. Gang jobs wait for contiguous GPUs. Levers: bin-packing, backfill, priority classes.
- Human attention. Output exceeds what people can verify. Levers: calibrated automated review, a human gate on claims that matter, audit sampling.
Failure modes
| Failure | Symptom | Cause | Fix |
|---|---|---|---|
| Fabricated results | paper numbers not in any log | the model writes results from memory or expectation | numbers inserted from tracker queries only; a check that every figure resolves to a run id |
| Evaluation tampering | metrics improve by changing the eval | agent can edit the scoring code, tests or data | read-only mounts for evaluators, hidden held-out set, hash of eval code in the tracker |
| Selection inflation | winners do not replicate | best of many noisy runs reported | seeds, replication with fresh seeds, correction for number of trials |
| Sandbox escape or exfiltration | unexpected network calls or host access | untrusted code or injected instructions from fetched pages | microVM isolation, deny-by-default egress, no secrets in the sandbox, approval for irreversible actions |
| Gang deadlock | cluster idle yet jobs pending | partial allocations holding GPUs | all-or-nothing allocation, backfill |
| Edit applied to the wrong place | tests fail in odd files | fuzzy match too loose | require unique match, show the diff, run tests, revert on failure |
| Context rot | agent repeats failed attempts | history pruned without notes | memory entries with run ids, consolidation, a "tried and failed" list in the prompt |
| Judge bias | high scores for fluent but weak work | LLM judge prefers style, length | rubrics, calibration against human labels, pairwise comparison with position swaps |
Real implementations
| name | what it is | repo | licence | notes |
|---|---|---|---|---|
| The AI Scientist | end-to-end pipeline from idea to paper with an automated reviewer | SakanaAI/AI-Scientist | — | v1; uses human-written code templates; read the repo licence before reuse |
| The AI Scientist-v2 | template-free version with agentic tree search and an experiment manager | SakanaAI/AI-Scientist-v2 | — | read the repo licence before reuse |
| AIDE | ML engineering agent framed as tree search over code | WecoAI/aideml | MIT | scaffold used in MLE-bench results |
| MLE-bench | 75 Kaggle competitions as an agent benchmark | openai/mle-bench | — | grading against human leaderboards |
| PaperBench | replicate ICML 2024 papers, graded by rubrics and an LLM judge | openai/frontier-evals | MIT | repository formerly named preparedness |
| SWE-agent | agent with an agent-computer interface for code tasks | SWE-agent/SWE-agent | MIT | code workbench reference |
| OpenHands | open platform for software-development agents with sandboxed runtime | OpenHands/OpenHands | MIT | agent loop and sandbox in one platform |
| Ray (Tune) | distributed execution with hyperparameter search schedulers | ray-project/ray | Apache-2.0 | ASHA, PBT and gang placement groups |
| MLflow | experiment tracking and artifact store | mlflow/mlflow | Apache-2.0 | tracking server and model registry |
| Firecracker | minimal KVM microVM monitor for strongly isolated sandboxes | firecracker-microvm/firecracker | Apache-2.0 |
Sources
- C. Lu et al., The AI Scientist: Towards Fully Automated Open-Ended Scientific Discovery, 2024. paper · code
- Y. Yamada et al., The AI Scientist-v2: Workshop-Level Automated Scientific Discovery via Agentic Tree Search, 2025. paper · code
- Z. Jiang et al., AIDE: AI-Driven Exploration in the Space of Code, 2025. paper
- J. S. Chan et al., MLE-bench: Evaluating Machine Learning Agents on Machine Learning Engineering, 2024 (75 Kaggle competitions). paper
- H. Wijk et al., RE-Bench: Evaluating frontier AI R&D capabilities of language model agents against human experts, 2024. paper
- G. Starace et al., PaperBench: Evaluating AI's Ability to Replicate AI Research, 2025. paper
- J. Yang et al., SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering, 2024. paper
- L. Li et al., Hyperband: A Novel Bandit-Based Approach to Hyperparameter Optimization, JMLR 2018. paper
- L. Li et al., A System for Massively Parallel Hyperparameter Tuning (ASHA), MLSys 2020. paper
- M. Jaderberg et al., Population Based Training of Neural Networks, 2017. paper
- J. Kaplan et al., Scaling Laws for Neural Language Models, 2020. paper
- A. Agache et al., Firecracker: Lightweight Virtualization for Serverless Applications, NSDI 2020. paper · code
- J. Gottweis et al., Accelerating scientific discovery with Co-Scientist, 2025 (multi-agent hypothesis generation and ranking). paper