Description

Self improve invoke sandbox tool

Invokes the generated tool from the built sandbox DLL and compares output to the saved spec expected result.

Included in Version 8

Dynamically extracted tool implementation.
How to register SelfImprovementToolscsharp
registry.Register(new AgentTool(            "self_improve_invoke_sandbox_tool",            "Invokes the generated tool from the built sandbox DLL and compares output to the saved spec expected result.",            InvokeInvokeSandboxTool,            new            {                type = "object",                properties = new                {                    tool_name = new { type = "string", description = "Optional if set_tool_spec was called." },                    arguments_json = new { type = "string", description = "Optional JSON string to pass to the tool (default {})." },                    expected_result = new { type = "string", description = "Optional expected result override (otherwise uses saved spec expected result)." },                },            },            ToolCategory.Self));
Helper classes for SelfImprovementToolscsharp
    private string InvokeInvokeSandboxTool(string argumentsJson)    {        var paths = RequirePaths();        if (!Directory.Exists(paths.Sandbox))            return "Error: sandbox does not exist. Call self_improve_create_sandbox and build first.";        var spec = ResolveToolSpec(argumentsJson);        if (string.IsNullOrWhiteSpace(spec.ToolName))            return "Error: No tool_name. Call self_improve_set_tool_spec first or pass tool_name.";        using var doc = JsonDocument.Parse(string.IsNullOrWhiteSpace(argumentsJson) ? "{}" : argumentsJson);        var root = doc.RootElement;        string toolArgs = root.TryGetProperty("arguments_json", out var argsEl) ? (argsEl.GetString() ?? "{}") : "{}";        string expectedOverride = root.TryGetProperty("expected_result", out var expEl) ? (expEl.GetString() ?? "") : "";        string? expected = !string.IsNullOrWhiteSpace(expectedOverride)            ? expectedOverride.Trim()            : spec.ResolveExpectedResult();        string result = SandboxToolInvoker.Invoke(paths, spec.ToolName, toolArgs);        if (result.StartsWith("Error", StringComparison.OrdinalIgnoreCase))            return result;        if (expected is null)            return $"TOOL TEST PASSED: {spec.ToolName}() => '{result}'";        if (result.Trim().Equals(expected, StringComparison.OrdinalIgnoreCase))            return $"TOOL TEST PASSED: {spec.ToolName}() => '{result}' (expected '{expected}')";        return $"TOOL TEST FAILED: {spec.ToolName}() => '{result}' (expected '{expected}')";    }