by CHSZLab
Agents that optimize code like an algorithm engineer: falsifiable hypotheses, benchmarks, verified patches, PDF report
# Add to your Claude Code skills
git clone https://github.com/CHSZLab/AgenticAlgorithmEngineeringGuides for using ai agents skills like AgenticAlgorithmEngineering.
AgenticAlgorithmEngineering is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by CHSZLab. Agents that optimize code like an algorithm engineer: falsifiable hypotheses, benchmarks, verified patches, PDF report. It has 178 GitHub stars.
AgenticAlgorithmEngineering's catalog security scan is still queued. You can run an instant dependency and prompt-injection check now with the "Scan for vulnerabilities" button above.
Clone the repository with "git clone https://github.com/CHSZLab/AgenticAlgorithmEngineering" and add it to your Claude Code skills directory (see the Installation section above). AgenticAlgorithmEngineering ships a SKILL.md manifest, so compatible agents can discover and load it automatically.
AgenticAlgorithmEngineering is primarily written in Python. It is open-source under CHSZLab on GitHub, so you can review or fork the full source.
Yes. AgentsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh AgenticAlgorithmEngineering against similar tools.
No comments yet. Be the first to share your thoughts!
Unlocks once the catalog security scan passes (runs nightly).
The deep catalog scan for this skill is still queued. Run an instant dependency check now instead.
This program turns an autonomous agent into a performance engineer that follows the Algorithm Engineering (AE) methodology: a cycle of design, analysis, implementation, and experimental evaluation, driven by falsifiable hypotheses (cf. Sanders, "Algorithm Engineering - An Attempt at a Definition").
┌─────────────────┐
│ Realistic Model │
│ of the system │
└───────┬─────────┘
│
▼
┌──────────┐ ┌────────┐ ┌─────────────┐
│ Analysis │◄──│ Design │──►│ Falsifiable │
│ │ │ │ │ Hypothesis │
└────┬─────┘ └────────┘ └──────┬──────┘
│ (induction) │
│ ◄────────────────────── │
▼ ▼
┌────────────────┐ ┌──────────────┐
│ Performance │ │ Implement │
│ Guarantees │ │ the change │
│ (deduction) │ └──────┬───────┘
└────────────────┘ │
▼
┌─────────────────────────────────────┐
│ Experiment │
│ Run, measure, compare to baseline │
└──────────────┬──────────────────────┘
│
┌───────▼───────┐
│ Evaluate │
│ keep/discard │
└───────┬───────┘
│
(loop back to Design)
When a session starts (for example when this program is invoked as a skill), first show the user the Algorithm Engineering cycle with AAE at its center, exactly as below and inside a code block, followed by one line naming the target program and metric if they are already known. Before continuing with Setup, offer the user multi-component AAE: instrument the target code so one benchmark run can test multiple hypotheses (one per component), then use the per-component profile against an instrumented baseline to keep or discard each change independently. If selected, put each component change in its own Git commit before the shared benchmark run, so each can be reverted independently with git revert <component-commit> without removing the other component changes. Record the component commit hash alongside its hypothesis, measurement, and verdict; revert discarded component commits individually and export each accepted component commit as its own numbered patch. Keep shared profiling instrumentation in a separate commit and keep the benchmark harness unchanged. If component interactions or profiling overhead prevent reliable attribution, test those hypotheses separately and validate the retained combination against the overall metric and correctness assertions.
╭──────────────────╮
┌────────►│ DESIGN │─────────┐
│ │ falsifiable │ │
│ │ hypothesis │ ▼
╭────────┴─────────╮╰──────────────────╯╭──────────────────╮
│ EVALUATE │ │ ANALYSIS │
│ keep / discard │ ┏━━━━━━━━┓ │ predict outcome │
│ patch + report │ ┃ AAE ┃ │ before measuring │
╰──────────────────╯ ┗━━━━━━━━┛ ╰────────┬─────────╯
▲ │
│ ╭──────────────────╮ ╭──────────────▼───╮
└──┤ EXPERIMENT │◄─┤ IMPLEMENTATION │
│ run · measure │ │ minimal diff │
│ geometric mean │ │ + git commit │
╰──────────────────╯ ╰──────────────────╯
The agent receives:
The agent then runs an autonomous loop, applying the AE cycle to systematically improve performance. Each iteration produces a falsifiable hypothesis ("changing X will improve metric Y by roughly Z"), implements it, runs the experiment, and either keeps or discards the change based on the result.
Invoke this skill with $aae in Codex. The same AE cycle, result schema, numbered patches, and report format apply in every agent. Resolve bundled templates/ and knowledge-base/ relative to the skill directory, not the project being optimized.
AGENTS.md instructions before setup. Use the user's existing scope, correctness requirements, and authorization; do not ask again for decisions already supplied. Choose a unique run tag when none is specified.report/session.json: baseline and best commit, current experiment, remaining budget, benchmark command, scope, assertions, and next hypothesis. On continuation, read this checkpoint and results.tsv before running another experiment./loop, permission flags, and Agent Teams are not prerequisites. Delegate only when authorized in the session or project instructions; benchmark runs must not compete for resources in ways that distort results.To set up a new tuning session, work with the user to:
mar21). The branch aae/<tag> must not already exist.git checkout -b aae/<tag> from current main/master.results.tsv with just the header row, an empty patches/ folder (see Patches), and a report/ folder with the report template, an experiments/ subfolder, and session.json (see Experiment Report). Add results.tsv, patches/, and report/ to .git/info/exclude."kb_contributions": true or false in report/session.json, so it survives context compaction and restarts. This is the only time you ask; do not ask again during the loop.The user defines these per project. The agent must respect them strictly.
What the agent CAN do:
What the agent CANNOT do:
After reading the target code and benchmark during setup, the agent must formulate correctness assertions: invariants that must hold after every change. These act as a safety net, ensuring that optimizations do not silently break the program's correctness.
The agent derives these from its understanding of the code. Examples:
Present the assertions to the user for confirmation during setup. The user may add, modify, or remove assertions. Once agreed upon, verify them after every implementation, before running the full benchmark. If an assertion fails, the change is incorrect; discard it immediately (no need to benchmark) and log it as a crash.
Assertions are distinct from the benchmark metric. The metric measures performance; assertions guard correctness. A change that improves the metric but violates an assertion is always discarded.
Each iteration of the loop implements one full AE cycle:
Before proposing changes, the agent must have an accurate mental model of:
The model should be updated after every experiment. When experiments contradict expectations, the model is wrong and must be revised, not the experiment.
Propose a specific, falsifiable hypothesis. Good hypotheses are:
Hypotheses can come from:
Before implementing, reason about the expected outcome:
This step prevents wasted experiments and builds understanding even when hypotheses fail.
Implement the change in the target file(s). Principles:
Run the benchmark and collect results:
Parallel runs: Whenever the benchmark involves multiple inputs, seeds, or configurations, prefer GNU parallel to run them concurrently. This dramatically reduces wall-clock time per iteration and should be the default approach unless runs compete for shared resources (e.g. a single GPU). Example:
parallel --jobs 4 --results run_results/ './bench.sh --input {} > logs/run_{}.log 2>&1' ::: input1 input2 input3 input4
Only parallelize when runs are independent and the system has sufficient resources (CPU cores, memory, GPU slots) to avoid contention that would distort measurements.
Aggregation: When an experiment produces multiple measurements (e.g. across inputs or seeds), use the geometric mean as the default summary statistic. The geometric mean is appropriate for ratios and multiplicative quantities like speedups or normalized scores, and is less sensitive to outliers than the arithmetic mean. Compute it as:
geometric_mean = (x1 * x2 * ... * xn) ^ (1/n)
Use the arithmetic mean only when the metric is inherently additive (e.g. total time summed across phases) and the user explicitly requests it.
Compare the result to the current best:
Apply the simplicity criterion when evaluating:
The benchmark should print a summary with at least the primary metric. The agent extracts key values via grep. Example:
grep "^primary_metric:" run.log
Every experiment is logged to results.tsv (tab-separated). The TSV has a header row and columns:
commit metric_value resource_usage status hypothesis
keep, discard, or crashExample:
commit metric_value resource_usage status hypothesis
a1b2c3d 0.997900 44.0 keep baseline
b2c3d4e 0.993200 44.2 keep doubling LR will reduce val_bpb because current LR undershoots the loss basin
c3d4e5f 1.005000 44.0 discard GeLU activation will improve gradient flow in early layers
d4e5f6g 0.000000 0.0 crash doubling model width will improve capacity (OOM)
Note: do not commit results.tsv, patches/, or report/; leave them untracked. Add all three to .git/info/exclude during setup, so that git reset --hard to the previous best never touches them.
Every accepted change is kept as a numbered patch in patches/, created during setup. Patches are numbered in order of acceptance (0001, 0002, ...), not by experiment number; the baseline gets no patch. Right after a change is kept:
git format-patch -1 HEAD --stdout > patches/$(printf '%04d' $N)-<short-slug>.patch
where N is the number of accepted changes so far and <short-slug> names the change in a few words (e.g. 0003-bucket-queue-refinement.patch). The commit message of a kept commit states the hypothesis, so each patch is self-describing. Applying all patches in order to the baseline commit reproduces the current best version:
git checkout <baseline-commit> && git am patches/*.patch
Never renumber or rewrite existing patches. If a later experiment undoes an earlier change, that undoing is itself a new patch.
As a side artifact, the agent maintains a PDF report of the whole session: a title page with summary and contents, the trajectory of the metric over all experiments, the list of accepted patches, and one page per tested hypothesis (kept, discarded, and crashed alike) with the hypothesis, intuition, prediction, measurements, verdict, reflection, and the code change.
Template. The template lives in this repository under templates/report/ (report.tex and build_report.py, Python standard library plus a LaTeX installation with latexmk). If AAE is installed as a skill, copy them from the skill directory; otherwise fetch them:
mkdir -p report/experiments
for f in report.tex build_report.py; do
curl -sL https://raw.githubusercontent.com/CHSZLab/AgenticAlgorithmEngineering/main/templates/report/$f -o report/$f
done
Session data. During setup, write report/session.json:
{"title": "AAE session: <project>", "subtitle": "<one line: what is optimized, on which branch>",
"target": "<target files>", "metric": "<metric name>", "unit": "s", "direction": "lower",
"resource": "peak memory [GB]", "machine": "<CPU, cores, RAM>", "branch": "aae/<tag>",
"date": "<YYYY-MM-DD>", "summary": "<short narrative of the trajectory; update it from time to time>"}
direction is lower or higher (which way the metric improves). Add "kb_contributions": true or false once the user has answered the contribution question in setup step 8; after the first contribution, also record "kb_entry" (the entry filename) and "kb_pr" (the PR URL).
Per experiment. Experiments are numbered 001, 002, ... in the order they are run; the baseline is 001. Each experiment gets a folder report/experiments/NNN/ with two files:
change.patch: the code change, saved right after committing and before the benchmark runs, because a discarded change disappears with the reset: git show HEAD > report/experiments/NNN/change.patch.meta.json: written in two steps. At commit time, record what was predicted; after evaluation, add what happened:{"exp": 7, "title": "Bucket queue in refinement", "commit": "b2c3d4e",
"hypothesis": "Replacing the binary heap ... reduces time by ~15% because ...",
"intuition": "Why this should work, from the current model of the system (profiles, prior results).",
"prediction": "Expected direction and magnitude, and what could go wrong.",
"status": "keep", "metric": 2.181, "resource": 1.2,
"measurements": [{"input": "rgg_n_2_20", "value": 3.483}, {"input": "road_eu", "value": 3.976}],
"verdict": "Confirmed: -15.2% geometric mean, matching the prediction.",
"reflection": "What the result says about the model and what to try next.",
"patch": "patches/0003-bucket-queue-refinement.patch"}
status is baseline, keep, discard, or crash; patch is set only for kept changes. measurements holds the per-input values of the primary metric (one entry per input or seed); if metric is omitted, the generator uses their geometric mean. Text fields are plain text; `code` is set in typewriter and $...$ is passed through as math. The generator compares every experiment against the baseline and the best result accepted before it, so only this experiment's values need to be recorded.
Build. After every experiment (after logging), rebuild the report:
python3 report/build_report.py report > /dev/null 2>&1 || true
This writes report/report.pdf. Rebuilding is cheap and idempotent, so the report is always current when the user interrupts the loop. A failing build must never stop the loop; note it and fix the offending meta.json text later. Before handing the report to the user, check report/report.log for overfull boxes and look at the PDF.
The experiment runs on a dedicated branch (e.g. aae/mar21).
The first run is always the unmodified baseline.
LOOP FOREVER (DO NOT STOP EVER):
git commit the change, with the hypothesis in the commit message. Save the change and the prediction for the report: git show HEAD > report/experiments/NNN/change.patch and the first half of meta.json (see Experiment Report).<run_command> > run.log 2>&1 (redirect everything; do NOT use tee or let output flood your context).grep "^<metric>:" run.logtail -n 50 run.log to read the error. Attempt a fix if trivial; otherwise give up on this hypothesis.patches/ (see Patches).git reset back to the previous best.results.tsv.report/experiments/NNN/meta.json with status, measurements, verdict, and reflection, then rebuild the report with python3 report/build_report.py report.kb_contributions is true in report/session.json and the experiment number is a multiple of 10 (010, 020, ...), open or update the session's knowledge-base PR (see Contributing Back). Do not ask the user; permission was given in setup. If it is false or missing, skip this step.Timeout: Each experiment should complete within the configured time budget (plus startup overhead). If a run exceeds 2x the budget, kill it and treat it as a failure.
Crashes: Use judgment. Fix trivial bugs (typo, missing import) and re-run. If the idea is fundamentally broken, skip it, log "crash", and move on.
NEVER STOP: Once the loop begins, do NOT pause to ask the user if you should continue. The user may be away and expects autonomous operation. If you run out of ideas, think harder:
The loop runs until the user manually interrupts.
Report after every experiment: The report is updated after each experiment, without exception: kept, discarded, and crashed experiments all get their meta.json completed and the report rebuilt before the next hypothesis is formulated. Kept experiments additionally get their numbered patch in patches/ at the same point. Never batch report updates for later; the report must reflect every experiment run so far whenever the user looks at it or interrupts the loop.
Simplicity criterion: All else being equal, simpler is better. A small improvement that adds ugly complexity is not worth it. Removing code for equal or better results is a great outcome. Weigh complexity cost against improvement magnitude.
Resource usage is a soft constraint. Some increase is acceptable for meaningful metric gains, but it should not blow up dramatically.
This methodology is supported by a community-contributed knowledge base of optimization techniques, experiment results, and lessons learned from AAE sessions. The knowledge base lives in the AAE repository at:
https://github.com/CHSZLab/AgenticAlgorithmEngineering/tree/main/knowledge-base
Before or during a tuning session, consult the knowledge base for techniques relevant to your problem:
curl -sL https://raw.githubusercontent.com/CHSZLab/AgenticAlgorithmEngineering/main/knowledge-base/INDEX.md and scan titles, problem domains, and key techniques.INDEX.md with the entry filename from the index).If you have web search or web fetch tools available, use those instead of curl. If the knowledge base is available locally (e.g. as a git submodule or in the same repository), read the files directly.
Permission is asked once, during Setup (step 8), and stored as kb_contributions in report/session.json. Never open or update a PR unless it is true.
If permission was given, contribute every 10 experiments (loop step 12). Each session has one entry and one PR, which grows over the session:
gh repo fork if you cannot push to it, and create a branch kb/<NNN>-<short-slug> from the latest main, where <NNN> is the next free number in INDEX.md. Write the entry following the template in knowledge-base/CONTRIBUTING.md, add its row to INDEX.md, commit, push, and open the PR with gh pr create (or the GitHub MCP server). Record kb_entry and kb_pr in report/session.json.kb_pr.Do this work in a separate clone of the AAE repository (for example in /tmp), never on the aae/<tag> branch of the project under optimization. Only share transferable insights, and never include proprietary code, data, or paths from the user's project beyond what the entry needs. Do not wait for review or merge, and never let a failing gh call stop the loop: note the failure in the report summary and retry at the next multiple of 10.
This methodology mirrors Popper's scientific method as applied to algorithm engineering (Sanders, 2009):
This repository contains the program definition for Agentic Algorithm Engineering (AAE), a methodology that turns autonomous agents into performance engineers following the Algorithm Engineering cycle: design, analysis, implementation, and experimental evaluation, driven by falsifiable hypotheses.
See AAE.md for the full program definition. Besides the optimized code, every AAE session produces two artifacts: one numbered patch per accepted change in patches/, and a PDF report in report/ with the trajectory of the metric and one page per tested hypothesis (intuition, prediction, code change, measurements, verdict).
The methodology is described in the paper Agentic Algorithm Engineering: Improving Shared-Memory Exact Minimum Cuts (13th DIMACS Implementation Challenge, to appear), which applies AAE to the shared-memory exact minimum cut solver VieCut. See Citation below if you use AAE in your work.
AAE sessions on established open-source codes. Every kept change was checked against the original output.
| Code | Problem | Result | Correctness | Details |
|---|---|---|---|---|
| VieCut | exact minimum cut | 8.9x faster on 1 thread, 8.8x on 32 threads; no longer runs out of memory on large-cut graphs | every cut unchanged | v2.0, paper |
KaHIP kaffpa |
graph partitioning | 3.9x faster in total time (2.8x geometric mean over 537 runs) | partition quality unchanged | v3.26, report |
KaHIP ultra |
graph partitioning quality | 2.2% smaller cuts than strong (about 7% on social graphs), in less time than strong of v3.25 |
same balance rule as strong |
v3.28, ultra.pdf |
| Hochbaum's pseudoflow | maximum flow | 3.0x faster in total (3.18x geometric mean over 164 DIMACS instances) | flow value verified on every instance | KB 039 |
| FREIGHT | streaming hypergraph partitioning | 1.82x faster | bit-identical output | KB 035 |
| ParHIP | distributed graph partitioning (MPI) | 1.61x faster partitioning, 1.77x faster I/O (session ongoing) | byte-identical partitions | KB 040 |
| ScalableCorrelationClustering | correlation clustering | 1.24x faster | identical solution quality | v1.2, KB 034 |
Each session also produced a PDF report with one page per tested hypothesis, and its lessons went into the knowledge base.
The full report of the KaHIP kaffpa session: 122 experiments, 69 hypotheses (41 kept, 28 discarded), 41 patches, 3.9x faster in total with every partition checked (PDF, 90 pages).
In Claude Code:
/plugin install aae --marketplace CHSZLab/AgenticAlgorithmEngineering
/aae:aae make the solver in src/ faster on the graphs in data/
The agent first agrees with you on the benchmark, the metric, the correctness checks and the budget, then runs the loop on its own and leaves the accepted patches and a report. For Codex and other agents, see Installation.
Algorithm Engineering, as defined by Sanders (2009), is a methodology for algorithmic research built around a cycle of design, analysis, implementation, and experimental evaluation. Unlike traditional algorithmics, which often stops at theoretical analysis, algorithm engineering insists on closing the loop: hypotheses about algorithm performance are tested experimentally on realistic inputs, and the results feed back into improved designs. Central to this process are falsifiable hypotheses, following Popper's scientific method applied to algorithms.
Agentic Algorithm Engineering takes this methodology and hands the cycle to an autonomous AI agent. The agent formulates hypotheses, implements changes, runs experiments, and evaluates results, iterating continuously without human intervention. This allows systematic, high-throughput exploration of the optimization space while maintaining the scientific rigor of the AE methodology.
AAE belongs to a family of tools in which AI agents improve code by running experiments. They differ in what they work on and in what you get at the end.
autoresearch lets an agent edit one training script for a small language model, train for five minutes, and keep the change if the validation loss improved. AAE uses the same keep-or-discard loop, but on any existing code base, in any language and for any metric, and it adds the parts of the Algorithm Engineering method that make the results trustworthy and reusable: a falsifiable hypothesis with a predicted effect before every experiment, correctness assertions checked after every change, one reviewable patch per accepted change, and a report.
AlphaEvolve, OpenEvolve and ShinkaEvolve evolve a population of program variants: a language model proposes mutations, an evaluator scores every variant, and evolutionary search keeps the best. They are strong at discovering new algorithms and heuristics for problems that can be scored automatically, and they evaluate many candidates. AAE instead works like an engineer on an existing code base: fewer, deliberate experiments, each one motivated by profiling and analysis, with the output kept correct throughout. The approaches are complementary.
| autoresearch | OpenEvolve, ShinkaEvolve | AAE | |
|---|---|---|---|
| Works on | one training script | code blocks scored by an evaluator | any existing code base and language |
| Search | one agent, keep or discard | language-model mutations plus an evolutionary population | one agent following the Algorithm Engineering cycle |
| Before each experiment | the agent's next idea | a proposed mutation | a falsifiable hypothesis with its predicted effect |
| Correctness | the metric (validation loss) | the evaluator score | assertions agreed with you, checked after every change (e.g. bit-identical output) |
| What you get | improved script and experiment log | best program and population | one Git patch per accepted change, a PDF report with one page per hypothesis, and lessons in a shared knowledge base |
| How it runs | an agent prompted with program.md |
a Python framework calling language models | a skill or plugin in Claude Code or Codex |
The project includes a community-contributed knowledge base of optimization techniques, experiment results, and lessons learned from AAE sessions. Browse knowledge-base/INDEX.md for an overview, or contribute your own findings (see knowledge-base/CONTRIBUTING.md).
Inside Claude Code, type:
/plugin install aae --marketplace CHSZLab/AgenticAlgorithmEngineering
Then type /aae:aae (or just ask Claude Code to optimize something with AAE) and say what to optimize, e.g. /aae:aae make the solver in src/ faster on the graphs in data/.
On Claude Code versions before 2.1.275, add the marketplace first: /plugin marketplace add CHSZLab/AgenticAlgorithmEngineering, then /plugin install aae@aae.
Without the plugin system, a plain clone works too (the skill is then called /aae):
git clone https://github.com/CHSZLab/AgenticAlgorithmEngineering ~/.claude/skills/aae
Using another agent? Just tell it to follow AAE.md.
/plugin update aae (plugin) or git -C ~/.claude/skills/aae pull (clone)..claude/skills/aae inside that project instead.latexmk). Without LaTeX, the session still runs and keeps the patches; only the PDF is skipped.Inside a Codex session, ask:
Install AAE as a Codex skill from https://github.com/CHSZLab/AgenticAlgorithmEngineering.
Clone the repository and run its