# TimeoutAIFunction

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.timeoutaifunction/
> Summary: TimeoutAIFunction: Wraps an AI.AIFunction so a call that does not settle within a fixed duration ends in TraconToolTimeoutException instead of running unbounded.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Core.dll</code></div>

Wraps an `AI.AIFunction` so a call that does not settle within a
fixed duration ends in [TraconToolTimeoutException](/api/tracon.tracontooltimeoutexception/) instead
of running unbounded.

```csharp
public sealed class TimeoutAIFunction : DelegatingAIFunction
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← AITool ← AIFunctionDeclaration ← AIFunction ← DelegatingAIFunction ← <a href="/api/tracon.timeoutaifunction/">TimeoutAIFunction</a></dd><dt>Inherited Members</dt><dd>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&lt;TService&gt;(object?), AITool.Name, AITool.Description, AITool.AdditionalProperties, <a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

Installed by the tool registry, one layer **inside** the
authorization wrapper and **outside** the approval wrapper.
The 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.

On timeout the call is **cancelled** and the caller is handed
[TraconToolTimeoutException](/api/tracon.tracontooltimeoutexception/). Cancellation is
[cooperative](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken): a body that reads its token
stops there and spends nothing more, while one that never reads it is not
forcibly stopped and keeps running in the background until it finishes or
faults on its own. That remaining case is not left silent — when such a call
does settle, its result and whatever usage it reported are written onto the
call's existing record, which is the only way a charge incurred after the
timeout reaches a cost report at all.

## Methods

### <a id="Tracon_TimeoutAIFunction_InvokeCoreAsync_Microsoft_Extensions_AI_AIFunctionArguments_System_Threading_CancellationToken_"></a> InvokeCoreAsync\(AIFunctionArguments, CancellationToken\)

Invokes the `AI.AIFunction` and returns its result.

```csharp
protected override ValueTask<object?> InvokeCoreAsync(AIFunctionArguments arguments, CancellationToken cancellationToken)
```

#### Parameters

`arguments` AIFunctionArguments

The arguments to pass to the function's invocation.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to monitor for cancellation requests.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[object](https://learn.microsoft.com/dotnet/api/system.object)?\>

The result of the function's execution.
