How do you handle agent spend and runaway tool calls?

Quick question for people running CrewAI agents in real workflows:

How do you control costs when agents can call tools or paid APIs?

Especially:

  • per-agent budgets
  • hard stops if something loops
  • visibility into what each agent spent

Right now is it mostly manual monitoring, provider limits, or do you have actual controls set up?

Want to hear what’s working in practice.

What’s worked for me is three layers, none of them in the prompt.

On the agent, set max_iter, max_rpm and max_execution_time so a looping agent hits a wall instead of running all night. Wrap each paid tool in a small BaseTool subclass that checks a running total in something durable (even a SQLite row keyed by agent and day) before calling the API. Once the cap is hit it refuses and returns a plain error string the agent can read. For visibility, give each agent or crew its own API key or project on the provider side, so the provider’s usage page splits spend for you and you can revoke one key without touching the rest.

Provider-level limits are still a good last backstop, but they apply to the whole account, so they’re too coarse to be the only control.

The layered caps in the last reply (max_iter, a durable per-agent counter, per-key usage) are the right way to stop spend. They stop the run, though, and don’t tell you what the loop looked like.

One example I keep: a shopping agent called open_url with the identical search URL more than ten times and ended with an empty answer. A budget would have cut it off, but only a trace check shows that the repeated identical call was the bug. I run those checks on recorded runs with agentest: offline, deterministic, no API key, 165 tests. Replay a run you already stopped for cost and see whether it flags the loop. Try it on one of your own agent runs and tell us what it caught or missed.

pip install agentest-ai