Skip to main content

loopmath

loopmath finds out which change to keep, from as few scored runs as it can.

You have an agent or a pipeline, and a change to it: a new prompt, another model, a higher effort, a new tool. Is the change better, or as good and cheaper? loopmath tells your runner which runs to make, takes each run's score and cost, and stops when it is sure enough, with a verdict: adopt the change, keep what you have, or the best of many. Scores may come late, from several judges, and earlier scores can start it off.

loopmath runs nothing itself. Your runner, your agent or your CI job makes every run and gives every score; loopmath is a command line they call, reading and printing JSON. Everything runs locally. Once a day loopmath asks pypi.org whether a newer loopmath exists; it sends only its version and uploads nothing. LOOPMATH_NO_UPDATE_CHECK=1 turns the check off, and it is off when CI is set. Pages are served on 127.0.0.1 only.

Install

Python 3.11 or newer.

pipx install loopmath          # or: uv tool install loopmath, or pip install loopmath in a venv
loopmath self status

From a clone of this repository:

python3 -m venv .venv
.venv/bin/python -m pip install -e .

Installing needs the network: pip, pipx and uv download the build backend and the dependencies, from a clone too.

loopmath self update says whether a newer loopmath is out and prints the command that upgrades it for how you installed it. loopmath never upgrades itself.

With a coding agent

loopmath self skill install

It writes one skill, loopmath, for Claude Code and Codex. Then ask your agent, for example "check whether the new prompt is better with loopmath". The skill sends the agent to loopmath guide, which prints the steps for each thing you want, from the installed loopmath, so they always match its commands:

Topic For
check is a new config better than the one you run, or as good and cheaper
frontier many configs, such as models by efforts: which is best for the goal and the budget
improve let a loop propose edits, run them and keep what helps
late-scores scores that come hours or days later, several judges, corrections
judges which judge to trust, judge studies, forms for a person to score
live a real task to do now: which config to do it with
pipeline the verdict as a step in a build pipeline
from-scores start from earlier scores, or from what someone knows
upgrade moving from loopmath 0.4
files every file, line and exit code the topics name

The loop

An experiment is a set of tasks, the config you run today (the base), one or more candidates, a goal and a budget, in one input file:

{"id": "prompt-v2",
 "tasks": {"ids": ["t1", "t2", "t3", "t4", "t5", "t6"]},
 "candidates": [{"name": "old", "base": true, "parts": {"prompt": "v1"}},
                {"name": "new", "parts": {"prompt": "v2"}}],
 "goal": {"kind": "best_under_cost", "score": "quality"},
 "scoring": [{"name": "quality", "scale": "fraction"}],
 "budget": {"runs": 24}}

Then the loop:

loopmath experiment define --file experiment.json
loopmath next --experiment prompt-v2 --json        # the runs to make, or wait, or stop with a verdict
loopmath record add rows.jsonl                     # one row for each run your runner made
loopmath score add scores.jsonl                    # scores that came later, when there are any
loopmath next --experiment prompt-v2 --json > answer.json   # again, until it says stop
loopmath next act --did adopt --by ana --answer answer.json # when the user adopts
loopmath describe --experiment prompt-v2

Each run that next lists has an id to write on its row, so a score that comes later finds its run. The verdict is adopt, keep, best or undecided, with how sure it is and what it rests on. loopmath next --check says it in the exit status, for a build pipeline. The loop can stop and start at any point: everything it needs is in the log.

Connecting your own agent runner walks the loop with a made-up runner, its adapter and its loop, start to end.

The commands

Group Holds
loopmath experiment define, add, list, show: the experiments
loopmath next what to do next; next act writes what was decided
loopmath record add, check, repair: the rows of runs, and the log
loopmath score add and show, and the judge tools: study, fit, judges, rubric, trust, steps, labels, sheet, simulate
loopmath describe what the log says so far, with ranges
loopmath prior from-scores, state, show, remove, import, export: what is known before the first run
loopmath generate edits, grid, screen: candidates from a base and a list of edits
loopmath route live work: a config for the task at hand
loopmath guide the steps for each thing you want
loopmath ui pages
loopmath self status, config, doctor, drill, fit, import, plugins, prices, rebuild, refit, skill, update

