Repository navigation
Description
Description
FunctionInvokingChatClient.GenerateRejectedFunctionResults returns "Tool call invocation rejected." to the model when an approval is rejected without a Reason. That sentence says neither who rejected the call nor that the decision is final, so models read it as a transient or technical failure and request approval for the same tool call again.
The end user is then re-prompted to approve a tool they have already denied. Nothing on the library side bounds this: MaximumIterationsPerRequest limits iterations within one GetResponseAsync call, but each approval round-trip is a separate call, so the retries are bounded only by whatever the host application happens to do.
Reproduction Steps
Wrap a function in ApprovalRequiredAIFunction, reject the approval with CreateResponse(false) and no reason, and count how many times the model asks again.
using var client = new FunctionInvokingChatClient(inner);
var tool = new ApprovalRequiredAIFunction(AIFunctionFactory.Create(
(string city) => $"22C and sunny in {city}", "get_weather", "Gets the current weather for a city."));
var options = new ChatOptions { Tools = [tool] };
List<ChatMessage> messages = [new(ChatRole.User, "What is the weather in Paris? Use the get_weather tool.")];
int rounds = 0;
for (int i = 0; i < 5; i++)
{
var response = await client.GetResponseAsync(messages, options);
messages.AddRange(response.Messages);
var requests = response.Messages.SelectMany(m => m.Contents).OfType<ToolApprovalRequestContent>().ToList();
if (requests.Count == 0) break;
rounds++;
messages.Add(new ChatMessage(ChatRole.User, requests.Select(r => (AIContent)r.CreateResponse(false)).ToList()));
}Expected behavior
One approval round. Once rejected, the call is settled and the model should answer without asking again, whether or not an optional Reason was supplied.
Actual behavior
Approval rounds, three runs per model, rejection with no reason, against Azure OpenAI:
| model | rounds |
|---|---|
| gpt-4o | 1, 1, 1 |
| gpt-5.5 | 1, 1, 2 |
| gpt-5-mini | 2, 3, 2 |
| gpt-5.6-terra | 5, 2, 5 (5 = my loop cap; it had not stopped) |
Supplying a Reason gives exactly 1 round on every model. The rejected function is never executed in any run, so this costs round-trips and repeated user prompts rather than incorrect execution.
Regression?
Yes, in effect. Before #7140 the message was "Error: Tool call invocation was rejected by user.", which stated who rejected the call. #7139 asked only for the ability to supply a custom rejection message; #7140 added the Reason property and, as a side effect, shortened the default to "Tool call invocation rejected.", dropping the attribution. Newer models are noticeably more likely to retry on the shortened form.
Known Workarounds
Always pass a reason: CreateResponse(false, "..."). That reliably gives one round. But Reason is documented as "An optional reason", so correctness of the human-in-the-loop flow should not depend on supplying it.
Configuration
Microsoft.Extensions.AIat main (890988e), .NET 10, Windows x64- Azure OpenAI deployments of gpt-4o, gpt-5.5, gpt-5-mini and gpt-5.6-terra
Other information
Restoring the missing information fixes it. With the default changed to "Tool call invocation was rejected by the approver and must not be retried." all four models return exactly 1 round in 3/3 runs, including gpt-4o, which was already correct and does not regress.
Two details worth noting from testing:
- "approver" rather than "user", because
ToolApprovalRequestContentdocuments the approval as possibly coming from "a user prompt, a policy decision, or any other approver", so attributing it to a user would be wrong for policy-driven rejections. - The finality clause is load-bearing. With attribution alone (
"...was rejected by the approver.") gpt-5-mini still retried in 1 of 3 runs.
This is a deliberate change to an observable string, so it is a behavioral change even though no public API moves. I am happy to adjust the wording to whatever you prefer, or to leave it with you if you would rather own the phrasing. I will open a PR with the change and the updated tests shortly.
Activity