Table of Contents

Class Tool

Namespace
AnthropicClient.Models
Assembly
AnthropicClient.dll

Represents a tool that can be used.

public class Tool
Inheritance
Tool
Inherited Members

Properties

CacheControl

Gets or sets the cache control to be used for the tool.

[JsonPropertyName("cache_control")]
public CacheControl? CacheControl { get; set; }

Property Value

CacheControl

Description

Gets the description of the tool.

public string Description { get; }

Property Value

string

DisplayName

Gets the display name of the tool.

[JsonIgnore]
public string DisplayName { get; }

Property Value

string

Function

Gets the function of the tool.

[JsonIgnore]
public AnthropicFunction Function { get; }

Property Value

AnthropicFunction

InputSchema

Gets the input schema of the tool.

[JsonPropertyName("input_schema")]
public JsonObject InputSchema { get; }

Property Value

JsonObject

Name

Gets the name of the tool. This name will conform to the Anthropic tool naming rules.

public string Name { get; }

Property Value

string

Methods

CreateFromClass<T>(CacheControl?)

Creates a tool from a type that implements ITool.

public static Tool CreateFromClass<T>(CacheControl? cacheControl = null) where T : ITool, new()

Parameters

cacheControl CacheControl

Returns

Tool

The created tool as instance of Tool.

Type Parameters

T

The type that implements ITool.

Remarks

The implementation of ITool must have a parameterless constructor.

Exceptions

ArgumentException

Thrown when the name or description of the tool is null or empty.

ArgumentNullException

Thrown when the function of the tool is null.

CreateFromFunction<TResult>(string, string, Func<TResult>, CacheControl?)

Creates a tool from a function.

public static Tool CreateFromFunction<TResult>(string name, string description, Func<TResult> func, CacheControl? cacheControl = null)

Parameters

name string

The name of the tool.

description string

The description of the tool.

func Func<TResult>

The function.

cacheControl CacheControl

The cache control to be used for the tool.

Returns

Tool

The created tool as instance of Tool.

Type Parameters

TResult

The type of the result for the delegate.

Remarks

The name of the tool will be sanitized to conform to the Anthropic tool naming rules.

Exceptions

ArgumentNullException

Thrown when func is null.

CreateFromFunction<T1, TResult>(string, string, Func<T1, TResult>, CacheControl?)

Creates a tool from a function.

public static Tool CreateFromFunction<T1, TResult>(string name, string description, Func<T1, TResult> func, CacheControl? cacheControl = null)

Parameters

name string

The name of the tool.

description string

The description of the tool.

func Func<T1, TResult>

The function.

cacheControl CacheControl

The cache control to be used for the tool.

Returns

Tool

The created tool as instance of Tool.

Type Parameters

T1

The type of the first parameter for the delegate.

TResult

The type of the result for the delegate.

Remarks

The name of the tool will be sanitized to conform to the Anthropic tool naming rules.

Exceptions

ArgumentNullException

Thrown when func is null.

CreateFromFunction<T1, T2, TResult>(string, string, Func<T1, T2, TResult>, CacheControl?)

Creates a tool from a function.

public static Tool CreateFromFunction<T1, T2, TResult>(string name, string description, Func<T1, T2, TResult> func, CacheControl? cacheControl = null)

Parameters

name string

The name of the tool.

description string

The description of the tool.

func Func<T1, T2, TResult>

The function.

cacheControl CacheControl

The cache control to be used for the tool.

Returns

Tool

The created tool as instance of Tool.

Type Parameters

T1

The type of the first parameter for the delegate.

T2

The type of the second parameter for the delegate.

TResult

The type of the result for the delegate.

Remarks

The name of the tool will be sanitized to conform to the Anthropic tool naming rules.

Exceptions

ArgumentNullException

Thrown when func is null.

CreateFromInstanceMethod(string, string, object, string, CacheControl?)

Creates a tool from an instance method.

public static Tool CreateFromInstanceMethod(string name, string description, object instance, string methodName, CacheControl? cacheControl = null)

Parameters

name string

The name of the tool.

description string

The description of the tool.

instance object

The instance that contains the method.

methodName string

The name of the method.

cacheControl CacheControl

The cache control to be used for the tool.

Returns

Tool

The created tool as instance of Tool.

Remarks

The name of the tool will be sanitized to conform to the Anthropic tool naming rules.

Exceptions

ArgumentException

Thrown when methodName is null or empty.

ArgumentNullException

Thrown when instance is null.

ArgumentException

Thrown when methodName is not found in the type of instance.

CreateFromStaticMethod(string, string, Type, string, CacheControl?)

Creates a tool from a static method.

public static Tool CreateFromStaticMethod(string name, string description, Type type, string methodName, CacheControl? cacheControl = null)

Parameters

name string

The name of the tool.

description string

The description of the tool.

type Type

The type that contains the method.

methodName string

The name of the method.

cacheControl CacheControl

The cache control to be used for the tool.

Returns

Tool

The created tool as instance of Tool.

Remarks

The name of the tool will be sanitized to conform to the Anthropic tool naming rules.

Exceptions

ArgumentException

Thrown when methodName is null or empty.

ArgumentNullException

Thrown when type is null.

ArgumentException

Thrown when the method is not found in the type.