mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-06-27 14:36:27 +00:00
adding the provider confidence to the tool context; introducing a ToolExecutionBlockedException
This commit is contained in:
parent
1f42c8ad4c
commit
6da97c7c80
@ -713,6 +713,7 @@ public abstract class BaseProvider : IProvider, ISecretId
|
||||
toolCall.Function.Name,
|
||||
toolCall.Function.Arguments,
|
||||
runnableTools,
|
||||
this.Provider.GetConfidence(settingsManager).Level,
|
||||
toolCallCount,
|
||||
token);
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ public sealed class ToolExecutionContext
|
||||
public required SettingsManager SettingsManager { get; init; }
|
||||
|
||||
public required IReadOnlyDictionary<string, string> SettingsValues { get; init; }
|
||||
|
||||
public ConfidenceLevel ProviderConfidence { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||
}
|
||||
|
||||
public sealed class ToolExecutionResult
|
||||
@ -30,6 +32,8 @@ public sealed class ToolExecutionResult
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ToolExecutionBlockedException(string message) : Exception(message);
|
||||
|
||||
public enum ToolInvocationTraceStatus
|
||||
{
|
||||
NONE = 0,
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using AIStudio.Provider;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AIStudio.Tools.ToolCallingSystem;
|
||||
@ -11,6 +13,7 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService)
|
||||
string toolName,
|
||||
string argumentsJson,
|
||||
IReadOnlyList<(ToolDefinition Definition, IToolImplementation Implementation)> runnableTools,
|
||||
ConfidenceLevel providerConfidence,
|
||||
int order,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
@ -40,6 +43,7 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService)
|
||||
Definition = definition,
|
||||
SettingsManager = Program.SERVICE_PROVIDER.GetRequiredService<Settings.SettingsManager>(),
|
||||
SettingsValues = settingsValues,
|
||||
ProviderConfidence = providerConfidence,
|
||||
}, token);
|
||||
|
||||
return (result.ToModelContent(), new ToolInvocationTrace
|
||||
@ -55,6 +59,31 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService)
|
||||
Result = implementation.FormatTraceResult(result.ToModelContent()),
|
||||
});
|
||||
}
|
||||
catch (ToolExecutionBlockedException exception)
|
||||
{
|
||||
Dictionary<string, string> formattedArguments = [];
|
||||
try
|
||||
{
|
||||
using var document = JsonDocument.Parse(string.IsNullOrWhiteSpace(argumentsJson) ? "{}" : argumentsJson);
|
||||
formattedArguments = FormatArguments(document.RootElement, implementation.SensitiveTraceArgumentNames);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return (exception.Message, new ToolInvocationTrace
|
||||
{
|
||||
Order = order,
|
||||
ToolId = definition.Id,
|
||||
ToolName = implementation.GetDisplayName(),
|
||||
ToolIcon = implementation.Icon,
|
||||
ToolCallId = toolCallId,
|
||||
Status = ToolInvocationTraceStatus.BLOCKED,
|
||||
StatusMessage = exception.Message,
|
||||
Arguments = formattedArguments,
|
||||
Result = exception.Message,
|
||||
});
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var error = $"Tool execution failed: {exception.Message}";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user