Table of Contents

Class ToolDefinition

Namespace
Emissary
Assembly
Emissary.dll

A fully materialized tool: wire name, description, compile-time JSON Schema, and a reflection-free dispatcher. Instances are normally produced by the Emissary source generator from ClaudeToolAttribute-annotated methods, but can be built by hand.

public sealed class ToolDefinition
Inheritance
ToolDefinition
Inherited Members

Constructors

ToolDefinition(string, string, string, Func<JsonElement, CancellationToken, ValueTask<string>>, string?, bool, bool, Func<JsonElement, CancellationToken, ValueTask<string>>?, int?)

Creates a tool definition.

public ToolDefinition(string name, string description, string inputSchemaJson, Func<JsonElement, CancellationToken, ValueTask<string>> handler, string? requiredPolicy = null, bool untrusted = false, bool privileged = false, Func<JsonElement, CancellationToken, ValueTask<string>>? compensation = null, int? maxResultLength = null)

Parameters

name string

The wire name of the tool.

description string

The description shown to the model.

inputSchemaJson string

The JSON Schema for the tool input, as a JSON string.

handler Func<JsonElement, CancellationToken, ValueTask<string>>

The dispatcher invoked with the tool-use input.

requiredPolicy string

Policy an IToolAuthorizer must grant, or null.

untrusted bool

Whether the tool's output taints the run (see Untrusted).

privileged bool

Whether the tool is blocked in tainted runs (see Privileged).

compensation Func<JsonElement, CancellationToken, ValueTask<string>>

Handler that undoes this tool's effect given the original input, or null.

maxResultLength int?

Caps how much of the tool's output reaches the model; null for no cap.

Exceptions

ArgumentNullException

A required argument is null.

Properties

Compensation

Undoes this tool's effect given the original input, or null.

public Func<JsonElement, CancellationToken, ValueTask<string>>? Compensation { get; }

Property Value

Func<JsonElement, CancellationToken, ValueTask<string>>

Description

The description shown to the model.

public string Description { get; }

Property Value

string

Handler

The dispatcher invoked with the tool-use input.

public Func<JsonElement, CancellationToken, ValueTask<string>> Handler { get; }

Property Value

Func<JsonElement, CancellationToken, ValueTask<string>>

InputSchemaJson

The JSON Schema for the tool input, as a JSON string.

public string InputSchemaJson { get; }

Property Value

string

MaxResultLength

Caps how much of this tool's output reaches the model, guarding the context window and token budget against a tool that returns far more than expected. null means no cap.

public int? MaxResultLength { get; }

Property Value

int?

Name

The wire name of the tool.

public string Name { get; }

Property Value

string

Privileged

Whether the tool is blocked once the run is tainted.

public bool Privileged { get; }

Property Value

bool

RequiredPolicy

The policy an IToolAuthorizer must grant, or null for none.

public string? RequiredPolicy { get; }

Property Value

string

Untrusted

Whether a successful call taints the run with untrusted content.

public bool Untrusted { get; }

Property Value

bool

Methods

InvokeAsync(JsonElement, CancellationToken)

Invokes the tool with the given tool-use input.

public ValueTask<string> InvokeAsync(JsonElement input, CancellationToken cancellationToken = default)

Parameters

input JsonElement

The tool-use input object.

cancellationToken CancellationToken

Cancels the tool execution.

Returns

ValueTask<string>

The tool result content.