Description

Execute tool

Execute a specific tool by name with the provided arguments.

Included in Version 3

Dynamically extracted tool implementation.
How to register ToolRegistrycsharp
new AgentTool(            "execute_tool",            "Execute a specific tool by name with the provided arguments.",            ExecuteTool,            new            {                type = "object",                required = new[] { "tool_name" },                properties = new                {                    tool_name = new { type = "string", description = "The exact name of the tool to execute (from search_tools)." },                    tool_arguments = new { type = "object", description = "Arguments to pass to the tool as a JSON object." }                }            })
Helper classes for ToolRegistrycsharp
    private string ExecuteTool(string argsJson)    {        string toolName = string.Empty;        string toolArgs = "{}";        try        {            using var doc = JsonDocument.Parse(argsJson);            if (doc.RootElement.TryGetProperty("tool_name", out var nameProp))                toolName = nameProp.GetString() ?? string.Empty;            if (doc.RootElement.TryGetProperty("tool_arguments", out var argsProp)                && argsProp.ValueKind != JsonValueKind.Null                && argsProp.ValueKind != JsonValueKind.Undefined)                toolArgs = argsProp.GetRawText();        }        catch { }        if (string.IsNullOrWhiteSpace(toolName))            return "Error: tool_name is required.";        if (!_catalog.TryGetValue(toolName, out AgentTool? tool))            return $"Error: Unknown tool '{toolName}'. Use search_tools to find available tools.";        try        {            return tool.Invoke(toolArgs);        }        catch (Exception ex)        {            return $"Tool '{toolName}' failed: {ex.Message}";        }    }