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
cacheControlCacheControl
Returns
Type Parameters
TThe 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
namestringThe name of the tool.
descriptionstringThe description of the tool.
funcFunc<TResult>The function.
cacheControlCacheControlThe cache control to be used for the tool.
Returns
Type Parameters
TResultThe 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
funcis 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
namestringThe name of the tool.
descriptionstringThe description of the tool.
funcFunc<T1, TResult>The function.
cacheControlCacheControlThe cache control to be used for the tool.
Returns
Type Parameters
T1The type of the first parameter for the delegate.
TResultThe 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
funcis 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
namestringThe name of the tool.
descriptionstringThe description of the tool.
funcFunc<T1, T2, TResult>The function.
cacheControlCacheControlThe cache control to be used for the tool.
Returns
Type Parameters
T1The type of the first parameter for the delegate.
T2The type of the second parameter for the delegate.
TResultThe 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
funcis 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
namestringThe name of the tool.
descriptionstringThe description of the tool.
instanceobjectThe instance that contains the method.
methodNamestringThe name of the method.
cacheControlCacheControlThe 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
methodNameis null or empty.- ArgumentNullException
Thrown when
instanceis null.- ArgumentException
Thrown when
methodNameis 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
namestringThe name of the tool.
descriptionstringThe description of the tool.
typeTypeThe type that contains the method.
methodNamestringThe name of the method.
cacheControlCacheControlThe 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
methodNameis null or empty.- ArgumentNullException
Thrown when
typeis null.- ArgumentException
Thrown when the method is not found in the type.