What is the improvement loop
The agent improvement loop is how you change your agent and prove that the change made it better. When you change anything in the harness, the prompt, a tool description or the model, something that worked before can break five turns down the line. So you need a loop to keep improving the agent, in cost, in latency or in what it can handle, without dropping the quality.
The loop starts with a definition of quality that you can run. That definition is a test suite of scenarios: simulated conversations with the criteria the agent has to meet, all of which pass on the agent you trust today. The judge in each scenario reads the whole conversation together with the agent's traces, passes or fails every criterion you wrote, and explains the verdict.
Everything else you care about, turns, tokens, cost and latency, is a metric you push down while that suite keeps passing. The same run that gives you the verdicts also gives you those numbers, so you see in one place whether the change paid off and whether it cost you anything.
The loop
| Step | What you do | Where |
|---|---|---|
| 1. Define quality | Write five to ten scenarios from real conversations, with the criteria the agent must meet. Run them on the model and prompt you trust. Every scenario passes: this is the baseline. | Scenarios, Test suites |
| 2. Measure | Read the pass rate, the cost and the reply latency of the baseline run. | Results |
| 3. Change one thing | Ask Langy or your coding agent to read the run and come back with a hypothesis and one change: a smaller model, a rewritten tool description, a tool that validates its input, a shorter prompt, a lower iteration cap. One change per run, so the result has one cause. | Reduce turns |
| 4. Compare | Run the same suite against the changed agent, next to the baseline. Keep the change when the pass rate holds and the metric moved. | Compare agents |
Repeat from step 3, and put the suite in CI so a later change cannot undo the gain: see Run from CI.
Where the changes come from
The hypotheses come out of the last run. When a criterion fails, the judge's reasoning quotes the turn where it happened, and the trace of that turn shows what the agent saw and did; when a scenario passes but takes ten turns, you usually find the same tool called twice in a row in the conversation. There are two ways to turn that into a change:
- Guided. Langy, or your coding agent with the
langwatchCLI, reads the results and the traces and comes back with a hypothesis and the change for it, and you run the suite on that change to prove it made the agent better. See Prompt optimization with Langy for the prompt case. - Algorithmic. Run a DSPy optimizer: it rewrites the instructions and the tool descriptions and scores every candidate by running the suite, and GEPA also feeds the judge's reasoning back in as the feedback for the next candidate. See Optimize with DSPy.
Use the guided loop when the change is in code, in a tool or in the harness, since no optimizer can touch those, and when you want to review each change. Use an optimizer when the change is in text and you have the budget to run the suite fifty or so times.
Guides
agent-improve and scenarios skills for your coding agent).