Skip to content

AgentPrismToolApprovalPolicyExtensions

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Chain extension that registers a code-defined approval policy for a tool.

public static class AgentPrismToolApprovalPolicyExtensions

objectAgentPrismToolApprovalPolicyExtensions

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

This is an extension method, not a member of IAgentPrismBuilder: adding a member to the interface is a breaking change after release; adding an extension method is not.

AddToolApprovalPolicy(IAgentPrismBuilder, string, Func<ToolApprovalContext, ToolApprovalPolicyDecision>)

Section titled “ AddToolApprovalPolicy(IAgentPrismBuilder, string, Func<ToolApprovalContext, ToolApprovalPolicyDecision>)”

Registers a code-defined approval policy for a tool.

public static IAgentPrismBuilder AddToolApprovalPolicy(this IAgentPrismBuilder builder, string toolName, Func<ToolApprovalContext, ToolApprovalPolicyDecision> policy)

builder IAgentPrismBuilder

The configuration chain.

toolName string

The tool the policy judges.

policy Func<ToolApprovalContext, ToolApprovalPolicyDecision>

The policy delegate. Runs at every call to toolName, before the data rules (ToolApprovalRule). ToolApprovalPolicyDecision.Required and ToolApprovalPolicyDecision.NotRequired override the data rules; ToolApprovalPolicyDecision.Undecided defers to them. An exception is treated as ToolApprovalPolicyDecision.Required and logged — a broken policy does not silently release a tool from approval.

IAgentPrismBuilder

The chain, for further configuration.

The policy’s dependencies must be captured at REGISTRATION time (the delegate’s closure), not resolved from a service provider inside the delegate — the service provider a tool call sees is empty.

builder.AddAgentPrism()
.AddToolApprovalPolicy("refund_order", context =>
context.GetNumber("amount") is { } amount && amount <= 100
? ToolApprovalPolicyDecision.NotRequired
: ToolApprovalPolicyDecision.Required);

ArgumentNullException

builder or policy is null.

ArgumentException

toolName is empty or whitespace.