# TraconToolAttribute

> 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.tracontoolattribute/
> Summary: TraconToolAttribute: Marks a method as a tool. AddToolsFrom registers only methods carrying this attribute.

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

Marks a method as a tool. `AddToolsFrom<T>` registers only
methods carrying this attribute.

```csharp
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class TraconToolAttribute : Attribute
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="https://learn.microsoft.com/dotnet/api/system.attribute">Attribute</a> ← <a href="/api/tracon.tracontoolattribute/">TraconToolAttribute</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-memberinfo-system-type)">Attribute.GetCustomAttributes(MemberInfo, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-memberinfo-system-type-system-boolean)">Attribute.GetCustomAttributes(MemberInfo, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-memberinfo)">Attribute.GetCustomAttributes(MemberInfo)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-memberinfo-system-boolean)">Attribute.GetCustomAttributes(MemberInfo, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-memberinfo-system-type)">Attribute.IsDefined(MemberInfo, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-memberinfo-system-type-system-boolean)">Attribute.IsDefined(MemberInfo, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-memberinfo-system-type)">Attribute.GetCustomAttribute(MemberInfo, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-memberinfo-system-type-system-boolean)">Attribute.GetCustomAttribute(MemberInfo, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-parameterinfo)">Attribute.GetCustomAttributes(ParameterInfo)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-parameterinfo-system-type)">Attribute.GetCustomAttributes(ParameterInfo, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-parameterinfo-system-type-system-boolean)">Attribute.GetCustomAttributes(ParameterInfo, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-parameterinfo-system-boolean)">Attribute.GetCustomAttributes(ParameterInfo, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-parameterinfo-system-type)">Attribute.IsDefined(ParameterInfo, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-parameterinfo-system-type-system-boolean)">Attribute.IsDefined(ParameterInfo, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-parameterinfo-system-type)">Attribute.GetCustomAttribute(ParameterInfo, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-parameterinfo-system-type-system-boolean)">Attribute.GetCustomAttribute(ParameterInfo, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-module-system-type)">Attribute.GetCustomAttributes(Module, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-module)">Attribute.GetCustomAttributes(Module)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-module-system-boolean)">Attribute.GetCustomAttributes(Module, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-module-system-type-system-boolean)">Attribute.GetCustomAttributes(Module, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-module-system-type)">Attribute.IsDefined(Module, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-module-system-type-system-boolean)">Attribute.IsDefined(Module, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-module-system-type)">Attribute.GetCustomAttribute(Module, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-module-system-type-system-boolean)">Attribute.GetCustomAttribute(Module, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-assembly-system-type)">Attribute.GetCustomAttributes(Assembly, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-assembly-system-type-system-boolean)">Attribute.GetCustomAttributes(Assembly, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-assembly)">Attribute.GetCustomAttributes(Assembly)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes(system-reflection-assembly-system-boolean)">Attribute.GetCustomAttributes(Assembly, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-assembly-system-type)">Attribute.IsDefined(Assembly, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined(system-reflection-assembly-system-type-system-boolean)">Attribute.IsDefined(Assembly, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-assembly-system-type)">Attribute.GetCustomAttribute(Assembly, Type)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute(system-reflection-assembly-system-type-system-boolean)">Attribute.GetCustomAttribute(Assembly, Type, bool)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.equals">Attribute.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.gethashcode">Attribute.GetHashCode()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.match">Attribute.Match(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.isdefaultattribute">Attribute.IsDefaultAttribute()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.attribute.typeid">Attribute.TypeId</a>, <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

Marking is an **explicit choice**. Adding a new public method
to a class does not automatically expose it to agents. This is the
natural continuation of the code-only tools rule (tools are defined only in code).

The description field tells the model *when* to call the tool; if
left empty, the model looks only at the name and parameter schema.

```csharp
internal class OrderTools
{
    [TraconTool("get_order_status", "Returns an order's shipping status.")]
    public static string GetOrderStatus(string orderId) => "shipped";

