Interactive tool

Agent Token Compounding Simulator

Every time an AI agent calls a tool, the whole conversation goes back to the model. Watch the tokens and the cost pile up for an order-processing agent, and see what prompt caching does and doesn't save.

Input (new) Cache read Output

AI models are stateless. They remember nothing between calls. So when an agent loops (think, call a tool, read the result, think again), it has to send the whole conversation back to the model every time. Each tool call makes the next request bigger, and the cost compounds.

Model calls for one order
–
one tool per turn, no caching
Unique content
–
tokens in the final conversation
Tokens actually billed
–
–

The agent loop

System prompt + user requestInstructions, tool definitions, "process order SO-48213"
→
ModelReads everything, decides which tool to call
→
Integration layerLogic App, Function or API behind APIM runs the tool
→
Result appendedThe tool's response becomes part of the conversation

↺ Then the whole conversation, including every earlier result, goes back to the model, until the agent is done.

The scenario

A fictional order-processing agent is asked to process a 10-line sales order. With one tool call per turn it makes 13 model calls:

  1. Request 1: system prompt + user request. The agent calls get_order.
  2. Requests 2–11: the order header shows 10 lines, so the agent calls get_order_line once per line. Each call resends everything before it.
  3. Request 12: with every line checked, the agent calls submit_fulfilment and splits the order across two warehouses.
  4. Request 13: the agent writes its final summary.
The first request is – tokens. By request 13 the agent is sending – tokens, almost all of which the model has already seen.

Reading the simulator

Prompt tokensEvery token sent to the model, across all calls: the whole conversation, every time. It splits two ways: input (the new bit) and cache read (everything sent before).
Input tokensThe new bit of each request: what was added since the last call (the model's last reply plus the new tool result). Not in the cache yet, so billed at the full input price.
Cache readEverything that was already sent on the previous request. The provider serves it from its cache, billed at a fraction of the input price (0.1× by default, editable on the Simulator tab).
OutputTokens the model generates: its reasoning text and tool calls. Priced higher than input, but small in an agent loop.
Total tokensPrompt tokens + output for the whole order. Caching does not change this number: cached tokens are still sent and counted, they are just billed at a lower price. Caching changes the cost, not the token count.
Cost this orderWhat this one order cost, with the no-cache cost underneath for comparison.
Conversation panelEach message card lights up when it is resent. The coloured left edge shows whether that message was read from cache or sent as new input on the latest request.
Tokens per requestOne bar per model call. The bars get longer each call: that is the compounding.
AmplificationTokens billed ÷ unique content. On average, how many times each token in the conversation was paid for.

Matching this to your API logs

In your telemetry (OpenTelemetry spans, API usage logs) you will usually see the new bit as input tokens and the rest as cached tokens. The simulator uses the same split:

SimulatorWhat you typically see in usage data
Input tokensUncached input: the new bit added since the last request. Anthropic-style APIs report it as input_tokens.
Cache readTokens served from cache. cache_read_input_tokens (Anthropic-style) or prompt_tokens_details.cached_tokens (Azure OpenAI / OpenAI).
Prompt tokensInput + cache read. Azure OpenAI reports this total as prompt_tokens, with cached tokens as a subset of it.
Outputoutput_tokens / completion_tokens
Prompt tokens = input (the new bit) + cache read. A small input figure in your logs does not mean a small prompt: the whole conversation is still sent on every call, and most of it shows up as cached. OpenTelemetry instrumentation libraries differ in whether gen_ai.usage.input_tokens includes cached tokens, so check whether your spans carry separate cache attributes. Hover any bar on the Simulator tab to see the split for that request.

The two levers, plus caching

Tool calls

One per turn · Parallel

Fetching each order line in its own turn means 11 trips round the loop. Asking for all 10 lines in one turn cuts the agent to 4 model calls. It's the same lesson as chatty vs. coarse-grained APIs.

Caching

Automatic prefix caching · always on

Each request starts with everything the previous request sent, so the provider serves that part from cache and only the new bit is billed at full price. Over a whole run, every token is billed as input exactly once; every resend after that is a cache read. Caching makes the resend cheaper, but it does not make it go away: the tokens are still sent and still counted. The prefix must match exactly, so anything that changes early (a timestamp in the system prompt, for example) breaks the cache for everything after it.

Tool payload

Trimmed · Raw API response

Every token a tool returns is paid for again on every later call. Passing a raw API response (links, audit trails, metadata) straight to the model can multiply the cost of the whole run.

What this means for integration architects

Assumptions

Want to go deeper on Azure AI and cloud costs?

I cover this kind of thing on the podcast and in the playbook. If it was useful, share it with whoever owns your AI bill.