Skip to the page
Tecyfy

AI agents · intermediate · About 10 minutes

The agent bill that grew 5 times in a month

A coding agent's monthly bill went from $1,200 to $6,700 while the number of tasks rose by a fifth. Find where the money went before you cut the wrong thing.

You look after the team's AI coding agent and its budget.

What happened

Your team uses an AI coding agent to fix failing tests. It reads the code, runs the tests, edits files and runs the tests again until they pass.

The agent's line on the bill was $1,200 in August and $6,700 in September. The team ran about 20% more tasks in September. The model and its price did not change. Finance would like an explanation and a plan by Friday.

The incident is made up. How things work in it is real, with sources at the end.

The evidence

Everything you need is here. Read it before you decide.

01One typical task, August against September(Table)
AugustSeptember
Turns (model calls) per task1240
Conversation size at the first turn20,000 tokens20,000 tokens
Conversation size at the last turn50,000 tokens120,000 tokens
Input tokens processed, whole task420,0002,800,000
Output tokens written, whole task50,00060,000
Input tokens read from cache00

The team's price is $3 per million input tokens and $15 per million output tokens.

02What changed on 1 September(Note)

To help the agent debug, someone changed its setup to paste the full output of every test run into the conversation, not just the failures. A test run prints about 2,500 tokens.

03How the agent calls the model on every turn(Code)
while not done:
    reply = client.messages.create(
        model=MODEL,
        system=AGENT_INSTRUCTIONS,      # same text every turn
        tools=TOOLS,                    # same text every turn
        messages=conversation,          # everything so far, sent again
    )
    conversation.append(reply)
    conversation.append(run_tools(reply))  # test output goes in here

Your decisions

Decision 1 of 2

  1. Decision 1

    Where did the money go?

The ideas behind it

LessonSame price per token, smaller bill: what a job costs