Skip to content

TimeoutAIFunction

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Wraps an AI.AIFunction so a call that does not settle within a fixed duration ends in AgentPrismToolTimeoutException instead of running unbounded.

public sealed class TimeoutAIFunction : DelegatingAIFunction

object ← AITool ← AIFunctionDeclaration ← AIFunction ← DelegatingAIFunction ← TimeoutAIFunction

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, one layer inside the authorization wrapper and outside the approval wrapper — This ordering matters: ApprovalRequiredAIFunction never blocks on the human decision inside a single call (Microsoft Agent Framework returns a pending request immediately and the decision resumes as a new run, ), so wrapping it with a timeout only ever bounds the tool’s own execution, never an approval wait.

CancellationToken is cooperative. A tool body that never reads its token is not forcibly stopped: this class races the call against a delay and, on timeout, returns control to the caller while the call keeps running in the background until it finishes or faults on its own. This is a documented limit, not a bug.

TimeoutAIFunction(AIFunction, TimeSpan, ILogger<TimeoutAIFunction>)

Section titled “ TimeoutAIFunction(AIFunction, TimeSpan, ILogger<TimeoutAIFunction>)”

Creates a new timeout wrapper.

public TimeoutAIFunction(AIFunction innerFunction, TimeSpan timeout, ILogger<TimeoutAIFunction> logger)

innerFunction AIFunction

The tool to wrap.

timeout TimeSpan

The longest duration one call may run.

logger ILogger<TimeoutAIFunction>

The logger for a call that outlives its timeout.

ArgumentOutOfRangeException

timeout is zero or negative.

InvokeCoreAsync(AIFunctionArguments, CancellationToken)

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

arguments AIFunctionArguments

cancellationToken CancellationToken

ValueTask<object?>