AI-powered production incident analysis tool using multi-agent systems
Project description
OpsPilot-AI ๐ค
An intelligent agentic AI CLI tool for automated incident analysis and error resolution
OpsPilot-AI is your AI-powered Site Reliability Engineer that analyzes your projects, identifies runtime issues, and suggests safe fixesโall through a simple command-line interface.
๐ฏ What is OpsPilot-AI?
OpsPilot-AI uses a multi-agent AI architecture to understand your project's context, form hypotheses about runtime issues, and provide evidence-based fix recommendations. Think of it as having an experienced SRE on your team, available 24/7.
Key Capabilities
- ๐ Intelligent Context Gathering - Automatically analyzes logs, environment variables, Docker configs, dependencies, and project structure
- ๐ง Multi-Agent Architecture - 4 specialized agents (Planner, Verifier, Fixer, Remediation) working collaboratively
- ๐ Multi-Provider LLM Support - Automatic fallback across Ollama, OpenRouter, Gemini, and HuggingFace
- โ Evidence-Based Verification - Validates hypotheses with collected evidence and confidence scoring
- ๐ ๏ธ Safe Fix Suggestions - Provides dry-run suggestions with detailed rationale (never auto-applies changes)
- ๐พ Redis-Based Memory - Auto-expiring incident history with user isolation and sub-second lookups
- ๐จ Severity Classification - Automatic P0/P1/P2/P3 incident prioritization
- โ๏ธ Production Log Fetching - S3, Kubernetes, CloudWatch, and HTTP endpoint support
- ๐ Deployment Correlation - Links incidents to recent Git deployments for faster root cause analysis
๐ Quick Start
Prerequisites
- Python 3.8 or higher
- At least ONE of the following LLM providers:
- Ollama (local, free, recommended)
- Google Gemini API key (free tier)
- OpenRouter API key (free models available)
- HuggingFace API token (free tier)
Installation
From PyPI (Recommended):
# Basic installation
pip install opspilot-ai
# With Redis support (recommended for production)
pip install opspilot-ai[redis]
# With all integrations (Redis + AWS + Kubernetes)
pip install opspilot-ai[all]
From Source:
# Clone repository
git clone https://github.com/choudharikiranv15/OpsPilot-AI.git
cd opspilot
# Install in development mode
pip install -e ".[all]"
LLM Setup
Option 1: Ollama (Recommended - Local & Free)
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# Pull Llama 3 model
ollama pull llama3
Option 2: Cloud Providers (FREE tiers)
# Copy environment template
cp .env.example .env
# Add your API keys to .env
# GOOGLE_API_KEY=your-key-here
# OPENROUTER_API_KEY=your-key-here
# HUGGINGFACE_API_KEY=your-key-here
See FREE_LLM_SETUP.md for detailed setup instructions.
Usage
Navigate to your project directory and run:
# Basic analysis
opspilot analyze
# Analyze with production logs from S3
opspilot analyze --log-source s3://my-bucket/logs/app.log
# Analyze with deployment correlation
opspilot analyze --deployment-analysis --since-hours 48
# JSON output for automation
opspilot analyze --json --mode quick
# Verbose output for debugging
opspilot analyze --verbose --debug
Example Output:
Similar issues detected from past runs:
- Redis connection issue caused by network or Redis server downtime (confidence 0.8)
OpsPilot-AI initialized
Project detected: /your/project
Planner Agent reasoning...
Hypothesis: Redis connection issue
Confidence: 0.9
Evidence collected:
{'log_errors': {'ERROR': 1, 'Timeout': 1}, 'uses_redis': True}
Verifying hypothesis...
Supported: True
Confidence: 0.8
Reason: The presence of Redis connection-related errors (Timeout) and the system's use of Redis support the hypothesis.
Generating safe fix suggestions (dry-run)...
File: .env
Increase Redis timeout to reduce transient timeout errors under load.
--- a/.env
+++ b/.env
@@
-REDIS_TIMEOUT=1
+REDIS_TIMEOUT=5
File: app/config/redis.py
Enable connection pooling and reasonable timeouts to improve reliability.
--- a/app/config/redis.py
+++ b/app/config/redis.py
@@
-redis.Redis(host=host, port=port)
+redis.Redis(host=host, port=port, socket_timeout=5, max_connections=20)
๐๏ธ Architecture
OpsPilot-AI implements a multi-agent agentic architecture with four specialized agents:
- Planner Agent - Analyzes project context and forms hypotheses about root causes
- Verifier Agent - Collects evidence and validates hypotheses with confidence scoring
- Fixer Agent - Generates safe, actionable fix suggestions
- Remediation Agent - Creates 3-tier action plans (immediate, short-term, long-term)
Multi-Provider LLM System:
- Automatic fallback routing across 4 providers
- Connection pooling for high availability
- Provider health metrics and monitoring
Redis-Based Memory:
- User-isolated incident storage with SHA-256 project hashing
- Automatic TTL expiration (configurable, default 30 days)
- Sub-second similarity search with sorted sets
- Severity-based indexing (P0/P1/P2/P3)
See ARCHITECTURE.md for detailed design documentation.
๐งฉ How It Works
1. Context Collection
OpsPilot-AI gathers information from multiple sources:
- Logs: Recent error logs and exceptions
- Environment: Environment variables and configurations
- Dependencies: Project dependencies (requirements.txt, package.json)
- Docker: Dockerfile and docker-compose configurations
- Structure: Project file tree and organization
2. Hypothesis Generation
The Planner agent uses LLM reasoning to:
- Analyze collected context
- Identify patterns and anomalies
- Form hypotheses about root causes
- Assign confidence scores (0.0 - 1.0)
3. Evidence-Based Verification
The Verifier agent:
- Collects concrete evidence (log errors, missing configs, etc.)
- Cross-references with the hypothesis
- Updates confidence based on evidence strength
- Provides reasoning for the verdict
4. Safe Fix Suggestions
If confidence โฅ 0.6, the Fixer agent:
- Generates actionable fix suggestions as diffs
- Explains the rationale for each fix
- Provides domain-specific solutions (e.g., Redis timeout fixes)
- Never auto-applies changes (dry-run only for safety)
5. Learning from History
OpsPilot-AI maintains Redis-based memory of past issues:
- Stores hypotheses, confidence scores, and evidence with automatic TTL
- User-isolated storage using project path hashing
- Detects similar issues in future runs with sub-second lookups
- Automatic expiration prevents stale incident data
- Falls back to file-based storage if Redis unavailable
๐ Technology Stack
- LLM Integration: Multi-provider system (Ollama, OpenRouter, Gemini, HuggingFace) with automatic fallback
- Memory Layer: Redis (with file-based fallback) for incident history and similarity detection
- CLI Framework: Typer + Rich (professional terminal output)
- Cloud Integration: AWS (S3, CloudWatch), Kubernetes, HTTP endpoints
- AI Pattern: Multi-agent agentic architecture with 4 specialized agents
- Reasoning: Evidence-based decision making with P0/P1/P2/P3 severity classification
- Prompt Engineering: Robust JSON extraction with retry logic and safe parsing
- Testing: pytest with 45+ unit tests and integration test coverage
๐ Project Structure
opspilot/
โโโ agents/ # Four specialized AI agents
โ โโโ planner.py # Hypothesis generation
โ โโโ verifier.py # Evidence-based verification
โ โโโ fixer.py # Safe fix suggestions
โ โโโ remediation.py # 3-tier remediation plans
โโโ context/ # Context gathering modules
โ โโโ logs.py # Log analysis
โ โโโ env.py # Environment variables
โ โโโ deps.py # Dependency detection
โ โโโ docker.py # Docker configuration
โ โโโ project.py # Project structure
โ โโโ production_logs.py # Multi-source log fetching (S3, K8s, CloudWatch)
โ โโโ deployment_history.py # Git-based deployment correlation
โ โโโ pattern_analysis.py # Error pattern detection & severity classification
โโโ utils/ # Shared utilities
โ โโโ llm_providers.py # Multi-provider LLM router with fallback
โ โโโ llm.py # Backward-compatible LLM wrapper
โโโ tools/ # Evidence collection utilities
โ โโโ log_tools.py # Log error analysis
โ โโโ env_tools.py # Environment validation
โ โโโ dep_tools.py # Dependency checking
โโโ diffs/ # Domain-specific fix templates
โโโ memory.py # File-based memory (fallback)
โโโ memory_redis.py # Redis-based memory with user isolation
โโโ tests/ # Comprehensive test suite (45+ tests)
โ โโโ test_pattern_analysis.py
โ โโโ test_production_logs.py
โ โโโ test_remediation.py
โ โโโ test_llm_providers.py
โโโ cli.py # Command-line interface
๐ Safety & Design Principles
- Dry-Run Only: Never automatically applies changes to your code
- Evidence-Based: All suggestions backed by concrete evidence
- Confidence Scoring: Transparent about certainty levels (0.0 - 1.0)
- Privacy-Focused: Prefers local LLM (Ollama) with automatic fallback to cloud
- User Isolation: Redis memory uses SHA-256 project hashing for complete data separation
- Auto-Expiring Data: Incidents automatically expire after configurable TTL (default 30 days)
- High Availability: Multi-provider LLM system with automatic failover
- Modular Design: Easy to extend with new agents, providers, or context sources
- Production-Ready: Comprehensive test coverage, error handling, and graceful degradation
๐ ๏ธ Development
Running from Source
# Install in development mode
pip install -e .
# Run the CLI
opspilot analyze
Requirements
- Python 3.8+
- At least one LLM provider (see Quick Start)
- Optional: Redis for production incident memory
Running Tests
# Install test dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run with coverage
pytest --cov=opspilot tests/
# Run specific test file
pytest tests/test_llm_providers.py
๐บ๏ธ Roadmap
- Multi-provider LLM support with automatic fallback
- Comprehensive test coverage (45+ tests)
- Redis-based memory with user isolation
- Production log fetching (S3, K8s, CloudWatch)
- Deployment correlation analysis
- Severity classification (P0/P1/P2/P3)
- Plugin system for custom agents
- Web API for remote usage
- More domain-specific fix templates (PostgreSQL, MongoDB, etc.)
- Real-time metrics dashboard
- Slack/PagerDuty integration for incident alerts
๐ License
MIT License - see LICENSE for details
๐ค Contributing
Contributions are welcome! This project is under active development. Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For major changes, please open an issue first to discuss your ideas.
๐ง Contact
For questions or feedback, please open an issue on GitHub.
Built with โค๏ธ using agentic AI principles
๐ฆ PyPI
This package is available on PyPI: opspilot-ai
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opspilot_ai-0.1.1.tar.gz.
File metadata
- Download URL: opspilot_ai-0.1.1.tar.gz
- Upload date:
- Size: 51.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc2d694830363e8e86475e42edf781f29bf22f045fc3a5a5c0e9954ee9e4432
|
|
| MD5 |
e6cc6697b2354d1661bff7abb8dd02f1
|
|
| BLAKE2b-256 |
670dbb72dd66be20b4302a2e08bb2f9b45fd5704aca71268908a6885f6fdf008
|
File details
Details for the file opspilot_ai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: opspilot_ai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 38.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0e34be388ff8effb0d1d5b89ec13b49fffd70108b88fa1ceda0e56641a9aa65
|
|
| MD5 |
0fbc79a487a1393cdb29f8e397aa4ec3
|
|
| BLAKE2b-256 |
8ddaa18590f7ca1040f82acda6598826d65babdda80baebe63ca2e333376f61b
|