vaisnav25/Recursive-Code-Generator-Executor
0
๐ค Recursive AI Executor (RAIE)
An intelligent Python code generation and execution platform that learns from failures and progressively improves code quality through recursive AI-powered debugging.
โจ Features
๐ง Intelligent Retry Logic
- Progressive Learning: Each failed attempt informs the next generation cycle
- Error Pattern Recognition: Automatically categorizes and learns from different error types
- Adaptive System Prompts: AI prompts become more sophisticated with each retry
- Success Rate Tracking: Monitor improvement over time
๐ Advanced Error Analysis
- Automatic Error Categorization: Syntax, Import, Name, Type, Index, Key, and Indentation errors
- Context-Aware Suggestions: Tailored recommendations based on error patterns
- Line Number Extraction: Pinpoint exact error locations
- Cumulative Learning: Builds knowledge from all previous attempts
๐ป Code Execution Engine
- Sandboxed Execution: Safe code execution in temporary files
- Timeout Protection: Prevents infinite loops with 15-second timeout
- Comprehensive Error Reporting: Detailed stdout/stderr capture
- Real-time Status Updates: Live progress tracking during execution
๐ Enhanced Analytics
- Execution History: Complete record of all code generation sessions
- Learning Insights: Visual indicators of when AI learning is applied
- Performance Metrics: Success rates and attempt statistics
- Detailed Logs: Comprehensive debugging information for each attempt
๐ Installation
Prerequisites
- Python 3.7 or higher
- Mistral AI API key
Setup
- Clone or download the repository
git clone <repository-url>
cd raie- Install dependencies
pip install -r requirements.txt- Set up environment variables
Create a .env file in the project root:
MISTRAL_API_KEY=your_mistral_api_key_hereAlternatively, you can enter the API key directly in the web interface.
- Run the application
streamlit run raie.py- Access the web interface
Open your browser and navigate to http://localhost:8501
๐ฏ Usage
Basic Workflow
- Enter Your Programming Task
- Describe what you want the code to do
- Be specific about requirements and expected behavior
- Example: "Create a function to find prime numbers up to n=100 and display them"
- Configure Settings (Optional)
- Adjust maximum retry attempts (1-10)
- Enable/disable learning context display
- Monitor success rates and metrics
- Generate & Execute
- Click "๐ Generate & Execute"
- Watch the AI progressively improve code through multiple attempts
- View real-time error analysis and learning insights
- Review Results
- Examine generated code and execution output
- Download successful code for later use
- Analyze execution logs for debugging insights
Example Prompts
โ
Good Prompts:
- "Create a password generator with customizable length and character sets"
- "Build a CSV file reader that handles missing values and calculates statistics"
- "Write a web scraper for extracting product prices from HTML"
- "Generate a simple calculator with error handling for division by zero"
โ Avoid:
- Vague requests: "write some code"
- Requiring external APIs without credentials
- Tasks needing non-standard libraries (RAIE uses only Python standard library)๐๏ธ Architecture
Core Components
๐ง ErrorAnalyzer
- Purpose: Categorizes and analyzes execution errors
- Key Methods:
categorize_error(): Classifies error types and extracts metadatabuild_learning_context(): Creates cumulative learning from all attempts
๐ค MistralAIClient
- Purpose: Handles AI code generation with progressive intelligence
- Key Methods:
generate_code(): Creates code with attempt-aware prompting_build_system_prompt(): Constructs increasingly sophisticated system prompts_clean_generated_code(): Removes markdown artifacts from generated code
โก CodeExecutor
- Purpose: Safely executes Python code in sandboxed environment
- Key Methods:
execute_python_code(): Runs code with timeout and error capture
Learning Progression
Attempt 1: Basic code generation
โ
Attempt 2-3: Debugging mode with error analysis
โ
Attempt 4+: Expert recovery mode with complete rewrites๐ง Configuration
Environment Variables
MISTRAL_API_KEY=your_api_key_here # Required: Mistral AI API keyRuntime Settings
- Max Retry Attempts: 1-10 (default: 5)
- Show Learning Context: Display AI learning insights
- Success Rate Tracking: Monitor performance metrics
๐ Error Categories
RAIE automatically recognizes and learns from these error types:
๐ Security Features
- Sandboxed Execution: Code runs in temporary files with limited permissions
- Timeout Protection: 15-second execution limit prevents runaway processes
- No External Dependencies: Uses only Python standard library for safety
- Input Validation: Comprehensive error handling throughout the application
๐ค Contributing
Code Structure
raie.py
โโโ ErrorAnalyzer # Error categorization and learning
โโโ MistralAIClient # AI code generation
โโโ CodeExecutor # Safe code execution
โโโ main() # Streamlit interfaceDevelopment Guidelines
- Follow Python PEP 8 style guidelines
- Add comprehensive error handling
- Include docstrings for all classes and methods
- Test edge cases and error conditions
๐ Performance Tips
For Better Results
- Be Specific: Detailed prompts generate better code
- Include Context: Mention expected inputs, outputs, and constraints
- Error Tolerance: Let RAIE learn from failures - don't stop at first error
- Review Logs: Use execution analytics to understand AI learning patterns
Troubleshooting
- API Errors: Verify Mistral AI API key and network connectivity
- Execution Timeouts: Simplify complex algorithms or increase timeout
- Memory Issues: Restart application if session state becomes corrupted
๐ License
This project is open source. Please check the license file for specific terms.
๐ Support
If you encounter issues:
- Check the execution logs for detailed error information
- Verify your Mistral AI API key is valid
- Ensure all dependencies are installed correctly
- Review the troubleshooting section above
๐ Version History
Current Features
- โ Recursive AI-powered code generation
- โ Progressive error learning
- โ Comprehensive execution analytics
- โ Real-time status updates
- โ Code download functionality
Roadmap
- ๐ Support for additional AI models
- ๐ Custom error pattern training
- ๐ Code performance optimization suggestions
- ๐ Integration with version control systems
Built with โค๏ธ and powered by AI intelligence that gets smarter with every failure!