Every command in the table takes --json and then prints one JSON object whose schema names its shape. A plugin's commands print what the plugin says: harness watch --json, for one, prints one object per event, one per line, and harness schema --json prints a JSON Schema. Exit 0 is done; 1 is a command that parsed but cannot be done, or a line that was refused; 2 is a command line that does not parse, or a name or file that is not there. loopmath guide files lists the rest.

The log and privacy

The log is the record: a folder of JSON lines files, one for each machine that writes, under the root folder (~/.loopmath, or LOOPMATH_HOME, or --home). It holds what your runner recorded: rows, scores, decisions and experiments, and the documents attached to them. A line is never changed; a correction is a new line. The store under the root folder is made from the log, and loopmath self rebuild makes it again. Settings in config.toml are not in the log, and a rebuild does not bring them back: keep a copy. Do not edit the log by hand.

loopmath prior export --preview prints what a shared file of your runs would hold. Only prior export --out FILE writes it, and sending it is up to you. For each run the file holds its outcome, score values, dollars and status, and these labels: the names of its scores; the task's type, subtype and features; the workflow, its steps and their roles, artifacts, edges, gates and rescue; and for each setting its name, harness, model id, family and provider, effort and context policy. A label goes in as written when it is a short identifier (letters, digits and _ . : + -, at most 64 characters), and as a salted hash when it is not. Preview and export protect the whole slash label with a salted code by default (--subtypes hash). With guess, short slash labels such as configs/release.toml or tests/unit can travel as written. With full, the entire slash label travels as written, including any private text. Run, task, repository and slate ids and the organization are always salted hashes, salted with a secret made in the root folder at the first preview or export; node and attempt ids are renumbered (n1, a1). Left out: experiment names, candidate names and parts, titles, options (which hold commands and flags), run times and any other free text. A private model, workflow or step name that looks like an identifier travels as written.

Moving from 0.4

loopmath self import --from ~/.loopmath
loopmath self skill install

The import reads the root folder of 0.4 and writes what it holds to the log; it changes nothing there. loopmath guide upgrade maps each command of 0.4 to its place in 0.5. The commands of 0.4 that read other tools' logs, adapt, graph, analyze and onboard, are in the adapters plugin, under adapters, and ocp migrate is ocp-old migrate in the ocp-old plugin. loopmath self plugins list shows the plugins.

More

License

MIT.

Metadata

Release files for loopmath 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loopmath 0.5.0
File Size Uploaded Provenance Actions
loopmath-0.5.0.tar.gz 2.1 MB Without provenance Details for loopmath-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for loopmath 0.5.0
File Interpreter ABI Platform Actions
loopmath-0.5.0-py3-none-any.whl Python 3 none any Details for loopmath-0.5.0-py3-none-any.whl

Total release size: 4.3 MB

Release files / loopmath-0.5.0.tar.gz

Download URL loopmath-0.5.0.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
5ab8dcc82bfe661cacd9d7bc4a5588a1c76be95486c039ace248d238caf29346
BLAKE2b-256 checksum
How to use checksums
e20c3c014d3a1d463b6c7b8a954bcc1f97dadb0f1dedbec98d5bf9a46b36a627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / loopmath-0.5.0-py3-none-any.whl

Download URL loopmath-0.5.0-py3-none-any.whl
Size 2.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
8c33aa6325c600539055a558a6b4c950a275051029daa75842f47de7b54ea7ad
BLAKE2b-256 checksum
How to use checksums
c4c6ec4b84563c5da5e3f8b4be4cf9a251a35e56788e7bd498256f4888ca6392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for loopmath 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page