Urgent.News

What's breaking now, across thousands of outlets.

AI

5 Mistakes That Let a .NET AI Agent Burn Through 40 Tool Calls

I thought I had a budget. I set tools on FunctionInvokingChatClient , shipped a support agent, and figured forty iterations was plenty of room for a sticky ticket. Then an offline replay of a bad day showed one chat message chewing through 41 model calls and 40 tool calls. Another scenario pushed past a million input tokens. A third issued two refunds for the same order. Nobody wrote a while…

5 Common Errors That Cause a .NET AI Agent to Exceed Tool Calls

1. Ignoring the 40 iteration limit

The default MaximumIterationsPerRequest is 40, which acts as a fuse against infinite tool loops. However, this is not a budget for tokens or dollars, nor does it prevent repeated calls. Once the limit is reached, the client removes tools and continues with the next request. The real issue lies in the lack of proper budgeting within the tool loop.

2. Failing to detect tool call duplications

Many developers try to detect loop conditions by matching raw strings of tool calls. However, models often use different formatting for the same intent (e.g., "ORDER 4012" vs. "order 4012"). To accurately identify loops, developers should fingerprint tool calls by combining the tool name with canonical arguments and hashing the result. This ensures that the loop detection works as intended.

3. Only monitoring consecutive exact repeats

While fingerprinting helps, it only catches loop conditions when the same call repeats consecutively. There are other scenarios where the model gets stuck, such as searching for the same information multiple times or rephrasing the query without changing the fingerprint. To address these cases, developers should implement additional checks that monitor identical calls, regardless of their position in the conversation.

4. Metering only the outer FunctionInvokingChatClient

Budget tracking for model calls, tokens, cost, and time should encompass every round-trip within the tool loop. When only monitoring the outer FunctionInvokingChatClient, developers miss the twelve inner calls made by the model. To ensure accurate budget monitoring, the budget should be checked before each model call, and usage should be recorded after each iteration.

5. Lack of proper handling for tool errors

When a tool fails, developers often stop invoking tools altogether or set a Terminate flag. While these approaches might seem effective, they can lead to abrupt termination and loss of important context. A better strategy is to leverage the GuardAction interface, which provides options like GuardAction.Stop (to hard stop), GuardAction.Nudge (to issue a warning message), or GuardAction.ReplayResult (to allow the model to continue with the previous result).

By incorporating these options, developers can maintain a more controlled and graceful handling of tool errors.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

THE AI RECOMMENDATION ECONOMY: Measuring the Market Between AI Answers and Human Decisions

The Market Is Changing Before We Have Learned How to Measure It For decades, businesses have competed for visibility. They competed for search rankings, advertising impressions, website traffic, brand…

  • Companies must consider AI's influence on purchasing decisions alongside traditional metrics.
  • The AI Recommendation Economy has seven layers to analyze businesses' roles in the emerging market.

More from Tuesday 3 November →