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
Description
Gets the description of the tool.
public string Description { get; }
Property Value
DisplayName
Gets the display name of the tool.
[JsonIgnore]
public string DisplayName { get; }
Property Value
Function
Gets the function of the tool.
[JsonIgnore]
public AnthropicFunction Function { get; }
Property Value
InputSchema
Gets the input schema of the tool.
[JsonPropertyName("input_schema")]
public JsonObject InputSchema { get; }
Property Value
Name
Gets the name of the tool. This name will conform to the Anthropic tool naming rules.
public string Name { get; }
Property Value
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
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
stringThe name of the tool.
description
stringThe description of the tool.
func
Func<TResult>The function.
cacheControl
CacheControlThe cache control to be used for the tool.
Returns
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
stringThe name of the tool.
description
stringThe description of the tool.
func
Func<T1, TResult>The function.
cacheControl
CacheControlThe cache control to be used for the tool.
Returns
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
stringThe name of the tool.
description
stringThe description of the tool.
func
Func<T1, T2, TResult>The function.
cacheControl
CacheControlThe cache control to be used for the tool.
Returns
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
stringThe name of the tool.
description
stringThe description of the tool.
instance
objectThe instance that contains the method.
methodName
stringThe name of the method.
cacheControl
CacheControlThe cache control to be used for the tool.
Returns
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 ofinstance
.
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
stringThe name of the tool.
description
stringThe description of the tool.
type
TypeThe type that contains the method.
methodName
stringThe name of the method.
cacheControl
CacheControlThe cache control to be used for the tool.
Returns
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.