Go Deeper 7 min read Updated Sep 14, 2026

Cost and Latency: Making Agents Fast and Affordable

Once an agent is reliable enough to trust, a different constraint tends to show up: it's slow, or it's expensive, or both - and multi-step agents are particularly exposed to this, because every loop iteration is another full model call, and a task that takes ten steps costs roughly ten times what a single call would.

Where the cost actually comes from

Every planning step re-sends the accumulated context - the original instructions, the conversation, every prior tool call and result - so cost doesn't grow linearly with the number of steps, it grows worse than that, because each new step pays for all the previous ones' context too. An agent that takes twelve steps on a task that could have taken four isn't just three times slower - depending on how much context has accumulated, it can be considerably more than three times the cost.

Step 1 small context Step 2 + step 1's context Step 3 + steps 1&2's context Step N growing context = growing cost

Each step pays for all the context that came before it - cost compounds as a loop runs longer.

Model routing: not every step needs your strongest model

A common and effective optimization is using different models for different steps based on how much reasoning they actually require - a fast, cheap model for simple classification or straightforward tool selection, and a stronger, more expensive model reserved for the step that actually needs deep reasoning. This is a natural fit for the multi-agent supervisor pattern from earlier in this series: the supervisor and simple sub-agents can run on a cheaper model, with the specialized reasoning-heavy sub-agent using the strongest one available.

Caching repeated work

Agents frequently make the same or very similar tool calls repeatedly within a run, or across runs from different users asking similar questions - caching tool results (especially for calls that are expensive or slow, like a web search or a large database query) avoids paying that cost twice. Beyond tool-level caching, many model providers also offer prompt/context caching, which reduces the cost of re-sending the same unchanging portion of context (like a long system prompt or tool definitions) across multiple calls in the same run.

Trimming context deliberately

Since cost compounds with context size, actively managing what stays in context - summarizing older steps rather than carrying the full raw history forward, dropping tool results that are no longer relevant to the current step - directly controls cost, not just quality. This is the same context-management discipline covered in the memory guide, applied here specifically as a cost lever rather than a correctness one.

Setting a real budget, not just an iteration ceiling

The iteration ceiling from the agent loop guide caps how many steps a run can take, but a step count alone doesn't map cleanly to cost, since steps vary a lot in how much context they carry. Production systems often track and cap actual token spend per run, not just step count, which catches the case where a run stays under the iteration ceiling but still burns far more than the task was worth because each step's context kept growing.

Where to start if cost is already a problem: before reaching for model routing or caching, first check whether the agent is actually taking more steps than the task needs - a failure mode from the previous guide (unproductive loops, tool misuse) is very often the real source of runaway cost, not the architecture itself. Fixing reliability issues first tends to fix a meaningful chunk of the cost problem for free.
You've now covered the full arc: what makes something an agent, the loop, tools, memory, evaluation and deployment, multi-agent systems, design patterns, failure modes, and cost. From here, the best next step is building one, watching where it actually struggles, and coming back to whichever guide addresses that specific struggle.
Share this guide

Was this guide helpful?

Thanks for the feedback!

Want more hands-on AI builds like this?

APA Mastery runs live, practical sessions on working with modern AI tools - not just theory.

See What's On →
← PreviousCommon Agent Failure Modes