AutoResearch Quickstart
Problem
You have a training script and a metric you want to optimize (e.g., validation loss), and you want an AI agent to autonomously iterate on the code — proposing changes, running experiments, keeping improvements, and reverting failures — without manual intervention.
Solution
Use NeuroLink's AutoResearch engine. Initialize a config pointing at your repo, define the metric to optimize, and run experiment cycles. Each cycle: the AI reads your code, proposes a change, commits it to a branch, runs the experiment, parses the metric, and keeps or reverts the change.
Code
CLI — Single Experiment Cycle
# 1. Initialize AutoResearch in your repo
neurolink autoresearch init /path/to/repo \
--tag "run1" \
--target "train.py" \
--immutable "program.md" \
--run-command "python3 train.py" \
--metric-name val_bpb \
--metric-pattern "^val_bpb:\\s+([\\d.]+)" \
--metric-direction lower \
--timeout 120
# 2. Run one cycle (propose → execute → evaluate → keep/revert)
neurolink autoresearch run-once /path/to/repo
# 3. Check results
neurolink autoresearch status /path/to/repo
neurolink autoresearch results /path/to/repo
SDK — Single Experiment Cycle
import { NeuroLink } from "@juspay/neurolink";
import { ResearchWorker } from "@juspay/neurolink/autoresearch";
async function runOneExperiment() {
const neurolink = new NeuroLink({
provider: "google-vertex",
model: "gemini-2.5-flash",
});
const worker = new ResearchWorker({
repoPath: "/path/to/repo",
mutablePaths: ["train.py"],
immutablePaths: ["program.md"],
runCommand: "python3 train.py",
metric: {
name: "val_bpb",
pattern: "^val_bpb:\\s+([\\d.]+)",
direction: "lower",
},
timeoutMs: 120_000,
});
// Attach the emitter and listeners before initialize(), which emits
// autoresearch:initialized itself (resume() emits autoresearch:resumed)
const emitter = neurolink.getEventEmitter();
worker.setEmitter(emitter);
emitter.on("autoresearch:experiment-started", (e) => {
console.log(`Experiment ${e.runCount} starting`);
});
emitter.on("autoresearch:experiment-completed", (e) => {
console.log(`Experiment ${e.runCount}: ${e.status}, metric=${e.metric}`);
});
await worker.initialize("run1");
// Run one cycle
const result = await worker.runExperimentCycle(
"Reduce validation loss by improving the learning rate schedule",
);
console.log("Status:", result.status);
console.log("Metric:", result.metric);
console.log("Commit:", result.commit);
}
runOneExperiment();
SDK — Scheduled via TaskManager
import { NeuroLink } from "@juspay/neurolink";
async function scheduleResearch() {
const neurolink = new NeuroLink({
provider: "google-vertex",
model: "gemini-2.5-flash",
});
// Create a scheduled autoresearch task
const task = await neurolink.tasks.create({
name: "research-lr-schedule",
prompt: "Run autoresearch experiment cycle",
type: "autoresearch",
schedule: { type: "interval", every: 5 * 60 * 1000 }, // Every 5 minutes
autoresearch: {
repoPath: "/path/to/repo",
mutablePaths: ["train.py"],
runCommand: "python3 train.py",
metric: {
name: "val_bpb",
pattern: "^val_bpb:\\s+([\\d.]+)",
direction: "lower",
},
},
});
// Pause, resume or delete it later
await neurolink.tasks.pause(task.id);
await neurolink.tasks.resume(task.id);
}
scheduleResearch();
Note:
neurolink.tasks.create()registers the task with the configured TaskManager backend, and the schedule runs there. With the default in-process backend the timers live only as long as your process, so keep it running. From the CLI,neurolink autoresearch startonly saves the task andneurolink task startruns the worker.
Explanation
1. Initialization
autoresearch init (CLI) or new ResearchWorker(config) (SDK) sets up the config:
mutablePaths— Files the AI is allowed to edit (your training script)immutablePaths— Files the AI can read but not modify (research program, dataset configs)runCommand— Shell command to execute the experimentmetric— Name, regex pattern to extract the value from stdout, and optimization direction (lowerorhigher)timeoutMs— Max wall-clock time per experiment run
The CLI writes this to .autoresearch/config.json and creates a dedicated git branch.
2. Experiment Cycle
Each runExperimentCycle() call goes through 9 phases:
- bootstrap — Read the research program and understand the codebase
- analyze — Study current results and identify improvement opportunities
- plan — Propose a specific code change
- implement — Apply the change to mutable files
- validate — Verify the code is syntactically valid
- commit — Git-commit the candidate change
- execute — Run the experiment command
- evaluate — Parse the metric from stdout using the regex pattern
- decide — Keep the commit if the metric improved, revert otherwise
3. Artifacts
After running, check .autoresearch/ in your repo:
| File | Contents |
|---|---|
config.json | Persisted configuration |
state.json | Current best metric, cycle count, phase, branch name |
results.tsv | Tab-separated log: commit, metric name, memory_gb, status, description |
runs.jsonl | Full JSON audit log — one JSON object per completed cycle |
4. Events
The SDK emits 10 typed events via neurolink.getEventEmitter(). A ResearchWorker created directly emits them once you pass it that emitter with worker.setEmitter(); tasks created through neurolink.tasks are wired for you:
| Event | Fired when |
|---|---|
autoresearch:initialized | A research session is created |
autoresearch:resumed | An existing research session is resumed |
autoresearch:phase-changed | The worker moves to a new phase |
autoresearch:experiment-started | An experiment cycle begins |
autoresearch:experiment-completed | An experiment cycle completes (success or fail) |
autoresearch:metric-improved | The best metric value improves |
autoresearch:revert | A candidate commit is reverted |
autoresearch:revert-failed | Reverting a candidate commit fails |
autoresearch:state-updated | The persisted state is updated |
autoresearch:error | An error occurs |
Variations
Use a Different Provider
Replace the provider/model in the config. AutoResearch works with any NeuroLink-supported provider:
const worker = new ResearchWorker({
// ... same config ...
provider: "anthropic",
model: "claude-sonnet-4-20250514",
});
Or via CLI:
neurolink autoresearch init /path/to/repo \
--provider anthropic --model claude-sonnet-4-20250514 \
# ... other flags ...
Optimize a Higher-is-Better Metric
Set direction: "higher" for metrics like accuracy:
metric: {
name: "accuracy",
pattern: "^accuracy:\\s+([\\d.]+)",
direction: "higher",
}
Reset and Start Over
# Deletes entire .autoresearch/ directory (config, state, results)
neurolink autoresearch reset /path/to/repo
Pause and Resume (TaskManager)
neurolink autoresearch pause /path/to/repo
# ... later ...
neurolink autoresearch resume /path/to/repo
Note:
pause,resume, andstopupdate the stored task status but do not interact with the TaskManager runtime directly. The task worker checks status before each cycle.
See Also
- AutoResearch Feature Guide — Full reference with phase diagrams, configuration, and architecture
- Tool Chaining — AutoResearch uses phase-gated tool chaining internally
- Structured Output with JSON Schema — Extract structured data from experiment outputs
- API Reference