Fixed a misleading tool calling error after a stopped or interrupted answer (#1202)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
j-erlerandThorsten Sommer authored and GitHub committed 2026-11-20 14:46:27 +01:00
1 parent fb8f51dec4
commit ca7413d84c
18 files changed
+272 -76

No files matched your search

@@ -1,3 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Tools.ToolCallingSystem.Harness;
/// <summary>
@@ -31,8 +33,13 @@ public interface IToolCallingProviderAdapter
/// <returns>
/// The events of this round: any number of TEXT_DELTA events, closed by one ROUND_COMPLETED
/// event carrying the outcome. A stream which ends without that closing event is a failed
/// round; it ends the loop without an error message because the adapter has already told the
/// user what went wrong.
/// round: its request failed, or a stop, a timeout, or a broken connection cut off its stream.
/// It ends the loop without an error message, because the user has already been told what went
/// wrong, and a stop is no error.<br/><br/>
/// An adapter therefore completes a round only from a stream which the provider closed, cf.
/// <see cref="ServerSentEventStreamEnd"/>, never from whatever arrived before the stream was cut
/// off. Such a round would have the loop report a model which said nothing, or run a call which
/// the user no longer wants.
/// </returns>
public IAsyncEnumerable<ToolCallingStreamEvent> ExecuteRoundAsync(string? finalResponseInstruction, bool includeTools, CancellationToken token = default);
@@ -109,11 +109,17 @@ public sealed class ToolCallingLoop(ILogger<ToolCallingLoop> logger) : IToolCall
}
//
// No outcome means the round failed: the request errored out, or the stream ended
// mid-sentence. Either way the adapter has already reported it. The answer keeps what
// was written so far, and with it what the tools of the earlier rounds contributed:
// No outcome means the round failed: its request errored out, or a stop, a timeout, or
// a broken connection cut off its stream. The user has been told about an error
// already, and a stop is none. The answer keeps what was written so far, and with it
// what the tools of the earlier rounds contributed.
//
if (round is null)
// A stop may also come after the provider closed the stream, before the round is acted
// on. It ends the answer the same way: a round without text and without calls is then
// no invalid answer of the provider, and a call of this round must not run after the
// user said stop.
//
if (round is null || token.IsCancellationRequested)
{
await context.ResetToolRuntimeStatusAsync();
if (toolSources.Count > 0 || toolPassages.Count > 0)
@@ -7,9 +7,10 @@ namespace AIStudio.Tools.ToolCallingSystem.Harness;
/// </summary>
/// <remarks>
/// Text arrives while the round is still running, its outcome only at the end. A round which ends
/// without a ROUND_COMPLETED event has failed: that is how a failed request or a truncated stream
/// is told apart from a round which simply had nothing to say. The adapter has already told the
/// user what went wrong in that case, so the loop ends without a message of its own.
/// without a ROUND_COMPLETED event has failed: that is how a failed request, or a stream which a
/// stop, a timeout, or a broken connection cut off, is told apart from a round which simply had
/// nothing to say. The user has already been told what went wrong in that case, and a stop is no
/// error, so the loop ends without a message of its own.
/// </remarks>
/// <param name="Kind">What this event carries.</param>
/// <param name="Delta">The piece of text, set for TEXT_DELTA events only.</param>