Skip to main content

Fixed: Microsoft Agent Framework Agent Calls a Tool Again After It Succeeded

· 9 min read
Jagdish Kumawat
Founder @ Dewiride

A Microsoft Agent Framework agent that books meeting rooms booked K2, then booked Denali as well, and told the user that no room was free. I first blamed parallel tool calls, and that was wrong. The model called the tool one room at a time, and read the tool's own success message, K2 is booked at 10:00., as K2 is taken. A success message that can't be read as a failure fixed it.

What I Was Doing​

I was building a small console agent for a guide about validating a tool's arguments: How to Validate a Function Tool's Arguments in C# with Microsoft Agent Framework. The agent books meeting rooms for today with one tool, book_room(room, startHour). Everest is taken at 10; K2 and Denali are free. When a room is taken, the tool returns a message with the free rooms, so the model can choose another one. The end of the tool looked like this:

Program.cs (the end of BookRoom, before the fix)
if (!taken.Add(startHour))
{
string free = string.Join(", ", bookings.Where(b => !b.Value.Contains(startHour)).Select(b => b.Key));
return $"{room} is already booked at {startHour}:00. Free at {startHour}:00: {free}.";
}

return $"{room} is booked at {startHour}:00.";

taken.Add(startHour) books the hour and returns false when it was already taken. The app prints a line every time the tool runs, then every result the model received, then the agent's answer. I asked: I need a meeting room at 10. Everest if it is free, otherwise any room.

What I Expected​

The tool refuses Everest and lists K2 and Denali, the model books K2, and the answer says so.

What I Got​

macOS-style terminal window showing dotnet run for the RoomAgent app: book_room was called three times, for Everest, K2 and Denali at 10; the model received Everest is already booked at 10:00. Free at 10:00: K2, Denali., then K2 is booked at 10:00. and Denali is booked at 10:00.; and the agent answered Sorry, Everest was unavailable, and K2 and Denali were also booked at 10:00.

Output
(book_room was called with room = Everest, startHour = 10)
(book_room was called with room = K2, startHour = 10)
(book_room was called with room = Denali, startHour = 10)
(the model received: Everest is already booked at 10:00. Free at 10:00: K2, Denali.)
(the model received: K2 is booked at 10:00.)
(the model received: Denali is booked at 10:00.)
Sorry, Everest was unavailable, and K2 and Denali were also booked at 10:00.

Both bookings worked: the tool reserved K2 and Denali at 10. Yet the answer told the user that nothing was free. Two rooms blocked, nobody told, and the person who asked has no room.

What I Checked​

1. Parallel tool calls? A wrong guess. All three book_room lines came before any result, so I assumed the model had asked for all three rooms in the same turn. ChatOptions has a setting for exactly that. Its reference: false if the IChatClient is asked to return a maximum of one tool call per request, with the warning that the underlying provider is not guaranteed to support or honor this flag. I set it through the agent's options:

Program.cs (what I tried first)
.AsAIAgent(new ChatClientAgentOptions
{
ChatOptions = new ChatOptions
{
ModelId = "gpt-5.6-luna",
Instructions = "You book meeting rooms for today. Answer in one or two sentences.",
Tools = [bookRoom],
// Ask the model for at most one tool call at a time.
AllowMultipleToolCalls = false,
},
});

Three runs, and each time the same three calls, Everest, K2 and Denali, and the same wrong answer in different words, such as All rooms are booked at 10:00 today, so I couldn’t reserve one.

2. One call per turn after all. The order of the printed lines proved nothing: the tool prints while the run is going, and the results are printed after it has finished. So I printed each message of the run, with its role and what it contained, by adding this after Console.WriteLine(response);:

Program.cs (what I added to see each message)
foreach (var m in response.Messages)
{
Console.WriteLine($"[{m.Role}] " + string.Join(", ", m.Contents.Select(c => c switch
{
FunctionCallContent f => $"call {f.Name}({string.Join(",", f.Arguments!.Values)})",
FunctionResultContent => "result",
TextContent => "text",
_ => c.GetType().Name,
})));
}

The output:

