All Toolsโ€บRecursive Agent Debugger
๐Ÿ”ง Recursive AI AgentsMay 3, 2026โœ… Tests passing

Recursive Agent Debugger

This tool allows AI developers to step through and visualize the recursive decision-making process of self-improving AI agents. It monitors how agents evolve their logic over iterations and provides debugging hooks to inspect state changes, decision trees, and improvement metrics. This is particularly useful for identifying where recursive agents might encounter logical flaws or inefficiencies in their self-improvement loops.

What It Does

  • Load and debug custom AI agent classes.
  • Visualize the decision-making process as a graph.
  • Display performance metrics in a tabular format.

Installation

Install the required dependencies:

pip install networkx matplotlib rich

Usage

Suppose you have an agent.py file with the following content:

class Agent:
    def __init__(self):
        self.state = 0

    def get_state(self):
        return self.state

    def make_decision(self):
        return f"decision_{self.state}"

    def improve_logic(self):
        self.state += 1
        return f"improvement_{self.state}"

Run the debugger as follows:

python recursive_agent_debugger.py --agent_file agent.py --steps 5

This will visualize the decision tree and display the performance metrics.

Source Code

import argparse
import importlib.util
import os
import sys
import networkx as nx
import matplotlib.pyplot as plt
from rich.console import Console
from rich.table import Table
from rich import print

console = Console()

def load_agent_class(file_path):
    if not os.path.exists(file_path):
        raise FileNotFoundError(f"The file '{file_path}' does not exist.")

    spec = importlib.util.spec_from_file_location("agent_module", file_path)
    agent_module = importlib.util.module_from_spec(spec)
    sys.modules["agent_module"] = agent_module
    spec.loader.exec_module(agent_module)

    if not hasattr(agent_module, "Agent"):
        raise AttributeError("The provided file does not define an 'Agent' class.")

    return agent_module.Agent

def visualize_decision_tree(tree, output_file="decision_tree.png"):
    pos = nx.spring_layout(tree)
    plt.figure(figsize=(12, 8))
    nx.draw(tree, pos, with_labels=True, node_size=3000, node_color="lightblue", font_size=10, font_weight="bold")
    plt.savefig(output_file)
    plt.close()
    console.print(f"[green]Decision tree visualization saved to {output_file}[/green]")

def debug_agent(agent_class, steps):
    agent = agent_class()
    decision_tree = nx.DiGraph()
    performance_metrics = []

    prev_state = None
    for step in range(steps):
        console.print(f"[bold blue]Step {step + 1}[/bold blue]")
        state = agent.get_state()
        decision = agent.make_decision()
        improvement = agent.improve_logic()

        decision_tree.add_node(f"Step {step + 1}: {state}")
        if step > 0:
            decision_tree.add_edge(f"Step {step}: {prev_state}", f"Step {step + 1}: {state}")

        performance_metrics.append((step + 1, state, decision, improvement))
        prev_state = state

    return decision_tree, performance_metrics

def display_metrics(metrics):
    table = Table(title="Performance Metrics")
    table.add_column("Step", justify="right", style="cyan")
    table.add_column("State", style="magenta")
    table.add_column("Decision", style="green")
    table.add_column("Improvement", style="yellow")

    for step, state, decision, improvement in metrics:
        table.add_row(str(step), str(state), str(decision), str(improvement))

    console.print(table)

def main():
    parser = argparse.ArgumentParser(description="Recursive Agent Debugger")
    parser.add_argument("--agent_file", required=True, help="Path to the Python file containing the Agent class.")
    parser.add_argument("--steps", type=int, default=10, help="Number of recursive iterations to debug.")
    args = parser.parse_args()

    try:
        agent_class = load_agent_class(args.agent_file)
        decision_tree, metrics = debug_agent(agent_class, args.steps)
        visualize_decision_tree(decision_tree)
        display_metrics(metrics)
    except Exception as e:
        console.print(f"[red]Error: {e}[/red]")

if __name__ == "__main__":
    main()

Community

Downloads

ยทยทยท

Rate this tool

No ratings yet โ€” be the first!

Details

Tool Name
recursive_agent_debugger
Category
Recursive AI Agents
Generated
May 3, 2026
Tests
Passing โœ…
Fix Loops
2

Quick Install

Clone just this tool:

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/ptulin/autoaiforge.git
cd autoaiforge
git sparse-checkout set generated_tools/2026-05-03/recursive_agent_debugger
cd generated_tools/2026-05-03/recursive_agent_debugger
pip install -r requirements.txt 2>/dev/null || true
python recursive_agent_debugger.py