Improvements

Improvements

LagrangeCloud reads an agent's runs and traces for runs that went wrong and how to fix them, and for ways to do the same work for less money or in less time. Each change it finds is saved as a candidate: a preview version of the agent with the change, an estimate of what it saves, and the evidence from the runs. Nothing reaches your callers until you promote it, and you can measure a candidate on real inputs and real traffic first.

  1. Runs and tracesWhat the agent did, and what it cost
  2. CandidateA preview version with one change
  3. ReplayRecent inputs run again, judged against the originals
  4. CanaryA share of live runs, with automatic stop
  5. PromoteIt becomes the live version
and again on new runs

Candidates are listed under Improvements in the console, and on each agent's Overview tab.

For a Paused or Removed agent, historical candidates, measurements and product feedback stay available, but new audits, Adjust, replays, canaries and promotions are blocked. Paused agents can still stop and reject an existing canary. These candidates no longer appear as actionable suggestions on Overview or run pages; historical usage and costs remain in the totals.

What it looks for

OptimizationWhat changesNeeds
A quality fixA model groups recent runs that went wrong into issues by cause, and adds notes or a skill to fix the issue that affects the most runs. Issues the agent's logic can't fix, such as a service that was down, are listed but left alone.2 runs that went wrong
A cheaper modelSwitch the main model to the cheaper platform model of the same family, when it would cost less for the same tokens5 finished runs
Steps that keep failingWhen the same tool call fails in several recent runs before the agent finds what works, add a note to the instructions so it skips the failing step5 finished runs
Unused MCP servers and skillsDrop servers and skills no recent run used. Each server starts with every run and adds its tools to every model call.20 finished runs
A leaner workflowA model reads the instructions, the skills and the most expensive runs, and rewrites the instructions or a skill to cut wasted work, such as fetching the same data twiceA few successful runs

A run counts as gone wrong when it failed, when someone rated it No on its page (or with lgr rate <run> bad "why"), when a test or outcome signal sent for it (POST /v1/runs/{id}/signals with a negative value) is negative, or when a person ran the same task again within two hours of it ending. A note left with a rating is the clearest evidence of what you wanted, so it goes to the model word for word. Quality fixes are tried before the other optimizations.

Set improvement.success in lgr.yaml to say, in a sentence or two, what a good run of the agent does. Quality audits and replay judges read it.

A candidate only changes the agent's configuration (instructions, skills, MCP servers, model), never the harness. Audits don't rewrite your instructions: they add and remove short notes in a Notes from earlier runs section at the end, and add or change skills, so what you wrote stays word for word.

LagrangeCloud looks every hour, once per live version, after the agent has had a few more finished runs. To look now, click Propose improvement on the agent's page. Set improvement: { mode: off } in lgr.yaml to stop it from looking on its own.

Replays

Before any caller sees a candidate, Replay recent inputs runs up to 5 recent inputs of the live version again on the candidate, in fresh sandboxes. A model compares each result with the original and judges it better, the same or worse, and the candidate shows cost and time next to the originals. Each pair is judged twice, with the two runs in either order; a verdict counts only when both readings agree, and a split shows as Unsure, which neither passes nor blocks the candidate. A quality fix replays the runs it was built to fix first, then recent good ones. Each replay shows its quality (same, better or a regression) and how its cost and time changed; the summary says whether any replay regressed. Compare steps on a replay puts the two runs side by side: the tool calls only one of them made, the ones whose input changed, and both results. Replays are paid for by LagrangeCloud.

Each candidate also recommends a next step with its reason, and marks its button: replay first, reject if a replay regressed, or start a canary if the replays cost less or took less time. During a canary it recommends waiting for 5 runs, then promoting, or rejecting if the candidate fails more often or costs more per run.

Replays only start when you click the button, because they run for real: an agent that changes things elsewhere, such as posting a message or merging a pull request, does so again.

A workflow candidate for a pull request review agent: four replays judged the same or better, 40% cheaper and 37% faster, and the change to its instructions
An example candidate after its replays

A workflow or quality candidate can't serve any runs until its replay passes: no result judged worse, at least one verdict both readings agreed on, and either a lower total cost (workflow) or at least one result judged better (quality). Any other candidate can start a canary right away, but takes 100% of runs only after a passing replay or a canary that served it 10 runs without being stopped.

Canary and promotion

  • Start canary sends a share of runs (5% to 50%) to the candidate, so both versions are measured on the same live traffic. The candidate shows success rate, cost per run, median time and failed tool calls per run for each version.
  • Promote to 100% makes the candidate the live version.
  • Reject drops it, with an optional reason.
  • Roll back on a promoted candidate makes the version it replaced live again.

Canaries guard themselves. While a candidate serves runs, in a canary or in its first 50 runs after promotion, it is compared with the version it was built from once it has 10 finished runs. If its success rate is more than 10 points lower, or its cost per run more than 10% higher, the canary is stopped or the promotion rolled back, with the reason on the candidate.

From the CLI:

lgr improvements                    # candidates and their state
lgr improvements imp_8f2c           # one candidate, with its change and numbers
lgr promote imp_8f2c --traffic 0.1  # canary on 10% of runs
lgr promote imp_8f2c                # make it live
lgr reject imp_8f2c --reason "Answers got shorter"
lgr rollback imp_8f2c

Only runs that name the agent without a version take part in a canary. Runs that name a version, such as support-bot@v3, always get that version.

Coming next

These aren't available yet. They are what we are building next.

Lagrange learns from your runs

Today an improvement changes the agent's configuration, and the harness stays the same. Lagrange, our own harness, will also learn from each agent's traces: how it plans, what it keeps in context, which tools it reaches for first, and when it checks its work. It will tune how it runs that agent, and those changes will go through the same candidates, replays and canaries, so you still see the numbers and decide.

Workflows, optimized step by step

An agent will be able to run as a workflow of steps in one sandbox, such as fetch, review and report. Each step will have its own instructions and model, and share the working directory with the others. Improvements will then work per step:

  • run a simple step on a cheaper model while the hard step keeps the strong one,
  • propose splitting an agent that does several jobs into steps,
  • replay a single step on recent inputs to measure a change to it alone.