diff --git a/src/AnthropicClient/Models/Tool.cs b/src/AnthropicClient/Models/Tool.cs index 9d667ce..bb70153 100644 --- a/src/AnthropicClient/Models/Tool.cs +++ b/src/AnthropicClient/Models/Tool.cs @@ -147,6 +147,26 @@ public class Tool return new Tool(name, description, new AnthropicFunction(func.Method, func.Target)); } + /// + /// Creates a tool from a function. + /// + /// The type of the first parameter for the delegate. + /// The type of the second parameter for the delegate. + /// The type of the result for the delegate. + /// The name of the tool. + /// The description of the tool. + /// The function. + /// Thrown when is null. + /// The created tool as instance of . + /// The name of the tool will be sanitized to conform to the Anthropic tool naming rules. + public static Tool CreateFromFunction(string name, string description, Func func) + { + ArgumentValidator.ThrowIfNull(func, nameof(func)); + + return new Tool(name, description, new AnthropicFunction(func.Method, func.Target)); + } + + private static string SanitizeName(string name) { var sanitizedName = name.Trim();