Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/complete-agi-core / mind_farm/src/toolsystem_test.cpp |
| Date | Not specified in source |
| Repository | Janady13/complete-agi-core |
| Revision | 33aa84f2aa61cedbe010240ada7f4efbdfe795a7 |
| Branch | claude/improve-math-logic-ehIW1 |
| Path or archive member | mind_farm/src/toolsystem_test.cpp |
| Original SHA-256 | cf844485b95567eccb7ce76111a7b10319bf0ed3ae258dfa5f20a7bbd654e4ad |
| Git blob SHA | baa3bc4fd344af9d0aaf23abcfbce5ec79efe1fe |
| Reading-copy SHA-256 | cf844485b95567eccb7ce76111a7b10319bf0ed3ae258dfa5f20a7bbd654e4ad |
Recovered source transcript
Download complete source text ↓273 lines · 10.8 KB
// ═══════════════════════════════════════════════════════════════════════════════
// AUTONOMOUS TOOL SYSTEM TEST
// Integrated with Gate5000 AGI Substrate
// ═══════════════════════════════════════════════════════════════════════════════
#include <iostream>
#include <iomanip>
#include <chrono>
#include "../include/constants.hpp"
#include "../include/gate5000.hpp"
#include "../include/toolbuilder.hpp"
#include "../include/fast_math.hpp"
using namespace mind_farm;
void print_separator() {
std::cout << "\n" << std::string(80, '=') << "\n";
}
void test_tool_generation() {
std::cout << "\n[TEST 1] Tool Generation from Specification\n";
std::cout << std::string(50, '-') << "\n";
AutonomousToolSystem system;
system.initialize();
// Create a tool specification
ToolSpec spec;
spec.name = "fibonacci";
spec.description = "Calculate nth Fibonacci number";
spec.input_type = Type::integer();
spec.output_type = Type::integer();
spec.confidence = 0.95f;
// Add Hoare triple contract
HoareTriple contract;
contract.precondition = "n >= 0";
contract.postcondition = "result >= 0";
contract.code = "fib(n)";
spec.contracts.push_back(contract);
// Generate the tool
auto tool = system.create_tool(spec);
std::cout << "Generated tool: " << tool.name << "\n";
std::cout << "Code:\n" << tool.code << "\n";
std::cout << "Fix history size: " << tool.fix_history.size() << "\n";
}
void test_code_debugging() {
std::cout << "\n[TEST 2] Self-Debugging System\n";
std::cout << std::string(50, '-') << "\n";
AutonomousToolSystem system;
system.initialize();
// Test code with deliberate errors
std::string buggy_code = R"(
int calculate(int x) {
int result = x / 0; // Division by zero!
if (x > 0 { // Missing closing paren
result = x * 2
} // Missing semicolon
return result;
)"; // Missing closing brace
std::cout << "Original buggy code:\n" << buggy_code << "\n";
// Analyze for errors
auto errors = system.debugger.analyze(buggy_code);
std::cout << "\nFound " << errors.size() << " errors:\n";
for (const auto& error : errors) {
std::cout << " - " << error.message << " (severity: " << error.severity << ")\n";
}
// Debug and fix
for (const auto& error : errors) {
auto fix = system.debug_code(buggy_code, error.message);
if (fix.confidence > 0.0f) {
std::cout << "\nFix proposal (confidence: " << fix.confidence << "):\n";
std::cout << fix.explanation;
buggy_code = fix.fixed_code;
}
}
std::cout << "\nFixed code:\n" << buggy_code << "\n";
}
void test_tool_execution() {
std::cout << "\n[TEST 3] Sandboxed Tool Execution\n";
std::cout << std::string(50, '-') << "\n";
AutonomousToolSystem system;
system.initialize();
// Create a simple tool
ToolSpec spec;
spec.name = "square";
spec.description = "Square a number";
spec.input_type = Type::integer();
spec.output_type = Type::integer();
auto tool = system.create_tool(spec);
// Execute multiple times
std::cout << "Executing tool 'square' with various inputs:\n";
for (int i = 1; i <= 5; ++i) {
auto result = system.execute_tool("square", std::to_string(i));
std::cout << " Input: " << i << " -> " << (result.success ? result.output : result.error) << "\n";
}
std::cout << "\nExecution stats:\n";
std::cout << " Invocation count: " << system.tools["square"].invocation_count << "\n";
std::cout << " Success rate: " << system.tools["square"].success_rate << "\n";
}
void test_hoare_verification() {
std::cout << "\n[TEST 4] Mathematical Verification (Hoare Logic)\n";
std::cout << std::string(50, '-') << "\n";
MathematicalVerifier verifier;
// Test case 1: Valid Hoare triple
HoareTriple triple1;
triple1.precondition = "x >= 0";
triple1.code = "y := x + 1";
triple1.postcondition = "y > 0";
auto result1 = verifier.verify_hoare(triple1);
std::cout << "Triple 1: {" << triple1.precondition << "} "
<< triple1.code << " {" << triple1.postcondition << "}\n";
std::cout << " Verified: " << (result1.verified ? "YES" : "NO") << "\n";
std::cout << " Confidence: " << result1.confidence << "\n";
// Test case 2: Loop invariant
std::string invariant = "sum >= 0";
std::string loop_body = "sum := sum + i; i := i + 1";
auto result2 = verifier.verify_invariant(invariant, loop_body);
std::cout << "\nLoop invariant: " << invariant << "\n";
std::cout << " Preserved: " << (result2.verified ? "YES" : "NO") << "\n";
}
void test_gate5000_integration() {
std::cout << "\n[TEST 5] Gate5000 Substrate Integration\n";
std::cout << std::string(50, '-') << "\n";
AutonomousToolSystem system;
system.initialize();
std::cout << "Initial substrate state:\n";
std::cout << " Bits set: " << system.substrate.popcount() << " / 5000\n";
std::cout << " Density: " << system.substrate.popcount() / 5000.0f << "\n";
// Create multiple tools to affect substrate
std::vector<std::string> tool_names = {
"add", "subtract", "multiply", "divide", "modulo",
"power", "sqrt", "log", "exp", "sin"
};
for (const auto& name : tool_names) {
ToolSpec spec;
spec.name = name;
spec.input_type = Type::floating();
spec.output_type = Type::floating();
system.create_tool(spec);
}
// Execute tools to modify substrate
for (const auto& name : tool_names) {
system.execute_tool(name, "42");
}
std::cout << "\nAfter tool operations:\n";
std::cout << " Bits set: " << system.substrate.popcount() << " / 5000\n";
std::cout << " Density: " << system.substrate.popcount() / 5000.0f << "\n";
std::cout << " Tools generated: " << system.tools_generated << "\n";
std::cout << " Successful executions: " << system.successful_executions << "\n";
}
void test_self_improvement() {
std::cout << "\n[TEST 6] Self-Improvement Loop\n";
std::cout << std::string(50, '-') << "\n";
AutonomousToolSystem system;
system.initialize();
// Create initial tool
ToolSpec spec;
spec.name = "learner";
spec.description = "Self-improving function";
spec.input_type = Type::floating();
spec.output_type = Type::floating();
auto tool = system.create_tool(spec);
std::cout << "Running self-improvement iterations...\n\n";
// Simulate improvement loop
for (int iteration = 0; iteration < 5; ++iteration) {
std::cout << "Iteration " << (iteration + 1) << ":\n";
// Execute and measure
auto result = system.execute_tool("learner", std::to_string(iteration));
// Analyze performance
auto errors = system.debugger.analyze(system.tools["learner"].code);
std::cout << " Errors found: " << errors.size() << "\n";
std::cout << " Success rate: " << system.tools["learner"].success_rate << "\n";
std::cout << " Fix history size: " << system.tools["learner"].fix_history.size() << "\n";
// Apply fixes
for (const auto& error : errors) {
auto fix = system.debugger.debug(system.tools["learner"].code, error);
if (fix.confidence > 0.3f) {
system.tools["learner"].code = fix.fixed_code;
system.tools["learner"].fix_history.push_back(fix);
}
}
}
system.print_stats();
}
int main() {
std::cout << "\n";
std::cout << "╔═══════════════════════════════════════════════════════════════════════════════╗\n";
std::cout << "║ AUTONOMOUS TOOL SYSTEM TEST SUITE ║\n";
std::cout << "║ Gate5000 AGI Substrate Integration ║\n";
std::cout << "╠═══════════════════════════════════════════════════════════════════════════════╣\n";
std::cout << "║ Golden Ratio Constants: ║\n";
std::cout << "║ φ = " << std::fixed << std::setprecision(16) << PHI << " ║\n";
std::cout << "║ α = " << ALPHA << " ║\n";
std::cout << "║ β = " << BETA << " ║\n";
std::cout << "║ γ = " << GAMMA << " ║\n";
std::cout << "╚═══════════════════════════════════════════════════════════════════════════════╝\n";
auto start = std::chrono::high_resolution_clock::now();
// Run all tests
test_tool_generation();
print_separator();
test_code_debugging();
print_separator();
test_tool_execution();
print_separator();
test_hoare_verification();
print_separator();
test_gate5000_integration();
print_separator();
test_self_improvement();
print_separator();
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "\n";
std::cout << "╔═══════════════════════════════════════════════════════════════════════════════╗\n";
std::cout << "║ ALL TESTS COMPLETE ║\n";
std::cout << "╠═══════════════════════════════════════════════════════════════════════════════╣\n";
std::cout << "║ Total execution time: " << std::setw(6) << duration.count() << " ms ║\n";
std::cout << "╚═══════════════════════════════════════════════════════════════════════════════╝\n";
return 0;
}