▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
AI Agents in Production · Lesson 10 of 14 · 2 min read · 5 min video
Cost and latency control
Caching, model routing, smaller contexts and step limits that cut the bill.
📄 Download slides (PDF)· free sign-upAn agent that costs ₹40 per task or takes a minute to reply won't survive real traffic. Most of the bill comes from a few habits you can fix.
Where the cost comes from
Every step re-sends the whole conversation. A 10-step run with a 5,000-token context pays for about 50,000 input tokens, not 5,000. So:
Cost ≈ steps × context size × price per token
Shrink any one of these and the bill drops.
The levers
- Fewer steps: better tools (one
get_order_summaryinstead of three lookups), clearer instructions and a hard step limit - Smaller context: trim old tool results, return only needed fields, summarise long histories
- Prompt caching: keep the system prompt and tool list identical at the start of every call, so the provider can cache them and charge much less for repeated tokens
- Model routing: a small, fast model for easy steps (classify, extract), and the big model only for hard reasoning
- Response caching: the same question with the same data? Reuse the last answer
Latency tricks
- Stream the final answer so the user sees words immediately
- Run independent tool calls in parallel
- Show progress ("Checking your order…") during long tasks
- Move slow tasks to the background and notify the user when done
Budget per task
Give every task a budget, such as ₹5 and 30 seconds. If it's reached, stop cleanly and hand off to a human, instead of letting it keep trying.
In one line
Agent cost is steps × context × price, so cut steps, trim context, cache prompts, route easy work to small models, and give every task a hard budget.
Share with a friend