An intelligent AI-powered DevOps assistant that automatically monitors application logs, detects errors in real-time, and suggests code-level fixes using GPT-4. The system simulates a complete CI/CD pipeline by auto-generating Pull Requests with proposed fixes.
- Overview
- Key Features
- Architecture
- Tech Stack
- Screenshots
- Project Structure
- Installation
- Usage
- How It Works
- API Configuration
- Future Enhancements
- Contributing
- Author
The Self-Healing Code Agent revolutionizes DevOps workflows by automating the error detection and resolution process. Instead of manually monitoring logs and debugging issues, this AI agent:
- Monitors application logs in real-time
- Detects errors, exceptions, and anomalies automatically
- Analyzes the error context using GPT-4
- Generates code-level fixes with explanations
- Creates Pull Requests with the proposed solution
- Simulates a complete CI/CD pipeline workflow
Perfect for: DevOps engineers, SREs, development teams, and anyone managing production systems who want to reduce MTTR (Mean Time To Resolution) and automate incident response.
- Real-time log file monitoring and parsing
- Pattern-based anomaly detection (ERROR, Exception, FATAL, etc.)
- Contextual error extraction with surrounding log lines
- Support for multiple log formats and sources
- GPT-4 integration for intelligent code analysis
- Root cause identification from error messages
- Context-aware fix generation
- Code explanation and best practices suggestions
- Simulated Pull Request creation with fix details
- Pre-commit validation and testing hooks
- Integration-ready for GitHub/GitLab APIs
- Automated fix verification pipeline
- Beautiful Streamlit web dashboard
- Real-time error display and fix suggestions
- Interactive PR preview and management
- CLI support for automation and scripting
- Environment-based API key management
- Configurable error detection thresholds
- Custom log pattern support
- Easy integration with existing systems
┌─────────────────────────────────────────────────────────────┐
│ Log Sources Layer │
│ (Application Logs, System Logs, Error Logs) │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Log Monitor Module │
│ (monitor/anomaly_detector.py) │
│ • Real-time log watching │
│ • Pattern matching (ERROR, Exception, FATAL) │
│ • Error extraction with context │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Parser Module │
│ (utils/parser.py) │
│ • Log line parsing and structuring │
│ • Timestamp and severity extraction │
│ • Context aggregation │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ AI Fix Agent Module │
│ (agent/llm_fix_agent.py) │
│ • GPT-4 API integration │
│ • Error analysis and root cause detection │
│ • Code fix generation with explanations │
│ • Best practices recommendations │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ CI/CD Automation Module │
│ (cicd/create_pr.py) │
│ • Pull Request generation │
│ • Fix documentation and formatting │
│ • Pre-commit hooks simulation │
│ • Integration with GitHub/GitLab APIs │
└────────────────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ User Interface Layer │
│ (streamlit_app.py / main.py CLI) │
│ • Dashboard visualization │
│ • Interactive fix review │
│ • PR management │
│ • Configuration settings │
└─────────────────────────────────────────────────────────────┘
| Component | Technology | Purpose |
|---|---|---|
| AI/ML | OpenAI GPT-4 | Intelligent error analysis and fix generation |
| Backend | Python 3.10+ | Core application logic |
| Web UI | Streamlit | Interactive dashboard and visualization |
| Log Processing | Python Logging, Regex | Pattern matching and parsing |
| CI/CD | Custom Python Scripts | PR generation and automation |
| API Management | python-dotenv | Secure environment variable handling |
| Development | Dev Containers | Consistent development environment |
openai>=1.0.0 # GPT-4 API integration
streamlit>=1.28.0 # Web interface
python-dotenv>=1.0.0 # Environment management
watchdog>=3.0.0 # File system monitoring (optional)
requests>=2.31.0 # HTTP requests
(Interactive web interface showing real-time error detection and AI-generated fixes)
(Log monitoring with highlighted errors and anomalies)
(GPT-4 generated code fixes with explanations)
(Auto-generated PR with fix details ready for review)
SelfHealingCodeAgent/
│
├── agent/ # AI Agent Core
│ └── llm_fix_agent.py # GPT-4 integration for fix generation
│
├── cicd/ # CI/CD Automation
│ └── create_pr.py # Pull Request creation logic
│
├── logs/ # Log Storage
│ └── sample_log.txt # Example log file for testing
│
├── monitor/ # Error Detection
│ └── anomaly_detector.py # Log monitoring and pattern matching
│
├── utils/ # Helper Utilities
│ └── parser.py # Log parsing and structuring
│
├── docs/ # Documentation & Demo
│ └── index.html # GitHub Pages landing page
│
├── .devcontainer/ # Development Container
│ └── devcontainer.json # VS Code dev container config
│
├── main.py # CLI Entry Point
├── streamlit_app.py # Web UI Entry Point
├── requirements.txt # Python Dependencies
├── .env.example # Environment Variable Template
├── .gitignore # Git Ignore Rules
└── README.md # Project Documentation
- Python 3.10 or later
- OpenAI API Key → Get one here
- Git (for cloning the repository)
git clone https://github.com/M1325-source/SelfHealingCodeAgent.git
cd SelfHealingCodeAgent# Create virtual environment
python -m venv venv
# Activate on Windows
venv\Scripts\activate
# Activate on macOS/Linux
source venv/bin/activatepip install -r requirements.txt# Copy the example env file
cp .env.example .env
# Edit .env and add your OpenAI API key
# On Windows: notepad .env
# On macOS/Linux: nano .envAdd the following to your .env file:
OPENAI_API_KEY=sk-your-openai-api-key-herepython -c "import streamlit; print('Setup complete!')"Run the agent in terminal mode for automation and scripting:
python main.pyFeatures:
- Monitors
logs/sample_log.txtby default - Detects errors automatically
- Prints AI-generated fixes to console
- Simulates PR creation
Custom Log File:
python main.py --log-file /path/to/your/logfile.logLaunch the interactive web interface:
streamlit run streamlit_app.pyAccess the dashboard:
- Local URL:
http://localhost:8501 - Network URL: Check terminal output for external access
Dashboard Features:
- 📊 Real-time log monitoring visualization
- 🔍 Error detection with highlighting
- 🤖 AI fix suggestions with explanations
- 📝 PR preview and download
- ⚙️ Configuration settings
For a consistent development environment:
- Open the project in VS Code
- Install the "Remote - Containers" extension
- Press
F1→ Select "Reopen in Container" - The environment will be set up automatically
Step 1: Log Monitoring
┌─────────────────────────────────────────┐
│ Monitor watches log files for changes │
│ Detects patterns: ERROR, Exception │
└─────────────┬───────────────────────────┘
▼
Step 2: Error Detection
┌─────────────────────────────────────────┐
│ Anomaly detector extracts error lines │
│ Captures context (5 lines before/after)│
└─────────────┬───────────────────────────┘
▼
Step 3: AI Analysis
┌─────────────────────────────────────────┐
│ GPT-4 analyzes error with context │
│ Generates code-level fix suggestion │
│ Provides explanation and best practices│
└─────────────┬───────────────────────────┘
▼
Step 4: PR Creation
┌─────────────────────────────────────────┐
│ Format fix as Pull Request │
│ Include error details, fix, and tests │
│ Simulate CI/CD pipeline approval │
└─────────────────────────────────────────┘
1. Log Entry Detected:
2026-02-04 10:30:45 ERROR [DatabaseConnection] Connection timeout after 30s
2. AI Analysis:
Root Cause: Database connection pool exhausted
Recommended Fix: Increase pool size and add connection retry logic
3. Generated Fix:
# Before
db_pool = create_pool(max_connections=10)
# After (AI-suggested fix)
db_pool = create_pool(
max_connections=50,
timeout=60,
retry_on_timeout=True,
max_retries=3
)4. Pull Request Created:
Title: [AutoFix] Resolve database connection timeout
Description: Increased connection pool size and added retry logic
Files Changed: database/connection.py
Status: Ready for Review
-
Get Your API Key:
- Visit OpenAI Platform
- Create a new API key
- Copy the key (it starts with
sk-)
-
Set Up Environment:
# Create .env file echo "OPENAI_API_KEY=sk-your-key-here" > .env
-
Verify Configuration:
from dotenv import load_dotenv import os load_dotenv() api_key = os.getenv("OPENAI_API_KEY") print("API configured!" if api_key else "API key missing!")
- Use GPT-4 for complex errors, GPT-3.5 for simple ones
- Cache similar error patterns to avoid redundant API calls
- Set rate limits to control costs
- Monitor usage on OpenAI dashboard
| Feature | Tech Stack | Status | Priority |
|---|---|---|---|
| Real-time log monitoring | Watchdog / OpenTelemetry | 🔄 In Progress | High |
| Auto PR to GitHub | PyGitHub / GitHub API | 📋 Planned | High |
| Automated testing pipeline | Pytest + GitHub Actions | 📋 Planned | High |
| Fix verification loop | Reinforcement Learning | 🔬 Research | Medium |
| Multi-source log aggregation | ELK Stack integration | 📋 Planned | Medium |
| Slack/Teams notifications | Webhook integration | 📋 Planned | Low |
| Custom ML models | TensorFlow / PyTorch | 🔬 Research | Low |
| Dashboard analytics | Plotly / Chart.js | 📋 Planned | Medium |
- Real-time file watching with Watchdog
- Support for multiple log sources
- Custom error pattern configuration
- Integration with OpenTelemetry
- Actual GitHub PR creation via API
- Automated branch creation and commits
- PR review automation
- Integration with GitHub Actions
- Automated test generation for fixes
- Fix verification before PR creation
- Rollback mechanism for failed fixes
- Integration testing pipeline
- Reinforcement learning for fix quality improvement
- Multi-model ensemble for better accuracy
- Custom fine-tuned models for specific codebases
- Predictive error detection
Contributions are welcome! Here's how you can help:
-
Fork the Repository
# Click the 'Fork' button on GitHub -
Clone Your Fork
git clone https://github.com/YOUR_USERNAME/SelfHealingCodeAgent.git cd SelfHealingCodeAgent -
Create a Feature Branch
git checkout -b feature/amazing-feature
-
Make Your Changes
- Add new features
- Fix bugs
- Improve documentation
- Add tests
-
Commit Your Changes
git add . git commit -m "Add amazing feature"
-
Push to Your Fork
git push origin feature/amazing-feature
-
Open a Pull Request
- Go to the original repository
- Click "New Pull Request"
- Describe your changes clearly
- Follow PEP 8 style guide for Python code
- Add docstrings to all functions and classes
- Include unit tests for new features
- Update documentation as needed
- Keep commits atomic and well-described
- 🐛 Bug Fixes: Report and fix issues
- ✨ New Features: Implement items from the roadmap
- 📝 Documentation: Improve README, add tutorials
- 🧪 Testing: Add unit tests and integration tests
- 🎨 UI/UX: Enhance Streamlit dashboard
- 🔧 DevOps: Improve CI/CD, Docker support
This project is licensed under the MIT License - see the LICENSE file for details.
Manisha Priya
AI Developer | DevOps Enthusiast | Automation Architect
Passionate about building intelligent systems that make developers' lives easier.
- 📧 Email: manishapriya1325@gmail.com
- 💼 LinkedIn: linkedin.com/in/your-profile
- 🐙 GitHub: @M1325-source
- 🌐 Website: m1325-source.github.io/SelfHealingCodeAgent
- OpenAI for providing the GPT-4 API
- Streamlit team for the amazing framework
- The DevOps and SRE communities for inspiration
- All contributors and supporters of this project
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: manishapriya1325@gmail.com
Q: How much does it cost to run?
A: Costs depend on OpenAI API usage. Typical usage: ~$0.01-0.05 per error analysis.
Q: Can I use this with private repositories?
A: Yes! Configure GitHub Personal Access Token in .env for private repo access.
Q: Does it work with languages other than Python?
A: Yes! The AI can suggest fixes for any language in your logs.
Q: How accurate are the fixes?
A: GPT-4 provides high-quality suggestions, but always review before applying.
If you find this project useful:
- ⭐ Star the repository on GitHub
- 🍴 Fork it and build something awesome
- 📢 Share it with your dev friends and colleagues
- 💬 Provide feedback through issues or discussions
- 🤝 Contribute by submitting PRs
Every star motivates me to keep improving this project!
- 🌟 3 Stars (and growing!)
- 🔄 10 Deployments on GitHub Pages
- 💻 100% Python codebase
- 📦 14 Commits of continuous improvement
Live Demo: View on GitHub Pages
Video Demo: Check out Self-Healing-DevOps-Demo.mp4 in the repository for a full walkthrough!
Built with ❤️ by Manisha Priya
Making DevOps smarter, one automated fix at a time.
Last Updated: February 2026