Module 5 · Evaluation & observability

Optimizing cost and latency at scale

5 min read

A prototype costing a few cents per run can cost thousands per month in production. And a note that takes three minutes to arrive stops being used. Optimizing cost and latency is a discipline in its own right — with one golden rule: measure before optimizing, and judge cost per successful task, not per call.

Step 1: measure

The tracing from module 5 provides everything you need. The cost of a call is computed from actual tokens, read from response.usage:

PRICES = {  # $ per million tokens (input, output) — keep up to date
    "claude-opus-5-5": (4.00, 20.00),
    "claude-sonnet-5-5": (2.00, 10.00),
    "claude-haiku-5-5": (0.10, 0.50),
}

cost = (input_tokens * price_in + output_tokens * price_out) / 1_000_000

Run your evaluation set and produce a profile per node:

NodeCalls / runInput tokens (avg.)Output tokens (avg.)Share of costDuration (avg.)
planner1………%…
researcher3………%… (parallel)
writer1.6………%…
critic1.6………%…

This table, filled in with your measurements, almost always points to one or two nodes accounting for most of the cost or latency. Optimize those, and only those.

Think per successful task. A configuration that is cheaper per call but triggers an extra revision on a third of notes may cost more overall. The right indicator: total cost ÷ number of approved notes.

Step 2: no-compromise gains

Start with optimizations that don't degrade quality.

Prompt caching

Agents' system instructions are identical from one call to the next: the ideal case for caching (lesson 3.3). Cache reads cost a fraction of the normal input price. Stable prefix first, variable content after, and check cache_read_input_tokens.

Input hygiene

  • Summaries rather than raw documents between agents (lesson 3.3).
  • Bounded, paginated tool results (lesson 1.4).
  • No replaying of the full history to every agent.

Output hygiene

Output tokens cost several times more than input tokens. Ask for outputs sized to the need: "300 words maximum" for the writer, compact schemas for agent-to-agent exchanges, no useless fields.

Parallelism

Send runs researchers in parallel: the latency of the research phase is that of the slowest researcher, not their sum. Check in the traces that researcher spans actually overlap.

Batch processing

For work that doesn't need an immediate answer (nightly evaluations, reprocessing a corpus), the Batches API processes requests asynchronously at a substantially reduced price.

Step 3: trade-offs to measure

These levers can degrade quality: change only one at a time, and measure on your evaluation set (module 5).

Effort level

With the same model, effort (low, medium, high, xhigh, max) trades thoroughness against tokens used:

complete(SYSTEM_WRITER, prompt, effort="low")      # less thinking, more direct answers
complete(SYSTEM_CRITIC, prompt, effort="high")     # structuring decision: more effort

Classification, routing or rewording tasks often do fine at low effort; planning and critique benefit from higher effort. Before multiplying models, first test the most capable model at lower effort: it's often a better trade-off, and a single model simplifies caching and operations.

Model tiering

Handing bounded, repetitive tasks to an economical model (Atlas's researchers on claude-haiku-5-5) can cut the cost of those nodes significantly — provided quality holds. Check on the evaluation set: does summary faithfulness stay at the same level?

Fewer agents or iterations

  • MAX_REVISIONS at 1 instead of 2?
  • A single researcher when the question is simple (the planner can return a single sub-question)?
  • Dropping the critic for some question categories?

Every agent removed is a certain gain in cost and latency, and a risk to quantify in quality.

Optimizing perceived latency

Perceived latency matters as much as actual latency:

  • Stream progress: graph.stream(..., stream_mode="updates") lets you show "Researching (2/3)…" while researchers work.
  • Stream the final text as it's generated rather than in one block at the end.
  • Hand back control early: for long processing, immediately return a task ID and notify at the end (lesson 6.3).

The optimization dashboard

IndicatorWhy
Average cost per approved noteThe reference economic indicator
p50 and p95 latencyThe average hides the slow cases that frustrate users
Average number of revisionsShows how well the critique loop converges
Cache read rateChecks that caching works
Quality score (judge, sample)Ensures savings don't degrade the outcome

Key takeaways

  • Measure per node, and think in cost per successful task.
  • No-compromise gains first: prompt caching, input and output hygiene, parallelism, batch processing.
  • Then trade-offs, one at a time, measured: effort, model tiering, number of agents and iterations.
  • Test the most capable model at reduced effort before building a model cascade.
  • Take care of perceived latency: streamed progress, early response for long tasks.

Hands-on

  1. Run 10 questions with the real model and fill in the per-node profile table.
  2. Move researchers from WORKER_MODEL to the main model: measure the difference in cost and quality.
  3. Test the writer at low then high effort on the same set: does the average number of revisions change?

Resources