All Toolsโ€บClaude Agent Loop Runner
๐Ÿ”ง Claude Code Updates and SDKMarch 8, 2026โœ… Tests passing

Claude Agent Loop Runner

This CLI tool simplifies the creation and execution of agent loops using the Claude AI SDK. Users can define task workflows as JSON or YAML files, which the tool translates into Claude-compatible agent loops. Developers can use this tool to quickly prototype complex multi-step AI workflows without manually coding the logic.

What It Does

  • Load workflows from JSON or YAML files.
  • Execute workflows using the Claude AI SDK.
  • Set a maximum number of iterations for workflow execution.

Installation

  • Python 3.7+
  • anthropic
  • pyyaml
  • rich

Usage

Run the tool using the following command:

python claude_agent_loop_runner.py --workflow <path_to_workflow_file> --max-iterations <max_iterations> --api-key <your_api_key>

Arguments

  • --workflow: Path to the workflow file (JSON or YAML).
  • --max-iterations: Maximum number of iterations (default: 10).
  • --api-key: Your Anthropic API key.

Source Code

import argparse
import json
import yaml
from anthropic import Anthropic
from rich.console import Console
from rich.logging import RichHandler
import logging

# Set up logging
console = Console()
logging.basicConfig(level=logging.INFO, handlers=[RichHandler(console=console)])
logger = logging.getLogger("ClaudeAgentLoopRunner")

def load_workflow(file_path):
    """Load workflow from a JSON or YAML file."""
    try:
        with open(file_path, 'r') as file:
            content = file.read()
            if file_path.endswith('.json'):
                return json.loads(content)
            elif file_path.endswith('.yaml') or file_path.endswith('.yml'):
                return yaml.safe_load(content)
            else:
                raise ValueError("Unsupported file format. Use JSON or YAML.")
    except Exception as e:
        logger.error(f"Failed to load workflow: {e}")
        raise

def execute_workflow(workflow, anthropic_client, max_iterations):
    """Execute the workflow using the Claude AI SDK."""
    try:
        for step in workflow.get("steps", []):
            if max_iterations <= 0:
                logger.info("Max iterations reached. Exiting.")
                break

            prompt = step.get("prompt")
            if not prompt:
                logger.warning("Step missing 'prompt'. Skipping.")
                continue

            logger.info(f"Executing step: {step.get('name', 'Unnamed Step')}")
            response = anthropic_client.completions.create(
                model="claude-v1",
                prompt=prompt,
                max_tokens_to_sample=step.get("max_tokens", 100)
            )

            logger.info(f"Response: {response.get('completion', 'No response')}") if response else logger.info("No response received.")
            max_iterations -= 1
    except Exception as e:
        logger.error(f"Error during workflow execution: {e}")
        raise

def main():
    """Main function for CLI."""
    parser = argparse.ArgumentParser(description="Claude Agent Loop Runner")
    parser.add_argument("--workflow", required=True, help="Path to the workflow file (JSON/YAML).")
    parser.add_argument("--max-iterations", type=int, default=10, help="Maximum number of iterations.")
    parser.add_argument("--api-key", required=True, help="Anthropic API key.")

    args = parser.parse_args()

    try:
        workflow = load_workflow(args.workflow)
        anthropic_client = Anthropic(api_key=args.api_key)
        execute_workflow(workflow, anthropic_client, args.max_iterations)
    except Exception as e:
        logger.error(f"Failed to run Claude Agent Loop Runner: {e}")

if __name__ == "__main__":
    main()

Community

Downloads

ยทยทยท

Rate this tool

No ratings yet โ€” be the first!

Details

Tool Name
claude_agent_loop_runner
Category
Claude Code Updates and SDK
Generated
March 8, 2026
Tests
Passing โœ…
Fix Loops
4

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-03-08/claude_agent_loop_runner
cd generated_tools/2026-03-08/claude_agent_loop_runner
pip install -r requirements.txt 2>/dev/null || true
python claude_agent_loop_runner.py
Claude Agent Loop Runner โ€” AI Tools by AutoAIForge