Skip to main content
[plugins.stop_rule] in piloop.toml says when a campaign stops, and when it holds. The setup writes the hours and the cap in USD of model tokens that you give it:
Any one limit stops the campaign. Without a limit, the campaign has no end. These are the limits of the built-in stop rule, limits: piloop status enwik8 shows the progress against each limit:

What a stop does

The daemon tells the running implementers to save their work and stop, and ends them 10 minutes later ([agents] wrap_up_grace). It drops the queued runs. Their submissions are still scored. To go on after a stop, raise the limits and run piloop init, or reopen the campaign. Either way, the limits count from then.

A hold

A hold is not a stop. While a hold_at fact is at its limit, or unknown, nothing new starts. What runs finishes and is scored. The daemon escalates once. At hold_at = { spend = 1000 }:

What a campaign spent

Each fact source reads a fact that a limit or a section can use: models_usd is the API-equivalent cost from genai-prices, not an invoice: a subscription bills otherwise. A model without a price makes the fact unknown, never 0. An alias such as sonnet has no list price, so give it one, in USD per million tokens:
piloop reads each agent’s tokens from its harness’s session file into agent_sessions.usage: about once a minute while the agent runs, and when it ends. max_tokens limits their total over the campaign, and hold_at sees a running agent’s spend too.

Spend outside piloop

The built-in command source runs a command that writes {"metrics": {"<name>": <value>}} to $PILOOP_RESULT_FILE. spend adds the fact to the sum, and hold_at holds the campaign at a limit of the sum:
The daemon runs the command every interval seconds (300 by default), at the repo’s root, with the daemon’s environment. Give it its keys as secrets. When piloop init changes the command, the readings of the old command no longer count: the daemon runs the new one at once. GET /v1/campaigns/enwik8/spend returns each part and the sum. A plugin can add a fact source or another stop rule: see Rules and facts.