    public static void Helper() { }   // not a tool
}
```

## Constructors

### <a id="Tracon_TraconToolAttribute__ctor"></a> TraconToolAttribute\(\)

Creates a mark that uses the method name as the tool name.

```csharp
public TraconToolAttribute()
```

### <a id="Tracon_TraconToolAttribute__ctor_System_String_"></a> TraconToolAttribute\(string\)

Creates a mark with an explicit tool name.

```csharp
public TraconToolAttribute(string name)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tool name. Used in agent definitions.

### <a id="Tracon_TraconToolAttribute__ctor_System_String_System_String_"></a> TraconToolAttribute\(string, string\)

Creates a mark with a name and a description.

```csharp
public TraconToolAttribute(string name, string description)
```

#### Parameters

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tool name. Used in agent definitions.

`description` [string](https://learn.microsoft.com/dotnet/api/system.string)

The description telling the model when to call the tool.

## Properties

### <a id="Tracon_TraconToolAttribute_Description"></a> Description

The description telling the model when to call the tool.

```csharp
public string? Description { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)?

### <a id="Tracon_TraconToolAttribute_Effect"></a> Effect

The tool's effect class. Defaults to [ToolEffect.Read](/api/tracon.tooleffect/).

```csharp
public ToolEffect Effect { get; init; }
```

#### Property Value

 [ToolEffect](/api/tracon.tooleffect/)

### <a id="Tracon_TraconToolAttribute_JsonSerializerContext"></a> JsonSerializerContext

The source-generated JSON context for a complex tool result, or
[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the result needs no JSON serialization.

```csharp
public Type? JsonSerializerContext { get; init; }
```

#### Property Value

 [Type](https://learn.microsoft.com/dotnet/api/system.type)?

#### Remarks

Set this to a `Serialization.JsonSerializerContext`
type that declares `[JsonSerializable(typeof(TResult))]`. The JSON
source generator only sees source written by the tool owner; a context
emitted by another source generator arrives too late for it to process.

### <a id="Tracon_TraconToolAttribute_MaxOutputBytes"></a> MaxOutputBytes

The maximum UTF-8 byte count for this tool result. Zero uses the installation default.

```csharp
public int MaxOutputBytes { get; init; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Remarks

This limit does not apply to `AI.AIContent` attachments. They use
the existing attachment contract instead of an inline text result.

### <a id="Tracon_TraconToolAttribute_Name"></a> Name

The tool name. The method name is used if [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

```csharp
public string? Name { get; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)?

### <a id="Tracon_TraconToolAttribute_RequiredPermission"></a> RequiredPermission

The permission name a caller must hold to call this tool, or
[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) to declare none.

```csharp
public string? RequiredPermission { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)?

#### Remarks

Checked by the registered `IToolAuthorizationHandler` before every call.

### <a id="Tracon_TraconToolAttribute_RequiresApproval"></a> RequiresApproval

Whether explicit approval is required before the call.

```csharp
public bool RequiresApproval { get; init; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

#### Remarks

A marked tool is wrapped with `ApprovalRequiredAIFunction` in the
registry. Microsoft Agent Framework produces an approval request
instead of running the tool; the call waits until the user's decision
arrives. Mark tools that perform irreversible actions (cancellation,
deletion, payment) this way.

### <a id="Tracon_TraconToolAttribute_SafeToRepeat"></a> SafeToRepeat

See [TraconToolRegistration.SafeToRepeat](/api/tracon.tracontoolregistration/#Tracon_TraconToolRegistration_SafeToRepeat). Defaults to [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool).

```csharp
public bool SafeToRepeat { get; init; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_TraconToolAttribute_TimeoutSeconds"></a> TimeoutSeconds

The longest duration this tool's call may run, in seconds. Zero (the
default) uses the installation default instead of a fixed value.

```csharp
public int TimeoutSeconds { get; init; }
```

#### Property Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

#### Remarks

An attribute argument cannot be a [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan), so seconds is
the unit; the registry converts it.
