diff options
Diffstat (limited to 'src/Agent.Core/Tools/ToolPolicy.cs')
| -rw-r--r-- | src/Agent.Core/Tools/ToolPolicy.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Agent.Core/Tools/ToolPolicy.cs b/src/Agent.Core/Tools/ToolPolicy.cs new file mode 100644 index 0000000..c9f216a --- /dev/null +++ b/src/Agent.Core/Tools/ToolPolicy.cs @@ -0,0 +1,31 @@ +using System.Text.Json; + +namespace Agent.Core.Tools; + +public sealed record ToolPolicyDecision(bool Allowed, string Reason) +{ + public static ToolPolicyDecision Allow() => new(true, "allowed"); + public static ToolPolicyDecision Deny(string reason) => new(false, reason); +} + +public interface IToolPolicyEngine +{ + ToolPolicyDecision Evaluate(string toolName, JsonElement arguments); +} + +public interface IInternalToolBackend +{ + Task BeginTaskAsync(Guid taskId, CancellationToken cancellationToken) => Task.CompletedTask; + Task<ToolExecutionResult> ExecuteAsync(Guid taskId, string toolName, JsonElement arguments, CancellationToken cancellationToken); + Task EndTaskAsync(Guid taskId, bool success, CancellationToken cancellationToken) => Task.CompletedTask; +} + +public sealed record ToolExecutionResult(bool Success, string Output, bool ExternalEffect, string? FailureFingerprint = null); + +public sealed class DenyByDefaultPolicy(IReadOnlySet<string>? allowedTools = null) : IToolPolicyEngine +{ + private readonly IReadOnlySet<string> _allowedTools = allowedTools ?? new HashSet<string>(StringComparer.Ordinal); + public ToolPolicyDecision Evaluate(string toolName, JsonElement arguments) => _allowedTools.Contains(toolName) + ? ToolPolicyDecision.Allow() + : ToolPolicyDecision.Deny("Capability is not allowed by policy."); +} |
