Skip to content

ToolApprovalRuleEvaluator

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Applies persistent approval rules to a tool call.

public sealed class ToolApprovalRuleEvaluator

objectToolApprovalRuleEvaluator

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Integrates with Microsoft Agent Framework’s ToolApprovalAgentOptions.AutoApprovalRules API. When a rule matches, the call runs without asking the user.

This class protects the tenant boundary. It always reads rules with ITenantContext.TenantId. An approval from one tenant cannot run a call for another tenant.

A store error does not grant approval. If a rule cannot be read, the call is not automatically approved and the system asks the user. This is the safe default.

A code-defined policy runs before the data rules and can override them. Code is a security boundary; data — writable from the UI — is not allowed to loosen it. See ToolApprovalContext and IAgentPrismBuilder.AddToolApprovalPolicy(...).

ToolApprovalRuleEvaluator(IToolApprovalRuleStore, ToolApprovalPolicyRegistry, ITenantContext, ILogger<ToolApprovalRuleEvaluator>)

Section titled “ ToolApprovalRuleEvaluator(IToolApprovalRuleStore, ToolApprovalPolicyRegistry, ITenantContext, ILogger<ToolApprovalRuleEvaluator>)”

Initializes a new evaluator.

public ToolApprovalRuleEvaluator(IToolApprovalRuleStore rules, ToolApprovalPolicyRegistry policies, ITenantContext tenantContext, ILogger<ToolApprovalRuleEvaluator> logger)

rules IToolApprovalRuleStore

The rule store.

policies ToolApprovalPolicyRegistry

The code-defined policy registry.

tenantContext ITenantContext

The tenant context.

logger ILogger<ToolApprovalRuleEvaluator>

The logger.

ArgumentNullException

A dependency is null.

ComputeArgumentsHash(IDictionary<string, object?>?)

Section titled “ ComputeArgumentsHash(IDictionary<string, object?>?)”

Produces a deterministic fingerprint from tool arguments.

public static string ComputeArgumentsHash(IDictionary<string, object?>? arguments)

arguments IDictionary<string, object?>?

The call arguments.

string

The hexadecimal fingerprint, or an empty string when there are no arguments.

Keys are sorted. Dictionary order can change between runs, and a different fingerprint for the same call would prevent a “do not ask again” rule from matching.

This method does not use JSON serialization. Reflection-based serialization produces IL2026, and AgentPrism.Core is marked as AOT-compatible.

IsAutoApprovedAsync(string, FunctionCallContent, CancellationToken)

Section titled “ IsAutoApprovedAsync(string, FunctionCallContent, CancellationToken)”

Determines whether a call is auto-approved: either a code-defined policy decides so, or — when the policy is silent — a persistent data rule matches.

public ValueTask<bool> IsAutoApprovedAsync(string agentName, FunctionCallContent call, CancellationToken cancellationToken = default)

agentName string

The agent that makes the call.

call FunctionCallContent

The tool call.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true if the call is automatically approved.

Code runs first and can override data in both directions: a ToolApprovalPolicyDecision.Required policy forces approval even if a data rule would otherwise auto-approve the call, and ToolApprovalPolicyDecision.NotRequired auto-approves even with no matching data rule. Only ToolApprovalPolicyDecision.Undecided (or no registered policy) falls through to the data rules.