An agent is not a single model call. It is a loop: read the request, plan, call a tool, read the result, decide again, and finally write the answer. Each stage has its own cost and its own failure mode. If you only measure the final response, you miss where the money and the quality go.

Here is the lifecycle of one agent task and what to watch at each stage.

1. Intake

The request arrives with context: a user message, a system prompt, retrieved documents, maybe a conversation history. This is the first cost decision. Every token you include here is input the model pays to read. If the system prompt is long and stable, cache it. If the history is long and mostly irrelevant, trim it. The intake stage is also where prompt-injection risk enters; treat untrusted text as data, not instructions.

2. Plan

The model decides what to do next. A simple task might need one plan; a complex one might need several. The plan is usually output tokens, so long internal reasoning is expensive even when the user never sees it. Cap the number of planning steps. A loop that re-plans without new information is the first place to look when a bill is higher than expected.

3. Tool call

The agent calls an API, a database, a search index or a file system. The tool result comes back and becomes input for the next step. Tool results are often larger than they need to be. Return only the fields the next step needs. If the tool call fails, the retry is another model call and another chance to loop. Count retries per task; they are a hidden multiplier.

4. Observation and synthesis

The model reads the tool result and writes the answer. This is the output meter. If the agent summarizes a long document, the summary is output tokens. If it repeats the whole document back, that is output tokens too. Separate user-visible output from internal reasoning so you can see which one is driving the bill.

5. Retry and escalation

When a step fails or the answer is wrong, the agent retries. Each retry resends context. A task that succeeds on the third try costs more than the same task that succeeds on the first. Track success rate per stage, not just per task. A stage with a low success rate is a cost leak even if the final answer looks fine.

What to measure

For each stage, log four numbers: calls, input tokens, output tokens and elapsed time. Then compute cost per successful task from the published rates. On the Standard tier those rates are $0.10 per 1M cache tokens, $0.40 per 1M input tokens and $1.60 per 1M output tokens. On Premium they are $0.20, $0.80 and $3.20. Transcription is a separate meter billed by audio duration and is included free on the Premium pay-as-you-go tier.

How to keep it predictable

Put a cap on the loop. Cache stable text. Send only the context a step needs. Log tokens per stage so you can see which part of the lifecycle is expensive. And keep the provider behind an OpenAI-compatible base URL, so a cost or capability decision is a configuration change, not a rewrite.

WebWright publishes an OpenAI-compatible API at https://webwright.ai/v1. The documented endpoints are GET /v1/models, POST /v1/chat/completions and POST /v1/audio/transcriptions. Model ids are wren-r1 and wren-r1-fast for chat and whisper-large-v3-turbo for speech to text. The trial gives you 4 days and 1M input tokens to measure your own lifecycle. It converts to Hobby at $9 per month when the trial ends or its limits are exceeded.

If you want help finding which stage in your agent lifecycle is driving the bill, book a 30 minute consult and bring one real task trace.

The WebWright Team