Cost ≈ steps × context size × price. Levers, in order of payoff:
1. Cut steps — better tool descriptions and a planning step remove whole iterations. 2. Cut context — summarise old turns; truncate tool output; never resend a full document. 3. Route models — strong model for planning and final answers, cheap model for extraction and routing. 4. Cache — prompt caching on the stable system+tools prefix; result caching on pure tools. 5. Parallelise — run independent tool calls concurrently.
ts
const [orders, gas] = await Promise.all([tools.run("get_orders", a), tools.run("get_gas", b)]);Keep the system prompt and tool schemas byte-stable across requests so provider prompt caching hits; a timestamp injected at the top of the prompt silently destroys every cache hit.
Track cost per successful task, not per request — an agent that costs twice as much but succeeds first time is cheaper.
Exercise: instrument every run with steps, prompt tokens, completion tokens, and cost; plot cost per successful task before and after adding tool-result truncation.