Output (each message of the run)
[assistant] TextReasoningContent, call book_room(Everest,10)
[tool] result
[assistant] call book_room(K2,10)
[tool] result
[assistant] call book_room(Denali,10)
[tool] result
[assistant] text

One call, its result, the next call: the model went one room at a time, with AllowMultipleToolCalls set to false and also with it set to true. My first guess was wrong, and the setting had nothing to fix here. I removed it again.

3. What the model read. Each call came after the model had read the result before it. The first result said Everest is already booked at 10:00. The second said K2 is booked at 10:00., in almost the same words.

Why It Happens​

The model knows nothing about a tool's call except the text it sends back. K2 is booked at 10:00. can mean I booked K2 for you or someone has booked K2. Right after Everest is already booked at 10:00., the model read it the second way: K2 is taken too, try the next free room. Denali got the same answer, and the model concluded that every room was taken. Each of those "refusals" was a real booking.

Microsoft's guide to adding tools asks for clear error messages, so the model can reason about what went wrong and try again or inform the user. A success message needs the same care: the model reasons from it in exactly the same way.

The Fix​

Make the success message impossible to read as a refusal. Replace the last line of BookRoom:

Program.cs (the last line of BookRoom)
return $"Done: {room} is now reserved for you at {startHour}:00.";

Done says it worked, and reserved for you says for whom. The refusal still starts with the room's name and is already booked, so the two can't be confused.

After the Fix​

macOS-style terminal window showing dotnet run for the RoomAgent app: book_room was called for Everest and then for K2 at 10; the model received Everest is already booked at 10:00. Free at 10:00: K2, Denali. and then Done: K2 is now reserved for you at 10:00.; and the agent answered Everest was unavailable, so I booked K2 for you at 10:00 today.

Output
(book_room was called with room = Everest, startHour = 10)
(book_room was called with room = K2, startHour = 10)
(the model received: Everest is already booked at 10:00. Free at 10:00: K2, Denali.)
(the model received: Done: K2 is now reserved for you at 10:00.)
Everest was unavailable, so I booked K2 for you at 10:00 today.

Two calls: Everest, refused; K2, Done. One room booked, and the answer is right. I ran the fixed app eleven times, four of them with AllowMultipleToolCalls set to false again, which changed nothing. Ten runs booked K2 and stopped. In one run the model booked Denali as well, and this time said so: Everest was unavailable, so K2 has been reserved for you today at 10:00. (Denali was also inadvertently reserved.)

So the misreading is gone, but a model can still decide to call a tool once too often. When a rule must hold, such as one room per person for each hour, a clear message isn't enough: check the rule in the tool too, the same way the tool checks that a room is free.

Common Mistakes​

MistakeWhat happensDo this instead
A success message that sounds like a refusalThe model treats the booking as refused and calls the tool againStart it with Done and say what now belongs to whom
Judging the call order from the tool's own outputLines printed while the run is going look like one batch of callsPrint each message of the run, with its role, as in step 2
Relying on the model to stop after one bookingAn extra booking can still happenCheck rules that must hold, such as one room per person, in the tool

Troubleshooting​

SymptomLikely causeFix
The agent says it failed, but the tool did the workThe model read the success message as a failureMake the success message unmistakable
The agent books several rooms for one requestEach success was read as a refusal, so the model kept tryingThe same: a clear success message, and a rule in the tool if it must never happen

FAQ​

Would AllowMultipleToolCalls = false have helped?​

Not here: the model already made one call per turn. The setting asks the model for at most one tool call in each response, and its reference says that this does not affect the ability to perform multiple function calls in sequence, which is what happened.

Could the tool return an object instead of text?​

Yes, and that makes the two outcomes even harder to confuse: an object with "booked": true or "problem": "…" reaches the model as JSON with an explicit field. Text is fine as long as success and failure read differently.

Conclusion​

The agent called book_room again after it had succeeded because the model read K2 is booked at 10:00. as K2 is taken, right after a real refusal in almost the same words. The calls were one at a time, so limiting parallel tool calls changed nothing. Done: K2 is now reserved for you at 10:00. fixed the misreading, and a rule that must always hold belongs in the tool's own checks.

Additional Resources​