Skip to content

colin-mclaughlin/codeops-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CodeOps Agent

An intelligent DevOps agent that automatically diagnoses CI failures, proposes fixes, and validates solutions using AI-powered reasoning and tool execution.

πŸ—οΈ Architecture Overview

The CodeOps Agent follows a sophisticated multi-step pipeline to diagnose and fix CI failures:

graph TD
    A[CI Failure Detected] --> B[Context Retrieval]
    B --> C[AI Planning & Analysis]
    C --> D[Tool Execution]
    D --> E[Code Patching]
    E --> F[Test Execution]
    F --> G{Success?}
    G -->|Yes| H[Verification & Documentation]
    G -->|No| I[Critic Agent Review]
    I --> J[Refined Planning]
    J --> D
    H --> K[Slack Notification]
    
    subgraph "Data Layer"
        L[FAISS Vector Store]
        M[SQLite Database]
        N[GitHub Repository]
    end
    
    subgraph "AI Components"
        O[OpenAI GPT-4]
        P[Sentence Transformers]
        Q[LangGraph Reasoning]
    end
    
    B --> L
    C --> O
    C --> Q
    D --> N
    H --> M
Loading

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Git
  • OpenAI API Key
  • GitHub Token (optional, for repository access)

Docker Setup (Recommended)

  1. Clone the repository:

    git clone <repository-url>
    cd codeops-agent
  2. Configure environment:

    cp .env.example .env
    # Edit .env with your API keys
  3. Start the application:

    docker compose up --build
  4. Access the services:

Local Development Setup

  1. Backend Setup:

    # Create virtual environment
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
    # Install dependencies
    pip install -r requirements.txt
    pip install sentence-transformers
    
    # Run backend
    uvicorn backend.app.main:app --reload --port 8000
  2. Frontend Setup:

    cd frontend
    pnpm install
    pnpm run dev

πŸ”§ Configuration

Environment Variables

Variable Description Required Default
OPENAI_API_KEY OpenAI API key for AI functionality Yes -
GITHUB_TOKEN GitHub token for repository access No -
SLACK_WEBHOOK_URL Slack webhook for notifications No -
AGENT_DRY_RUN Run in dry-run mode (no actual changes) No true
DB_URL Database connection string No sqlite+aiosqlite:///./data/codeops.db

Service Configuration

The Docker setup includes:

  • Backend (FastAPI): Port 8000, Python 3.11-slim
  • Frontend (React): Port 5173, Node 22 with Vite
  • FAISS Store: Vector database for semantic search
  • Demo Repository: Mounted for testing purposes

πŸ“Š Demo Workflow

1. Failure Detection

The agent monitors CI pipelines and detects failures through webhooks or manual triggers.

2. Context Retrieval

  • Analyzes failure logs and error messages
  • Retrieves relevant code context using FAISS vector search
  • Gathers repository metadata and recent changes

3. AI Planning

  • Uses OpenAI GPT-4 to analyze the failure
  • Generates a step-by-step fix plan
  • Identifies required tools and resources

4. Tool Execution

  • Executes git operations (checkout, branch, commit)
  • Runs tests to validate fixes
  • Applies code patches and modifications

5. Verification

  • Re-runs tests to confirm fixes
  • Validates solution completeness
  • Documents changes and rationale

6. Notification

  • Sends results to Slack (if configured)
  • Updates run logs and metrics
  • Provides detailed trace information

πŸ› οΈ API Endpoints

Core Endpoints

Endpoint Method Description
/healthz GET Health check
/metrics GET System metrics
/agent/run/{run_id} POST Trigger agent pipeline
/runs GET List all runs
/runs/{run_id} GET Get specific run details

Example Usage

# Trigger agent for run ID 1
curl -X POST http://localhost:8000/agent/run/1

# Get system metrics
curl http://localhost:8000/metrics

# List all runs
curl http://localhost:8000/runs

πŸ“ˆ Monitoring & Metrics

The dashboard provides real-time insights into:

  • Success Rate: Percentage of successful fixes
  • Average Latency: Time to complete fixes
  • Confidence Trends: AI confidence scores over time
  • Run Traces: Detailed execution logs

Example Metrics Response

{
  "total_runs": 45,
  "successful_runs": 38,
  "success_rate": 0.844,
  "average_latency": 2.3,
  "confidence_trend": [0.85, 0.87, 0.89, 0.91]
}

πŸ§ͺ Testing

Run Tests

# Backend tests
python -m pytest test_*.py

# Integration tests
python test_endpoints.py
python test_github_integration.py
python test_slack_integration.py

Demo Repository

The included demo-repo contains a simple calculator with intentional bugs for testing:

# Run demo tests
cd demo-repo
python test_calculator.py

πŸ” Troubleshooting

Common Issues

  1. Docker Build Fails:

    • Ensure Docker is running
    • Check available disk space
    • Verify network connectivity
  2. API Connection Issues:

    • Check if backend is running on port 8000
    • Verify CORS settings in backend/app/main.py
    • Check firewall settings
  3. FAISS Index Issues:

    • Ensure faiss_index.bin and faiss_index_texts.pkl exist
    • Check file permissions
    • Rebuild index if corrupted
  4. Environment Variables:

    • Verify .env file exists and is properly formatted
    • Check API key validity
    • Ensure no trailing spaces in values

Logs

# View Docker logs
docker compose logs -f backend
docker compose logs -f frontend

# View specific service logs
docker compose logs backend

πŸš€ Production Deployment

Docker Registry

# Build and tag images
docker build -f Dockerfile.backend -t codeops-agent/backend:latest .
docker build -f Dockerfile.frontend -t codeops-agent/frontend:latest .

# Push to registry
docker push codeops-agent/backend:latest
docker push codeops-agent/frontend:latest

Environment Considerations

  • Use production-grade database (PostgreSQL)
  • Configure proper secrets management
  • Set up monitoring and alerting
  • Enable HTTPS with proper certificates
  • Configure backup strategies for FAISS index

πŸ“š Additional Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Ready to automate your DevOps workflow? Start with docker compose up and watch the magic happen! πŸŽ‰

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors