Skip to content

AuthorizingAIFunction

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Wraps an AI.AIFunction with an IToolAuthorizationHandler check that runs before every call.

public sealed class AuthorizingAIFunction : DelegatingAIFunction

object ← AITool ← AIFunctionDeclaration ← AIFunction ← DelegatingAIFunction ← AuthorizingAIFunction

DelegatingAIFunction.ToString(), DelegatingAIFunction.GetService(Type, object?), DelegatingAIFunction.Name, DelegatingAIFunction.Description, DelegatingAIFunction.JsonSchema, DelegatingAIFunction.ReturnJsonSchema, DelegatingAIFunction.JsonSerializerOptions, DelegatingAIFunction.UnderlyingMethod, DelegatingAIFunction.AdditionalProperties, AIFunction.InvokeAsync(AIFunctionArguments?, CancellationToken), AIFunction.AsDeclarationOnly(), AIFunction.UnderlyingMethod, AIFunction.JsonSerializerOptions, AIFunctionDeclaration.JsonSchema, AIFunctionDeclaration.ReturnJsonSchema, AITool.ToString(), AITool.GetService(Type, object?), AITool.GetService<TService>(object?), AITool.Name, AITool.Description, AITool.AdditionalProperties, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Installed by the tool registry as the outermost layer — If a caller cannot make a call at all, there is no point waiting for its timeout or asking a human to approve it.

A denial does not throw. Microsoft Agent Framework turns a thrown exception into a tool result too, but denial and failure are different things at the record level (the model-facing-text rule applies here the same way): the reason text is returned as an ordinary successful result, the call is marked in the tenant’s authorization accumulator so ToolInvocationTracker can tell a denial apart from an ordinary success, and the model continues its turn.

If IToolAuthorizationHandler.AuthorizeAsync throws, the call is denied (fail-closed). A gate that fails open on an exception is not a gate.

AuthorizingAIFunction(AIFunction, IToolAuthorizationHandler, ToolEffect, string?, IRunAttributionContext?, ILogger<AuthorizingAIFunction>)

Section titled “ AuthorizingAIFunction(AIFunction, IToolAuthorizationHandler, ToolEffect, string?, IRunAttributionContext?, ILogger<AuthorizingAIFunction>)”

Creates a new authorization wrapper.

public AuthorizingAIFunction(AIFunction innerFunction, IToolAuthorizationHandler handler, ToolEffect effect, string? requiredPermission, IRunAttributionContext? attribution, ILogger<AuthorizingAIFunction> logger)

innerFunction AIFunction

The tool to wrap.

handler IToolAuthorizationHandler

The authorization policy.

effect ToolEffect

The tool’s effect class, passed through to the handler.

requiredPermission string?

The tool’s declared permission name, or null.

attribution IRunAttributionContext?

The current run’s user attribution, or null when none is registered — the request’s UserId stays empty in that case.

logger ILogger<AuthorizingAIFunction>

The logger for a faulting authorization handler.

InvokeCoreAsync(AIFunctionArguments, CancellationToken)

Section titled “ InvokeCoreAsync(AIFunctionArguments, CancellationToken)”
protected override ValueTask<object?> InvokeCoreAsync(AIFunctionArguments arguments, CancellationToken cancellationToken)

arguments AIFunctionArguments

cancellationToken CancellationToken

ValueTask<object?>