mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-06-27 19:16: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.Name,
|
||||||
toolCall.Function.Arguments,
|
toolCall.Function.Arguments,
|
||||||
runnableTools,
|
runnableTools,
|
||||||
|
this.Provider.GetConfidence(settingsManager).Level,
|
||||||
toolCallCount,
|
toolCallCount,
|
||||||
token);
|
token);
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,8 @@ public sealed class ToolExecutionContext
|
|||||||
public required SettingsManager SettingsManager { get; init; }
|
public required SettingsManager SettingsManager { get; init; }
|
||||||
|
|
||||||
public required IReadOnlyDictionary<string, string> SettingsValues { get; init; }
|
public required IReadOnlyDictionary<string, string> SettingsValues { get; init; }
|
||||||
|
|
||||||
|
public ConfidenceLevel ProviderConfidence { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ToolExecutionResult
|
public sealed class ToolExecutionResult
|
||||||
@ -30,6 +32,8 @@ public sealed class ToolExecutionResult
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class ToolExecutionBlockedException(string message) : Exception(message);
|
||||||
|
|
||||||
public enum ToolInvocationTraceStatus
|
public enum ToolInvocationTraceStatus
|
||||||
{
|
{
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
|
using AIStudio.Provider;
|
||||||
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace AIStudio.Tools.ToolCallingSystem;
|
namespace AIStudio.Tools.ToolCallingSystem;
|
||||||
@ -11,6 +13,7 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService)
|
|||||||
string toolName,
|
string toolName,
|
||||||
string argumentsJson,
|
string argumentsJson,
|
||||||
IReadOnlyList<(ToolDefinition Definition, IToolImplementation Implementation)> runnableTools,
|
IReadOnlyList<(ToolDefinition Definition, IToolImplementation Implementation)> runnableTools,
|
||||||
|
ConfidenceLevel providerConfidence,
|
||||||
int order,
|
int order,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
@ -40,6 +43,7 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService)
|
|||||||
Definition = definition,
|
Definition = definition,
|
||||||
SettingsManager = Program.SERVICE_PROVIDER.GetRequiredService<Settings.SettingsManager>(),
|
SettingsManager = Program.SERVICE_PROVIDER.GetRequiredService<Settings.SettingsManager>(),
|
||||||
SettingsValues = settingsValues,
|
SettingsValues = settingsValues,
|
||||||
|
ProviderConfidence = providerConfidence,
|
||||||
}, token);
|
}, token);
|
||||||
|
|
||||||
return (result.ToModelContent(), new ToolInvocationTrace
|
return (result.ToModelContent(), new ToolInvocationTrace
|
||||||
@ -55,6 +59,31 @@ public sealed class ToolExecutor(ToolSettingsService toolSettingsService)
|
|||||||
Result = implementation.FormatTraceResult(result.ToModelContent()),
|
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)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
var error = $"Tool execution failed: {exception.Message}";
|
var error = $"Tool execution failed: {exception.Message}";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user