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