Transform Python into High-Performance C++ with Autonomous AI Agents
A revolutionary code generation platform that uses multiple specialized AI agents to convert Python code into optimized C++, featuring parallel processing, comprehensive validation, and enterprise-grade reliability.
- 7 Specialized AI Agents working in orchestrated workflows
- Analyzer Agent: Code complexity assessment and conversion planning
- Translator Agent: Python-to-C++ conversion with semantic preservation
- Optimizer Agent: Performance optimization and algorithmic improvements
- Verifier Agent: Output validation and correctness verification
- Refiner Agent: Iterative improvement and error correction
- Parallel Processing: Concurrent file processing with ThreadPoolExecutor
- Intelligent Optimization: Compiler flags, memory management, and algorithmic improvements
- Performance Benchmarking: Automated Python vs C++ comparison with speedup metrics
- Input Validation: AST-based security scanning and code sanitization
- Circuit Breakers: Automatic failure recovery and resource protection
- Memory Management: Automatic cleanup and resource monitoring
- Run History Tracking: Complete audit trail of all conversions
- Agent Flow Visualization: Interactive workflow diagrams and step analysis
- Performance Analytics: Success rates, conversion times, and error patterns
# Python 3.9+
python --version
# uv (fast Python package manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
# C++ Compiler (macOS)
brew install llvm# Clone repository
git clone https://github.com/surpradhan/agentic-codegen.git
cd agentic-codegen
# Install dependencies (creates .venv automatically)
uv sync
# Setup API key
echo "GROQ_API_KEY=your_api_key_here" > .envfrom agentic_codegen import CodeGenerator
# Initialize
generator = CodeGenerator()
# Convert Python to C++
python_code = """
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
print(fibonacci(10))
"""
cpp_code, metadata = generator.convert(python_code)
print(f"Success: {metadata['success']}")
print(cpp_code)# Start web UI
python main.py --web
class CodeGenerator:
def convert(self, code: str, target_lang: str = "cpp") -> Tuple[str, Dict]
def convert_file(self, input_path: str, output_path: str = None) -> Dict
def convert_directory(self, input_dir: str, output_dir: str, **kwargs) -> List[Dict]
def benchmark(self, code: str, iterations: int = 5) -> Dict- AnalyzerAgent: Complexity analysis, feature detection, conversion planning
- TranslatorAgent: Semantic translation with type inference and optimization
- OptimizerAgent: Algorithmic improvements and compiler optimization
- VerifierAgent: Functional correctness verification and output validation
- RefinerAgent: Error correction and iterative refinement
- AST Analysis: Abstract Syntax Tree parsing for security validation
- Code Sanitization: Removal of dangerous patterns and imports
- Complexity Assessment: Automatic difficulty classification
- Circuit Breakers: Resource protection and failure isolation
# Process entire directories with parallel workers
results = generator.convert_directory(
input_dir="./python_project",
output_dir="./cpp_output",
max_workers=4, # Parallel processing
recursive=True
)
# Results include success rates and performance metrics
success_rate = sum(1 for r in results if r['success']) / len(results)# Compare Python vs C++ performance
results = generator.benchmark(python_code, iterations=10)
print(f"Python time: {results['python_time_avg']:.4f}s")
print(f"C++ time: {results['cpp_time_avg']:.4f}s")
print(f"Speedup: {results['speedup']:.1f}x")from agentic_codegen.utils.run_history import get_run_history_manager
history = get_run_history_manager()
# Get recent runs
recent_runs = history.get_run_history(limit=10)
# Get performance statistics
stats = history.get_run_statistics(days=7)
print(f"Success rate: {stats['success_rate']:.1%}")
print(f"Average duration: {stats['avg_duration']:.2f}s")# API Keys
GROQ_API_KEY=your_groq_api_key
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
# System Configuration
MAX_ITERATIONS=3
COMPILATION_TIMEOUT=30
OPTIMIZATION_LEVEL=1
# Model Preferences
PRIMARY_MODEL=openai/gpt-oss-120b
FALLBACK_MODEL=claude-3-sonnet{
"api_keys": {
"groq": "your_key",
"openai": "your_key"
},
"agents": {
"max_iterations": 3,
"optimization_level": 1
},
"compilation": {
"compiler": "clang++",
"flags": "-std=c++17 -Ofast"
}
}- Real-time Python to C++ conversion
- Syntax highlighting and error display
- Progress tracking and agent status
- Directory-wide conversion with progress bars
- Recursive processing and pattern matching
- Parallel worker configuration
- Automated Python vs C++ performance comparison
- Statistical analysis and speedup calculations
- Detailed timing breakdowns
- Interactive workflow visualization
- Step-by-step agent execution tracking
- Performance bottleneck identification
- Complete conversion history with filtering
- Success rate analytics and trends
- Detailed run inspection and debugging
- Model selection and API configuration
- Optimization level tuning
- Compiler flag customization
# Run comprehensive test suite
pytest tests/ -v --cov=agentic_codegen
# Test specific components
pytest tests/test_agents.py -k "translator"
pytest tests/test_validation.py# Test full conversion pipeline
python test_examples.py
# Test batch processing
python -m pytest tests/test_batch_processing.py# Benchmark different code patterns
python benchmark_examples.py
# Memory usage analysis
python -m memory_profiler main.py- Simple Functions: 98%+ accuracy
- Complex Algorithms: 95%+ accuracy
- Mathematical Code: 97%+ accuracy
- Data Processing: 94%+ accuracy
- Algorithmic Optimization: 2-10x speedup
- Memory Efficiency: 50-80% reduction
- Compilation Optimization: Additional 2-5x speedup
Fibonacci (n=30): Python 0.8s β C++ 0.02s (40x speedup)
Matrix Multiplication: Python 12.3s β C++ 0.8s (15x speedup)
Pi Calculation (1M iterations): Python 2.1s β C++ 0.15s (14x speedup)
βββ core/
β βββ main.py # Main CodeGenerator class
β βββ config.py # Configuration management
βββ agents/
β βββ orchestrator.py # Agent coordination
β βββ analyzer.py # Code analysis
β βββ translator.py # Code translation
β βββ optimizer.py # Performance optimization
β βββ verifier.py # Output verification
β βββ refiner.py # Iterative refinement
βββ utils/
β βββ validation.py # Security & syntax validation
β βββ executor.py # Code execution & compilation
β βββ memory_manager.py # Resource management
β βββ circuit_breaker.py # Failure recovery
β βββ run_history.py # Analytics & tracking
β βββ logger.py # Logging system
βββ ui/
β βββ web_interface.py # Gradio web interface
βββ tests/
βββ unit/ # Unit tests
βββ integration/ # Integration tests
βββ benchmarks/ # Performance tests
Input Code β Validation β Analysis β Translation β Optimization β Verification β Refinement β Output
β β β β β β β β
Security Complexity Type Algorithm Compiler Correctness Error Final
Checks Assessment Inference Optimization Flags Verification Correction Code
# Fork and clone
git clone https://github.com/surpradhan/agentic-codegen.git
cd agentic-codegen
# Install all dependencies including dev (creates .venv automatically)
uv sync --dev
# Run tests
uv run pytest tests/- PEP 8 compliance with Black formatting
- Type hints for all function signatures
- Comprehensive docstrings with examples
- Unit test coverage > 95%
- Integration tests for all major features
from ..utils.base_agent import BaseAgent
class CustomAgent(BaseAgent):
def execute(self, input_data: Dict) -> Dict:
"""Implement custom agent logic."""
# Your implementation here
passThis project is licensed under the MIT License - see the LICENSE file for details.
- Groq for providing fast LLM inference
- Gradio for the excellent web interface framework
- Clang/LLVM for C++ compilation and optimization
- Open-source community for inspiration and tools
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Built with β€οΈ for the future of AI-assisted software engineering
- β Multi-agent architecture (7 specialized agents)
- β Python to C++ conversion
- β Web interface (Gradio)
- β Parallel batch processing (directory-wide conversion)
- β Performance benchmarking (Python vs C++ comparison)
- β Language handler framework (Rust, Go handlers built; C++ fully integrated)
- β Collaborative workspaces (team sharing, code reviews, role-based permissions)
- β Metrics collection & performance analytics
- β Database persistence (SQLAlchemy models, run history tracking)
- β Security validation (AST-based scanning, circuit breakers)
- π Full Multi-language Integration: Wire Rust & Go handlers into main pipeline; add Julia support
- π Cloud Deployment: REST API endpoints (FastAPI), Docker containers
- π Advanced Optimization: SIMD vectorization, GPU acceleration hints
- π IDE Integration: VS Code extension, PyCharm plugin
- π Advanced Analytics: ML-powered optimization suggestions
- π Auto-scaling: Dynamic agent pool management and load balancing
- π Deep Code Understanding: Neural network-based semantic analysis
- π Cross-file Dependency Analysis: Import graph resolution and multi-file linking
- π Real-time Performance Profiling: Live optimization feedback during conversion
- π Enhanced Collaboration: Persistent database-backed reviews, team dashboards
Transform your Python code into high-performance C++ with the power of autonomous AI agents! π