Skip to content
Operations / Cost & Performance

Budget and control agent cost and latency

  • BP-0041
  • v1.0.0
  • draft
  • guideline
  • role: orchestrator
  • role: implementer
  • stage: plan
  • stage: build
  • stage: operate
  • updated 2026-11-24
  • reviewed 2026-11-24
  • next review 2027-05-24
  1. MUST set a budget for every unattended run: maximum turns, tokens, spend and wall-clock time, enforced by the harness, with the run stopping and reporting when a cap is hit.
  2. MUST stop loops: cap retries per step, detect repeated identical tool calls or errors, and escalate to a person instead of trying again.
  3. SHOULD measure cost and time per completed task (not per call), and track them over time alongside quality (BP-0006) so savings that lower quality are visible.
  1. MUST keep context lean: load by reference and retrieve passages, not whole files or documents (BP-0011, BP-0028).
  2. SHOULD order prompts so stable content comes first (tool definitions, system instructions, shared documents) and per-request content last, and enable prompt caching on the stable prefix. Do not put timestamps or per-request values before the cache point, or every request pays to write the cache and none reads it.
  3. SHOULD check cache effectiveness from the usage figures (cache-read versus cache-write versus uncached input tokens) rather than assuming it works.
  1. SHOULD route each step to the smallest model that meets its quality bar (for example a small model for classification and extraction, a larger one for planning and review), and verify the bar with evaluations before switching.
  2. SHOULD use batch processing for work that does not need an immediate answer (bulk classification, nightly summaries), where the provider offers it at lower cost.
  3. SHOULD run independent sub-tasks in parallel to cut wall-clock time, but count the extra tokens each sub-agent spends re-reading context, and prefer one agent for small tasks.
  4. SHOULD cap output length per step, and ask for structured output where free text is not needed.

Any agent workload that runs repeatedly, unattended, at scale, or on a budget.

Lever Before After
Caching 18k-token system prompt + tools sent uncached every turn Stable prefix cached; most input billed at cache-read rate after the first call
Routing Largest model for every step Small model tags 500 receipts; large model reviews the 20 it flagged
Context Whole repository files read each turn Code index queries; only the needed spans
Loops Agent retries a failing build 40 times Two retries, then stop and report
Scheduling Nightly report runs interactively Submitted as a batch job
  • No budget on an unattended agent.
  • A timestamp at the top of the system prompt, defeating the cache.
  • Switching to a cheaper model without re-running evaluations.
  • Ten parallel sub-agents for a task one agent finishes in five minutes.
  • Turn, token, spend and time caps enforced; loops detected
  • Cost and time per completed task tracked with quality
  • Stable prefix first and cached; cache hits checked
  • Smallest adequate model per step, verified by evals
  • Batch for non-urgent work; parallelism justified; output capped