Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

πŸ”– Checkpoint: Edit /workspaces/claude-code-flow/benchmark/examples/basic/simple_swarm.py

rUv18a2f3a891ff
diff --git a/benchmark/.claude/checkpoints/task-1754447669.json b/benchmark/.claude/checkpoints/task-1754447669.json
new file mode 100644
index 0000000000..6c34a3f832
--- /dev/null
+++ b/benchmark/.claude/checkpoints/task-1754447669.json
@@ -0,0 +1 @@
+{"checkpoint": "task-20250806-023428", "task": "full implement all real benchmarks and optmization in swarm-benchmark cli commands in benchmark/src/", "timestamp": "2025-08-06T02:34:29Z", "commit": "005114243d5879bf11e41c624e5ee1136d8e61b6", "github_release": "true"}
diff --git a/benchmark/examples/basic/simple_swarm.py b/benchmark/examples/basic/simple_swarm.py
new file mode 100644
index 0000000000..c80a88357a
--- /dev/null
+++ b/benchmark/examples/basic/simple_swarm.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python3
+"""
+Simple swarm benchmark example using real claude-flow execution.
+
+This example demonstrates:
+- Basic swarm initialization
+- Simple task execution
+- Metrics collection
+- Best practices for swarm coordination
+"""
+
+import subprocess
+import sys
+import json
+from pathlib import Path
+
+def run_swarm_benchmark():
+ """Run a simple swarm benchmark using CLI commands."""
+ print("πŸš€ Starting Simple Swarm Benchmark")
+ print("=" * 50)
+
+ # Example 1: Using CLI
+ print("\nπŸ“‹ Method 1: CLI Execution")
+ cmd = [
+ "swarm-benchmark", "real", "swarm",
+ "Create a hello world API with basic authentication",
+ "--strategy", "auto",
+ "--max-agents", "3",
+ "--output-format", "json"
+ ]
+
+ try:
+ result = subprocess.run(cmd, capture_output=True, text=True, cwd="/workspaces/claude-code-flow/benchmark")
+ if result.returncode == 0:
+ print(f"βœ… CLI execution successful")
+ print(f"πŸ“Š Output: {result.stdout[:200]}...")
+ else:
+ print(f"❌ CLI execution failed: {result.stderr}")
+ except Exception as e:
+ print(f"⚠️ CLI execution error: {e}")
+
+ # Example 2: Using Python API
+ print("\nπŸ“‹ Method 2: Python API")
+ try:
+ from swarm_benchmark import BenchmarkEngine
+
+ # Initialize with real executor
+ engine = BenchmarkEngine(use_real_executor=True)
+
+ # Configure benchmark
+ config = {
+ "task": "Create a simple REST API",
+ "strategy": "auto",
+ "max_agents": 3,
+ "coordination_mode": "hierarchical"
+ }
+
+ # Run benchmark
+ result = engine.run_benchmark(**config)
+
+ print(f"βœ… Python API execution successful")
+ print(f"πŸ“Š Result ID: {result.get('benchmark_id', 'unknown')}")
+ print(f"🎯 Task completion: {result.get('status', 'unknown')}")
+
+ except ImportError:
+ print("⚠️ Swarm benchmark package not available, install with: pip install -e .")
+ except Exception as e:
+ print(f"❌ Python API error: {e}")
+
+def demonstrate_metrics_collection():
+ """Show how to collect and interpret metrics."""
+ print("\nπŸ“Š Metrics Collection Example")
+ print("=" * 30)
+
+ # Example metrics structure
+ sample_metrics = {
+ "benchmark_id": "simple-swarm-demo",
+ "execution_time": 45.2,
+ "agents_used": 3,
+ "tokens_consumed": 1250,
+ "task_completion_rate": 100.0,
+ "coordination_efficiency": 85.5,
+ "memory_usage_mb": 128.4
+ }
+
+ print("Sample metrics structure:")
+ print(json.dumps(sample_metrics, indent=2))
+
+ # Save to file
+ output_dir = Path("/workspaces/claude-code-flow/benchmark/examples/output")
+ output_dir.mkdir(exist_ok=True)
+
+ with open(output_dir / "simple_swarm_metrics.json", "w") as f:
+ json.dump(sample_metrics, f, indent=2)
+
+ print(f"πŸ“ Metrics saved to: {output_dir / 'simple_swarm_metrics.json'}")
+
+def show_best_practices():
+ """Display best practices for swarm benchmarking."""
+ print("\nπŸ’‘ Best Practices")
+ print("=" * 20)
+
+ practices = [
+ "Start with small agent counts (3-5) for testing",
+ "Use 'auto' strategy to let the system choose optimal coordination",
+ "Always collect metrics for performance analysis",
+ "Use hierarchical coordination for complex tasks",
+ "Monitor token consumption to optimize costs",
+ "Test with real claude-flow integration for accurate results"
+ ]
+
+ for i, practice in enumerate(practices, 1):
+ print(f"{i}. {practice}")
+
+if __name__ == "__main__":
+ run_swarm_benchmark()
+ demonstrate_metrics_collection()
+ show_best_practices()
+
+ print("\nπŸŽ‰ Simple Swarm Benchmark Complete!")
+ print("Next steps:")
+ print("- Try advanced examples in ../advanced/")
+ print("- Run real benchmarks in ../real/")
+ print("- Check CLI examples in ../cli/")
\ No newline at end of file