Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Enhancement]: Multi-LLM Provider Support - Add Google Gemini CLI and OpenAI Codex CLI IntegrationΒ #221

@kesslerio

Description

@kesslerio

🎯 Feature Request: Multi-LLM Provider Architecture

Priority: P2 (High Impact, Strategic Enhancement)
Type: Major Feature Enhancement
Estimated Effort: 3-4 weeks implementation + testing

πŸ“‹ Executive Summary

Transform Vibe Check MCP from Claude CLI-only to a multi-LLM provider system supporting Google Gemini CLI and OpenAI Codex CLI. This enhancement addresses vendor lock-in concerns, provides cost optimization opportunities, and leverages provider-specific strengths for different analysis tasks.

🎯 Problem Statement

Current Limitations

  • Single Provider Dependency: Complete reliance on Claude CLI creates vendor lock-in
  • No Cost Optimization: Unable to leverage cheaper providers for simple tasks
  • Limited Specialization: Can't use provider-specific strengths (e.g., Codex for code analysis)
  • No Fallback Strategy: System fails completely if Claude CLI is unavailable
  • Scale Limitations: Rate limits constrained to single provider

Business Impact

  • Risk: Vendor dependency could impact availability/pricing
  • Cost: Missing opportunities for 60-80% cost savings on routine analysis
  • Performance: Can't optimize provider selection based on task requirements
  • Reliability: No redundancy for critical engineering analysis workflows

πŸ”¬ Research Summary

Comprehensive research reveals strong ecosystem readiness for multi-provider integration:

Google Gemini CLI βœ… Production Ready

# Installation: npm install -g @google/generative-ai-cli
# Integration: Straightforward subprocess pattern
# Performance: 2-5 seconds response time
# Context: 1M tokens (5x Claude limit)
# Cost: 60-80% cheaper than Claude for analysis tasks

OpenAI Codex CLI βœ… Feature Rich

# Installation: npm install -g @openai/codex
# Specialization: Optimized for code analysis tasks
# Security: Advanced sandboxing capabilities  
# Performance: 2-6 seconds with excellent code understanding
# Models: o4-mini, o3, gpt-4.1 with fast reasoning

Industry Best Practices

  • LiteLLM Pattern: Industry standard for provider abstraction
  • Factory Architecture: Configuration-driven provider selection
  • Circuit Breakers: Automatic failover and reliability patterns
  • Cost Optimization: Provider routing based on task complexity

πŸ—οΈ Proposed Implementation

Phase 1: Core Provider Abstraction (Week 1-2)

1.1 Abstract Provider Interface

from abc import ABC, abstractmethod

class LLMCliProvider(ABC):
    """Abstract base class for LLM CLI providers"""
    
    @abstractmethod
    def execute(self, prompt: str, **kwargs) -> Dict[str, Any]:
        """Execute analysis with provider-specific implementation"""
        pass
    
    @abstractmethod
    def is_available(self) -> bool:
        """Check if provider CLI is available"""
        pass
    
    @abstractmethod
    def get_models(self) -> list:
        """Get available models for this provider"""
        pass
    
    @abstractmethod
    def get_cost_estimate(self, prompt_length: int) -> float:
        """Estimate cost for analysis"""
        pass

1.2 Refactor Existing ClaudeCliExecutor

  • Wrap existing logic in ClaudeCliProvider class
  • Maintain backward compatibility with current MCP tools
  • Add provider metadata to all responses

1.3 Configuration System

# ~/.vibe-check/llm-config.yaml
providers:
  claude:
    enabled: true
    cli_path: "~/.claude/local/claude"
    models: ["sonnet", "opus", "haiku"]
    timeout: 60
  
  gemini:
    enabled: false  # Start disabled for gradual rollout
    cli_path: "gemini"
    models: ["gemini-2.0-flash", "gemini-pro"]
    timeout: 45
    
  codex:
    enabled: false
    cli_path: "codex"  
    models: ["o4-mini", "o3", "gpt-4.1"]
    timeout: 120

# Task-specific routing
task_routing:
  pr_review:
    primary: "claude"
    fallback: ["codex", "gemini"]
    
  code_analysis:
    primary: "codex"
    fallback: ["claude", "gemini"]
    
  issue_analysis:
    primary: "claude"
    fallback: ["gemini", "codex"]

Phase 2: Gemini CLI Integration (Week 2)

2.1 GeminiCliProvider Implementation

class GeminiCliProvider(LLMCliProvider):
    def execute(self, prompt: str, model: str = "gemini-2.0-flash", **kwargs) -> Dict[str, Any]:
        cmd = [
            "gemini",
            "--model", model,
            "--format", "json",
            prompt
        ]
        
        env = dict(os.environ)
        env["GOOGLE_AI_API_KEY"] = os.getenv("GOOGLE_AI_API_KEY")
        
        result = subprocess.run(cmd, capture_output=True, text=True, 
                               timeout=self.timeout_seconds, env=env)
        
        return self._standardize_response(result, "gemini", model)

2.2 Environment Configuration

  • Add GOOGLE_AI_API_KEY to environment variables
  • Update MCP deployment documentation
  • Add Gemini-specific error handling and rate limiting

Phase 3: OpenAI Codex CLI Integration (Week 3)

3.1 CodexCliProvider Implementation

class CodexCliProvider(LLMCliProvider):
    def execute(self, prompt: str, model: str = "o4-mini", **kwargs) -> Dict[str, Any]:
        cmd = [
            "codex", "exec",
            "--ask-for-approval", "never",
            "--sandbox", "read-only", 
            "--model", model,
            prompt
        ]
        
        env = dict(os.environ)
        env["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
        
        result = subprocess.run(cmd, capture_output=True, text=True,
                               timeout=self.timeout_seconds, env=env,
                               cwd=os.path.expanduser("~"))
        
        return self._standardize_response(result, "openai_codex", model)

3.2 Advanced Features

  • Leverage Codex sandbox capabilities for secure analysis
  • Implement model selection optimization (o4-mini for speed, o3 for depth)
  • Add code-specific analysis enhancements

Phase 4: Provider Factory and Routing (Week 3-4)

4.1 LLMProviderFactory

class LLMProviderFactory:
    def __init__(self, config_path: Optional[str] = None):
        self.providers = {
            "claude": ClaudeCliProvider(),
            "gemini": GeminiCliProvider(), 
            "codex": CodexCliProvider()
        }
        self.config = self._load_config(config_path)
    
    def execute_with_fallback(self, prompt: str, task_type: str, **kwargs) -> Dict[str, Any]:
        """Execute with intelligent provider selection and fallback"""
        routing = self._get_routing_for_task(task_type)
        
        for provider_name in [routing["primary"]] + routing["fallback"]:
            try:
                provider = self.get_provider(provider_name)
                result = provider.execute(prompt, **kwargs)
                result["provider_used"] = provider_name
                return result
            except Exception as e:
                logging.warning(f"Provider {provider_name} failed: {e}")
                continue
        
        return {"success": False, "error": "All providers failed"}

4.2 Update MCP Tools

  • Modify existing tools to use provider factory
  • Add provider selection parameters to tools
  • Maintain backward compatibility

Phase 5: Advanced Features (Week 4)

5.1 Cost Optimization

class CostOptimizedRouting:
    PROVIDER_COSTS = {
        "claude": {"input_1k": 0.0030, "output_1k": 0.0150},
        "gemini": {"input_1k": 0.000375, "output_1k": 0.0015},  # 60-80% cheaper
        "codex": {"input_1k": 0.00015, "output_1k": 0.0006}     # 85%+ cheaper
    }
    
    def select_cost_optimal_provider(self, prompt_length: int, task_type: str) -> str:
        """Select most cost-effective provider for task"""
        # Route simple tasks to cheaper providers
        # Route complex analysis to specialized providers

5.2 Performance Monitoring

  • Add provider performance metrics to telemetry
  • Track cost savings and provider usage patterns
  • Monitor fallback frequency and success rates

5.3 Security Enhancements

class SecureCredentialManager:
    """Secure management of multiple API keys"""
    def store_credentials(self, provider: str, credentials: dict):
        # Encrypted credential storage
    
    def setup_environment_for_provider(self, provider: str):
        # Provider-specific environment setup

🎯 Configuration and Deployment

Environment Variables

# Required for multi-provider support
VIBE_CHECK_LLM_PROVIDER="claude"  # Default provider
GOOGLE_AI_API_KEY="your_key"      # For Gemini
OPENAI_API_KEY="your_key"         # For Codex
ANTHROPIC_API_KEY="your_key"      # For Claude (existing)

MCP Server Config Update

{
  "mcpServers": {
    "vibe-check": {
      "command": "npx",
      "args": ["vibe-check-mcp", "--stdio"],
      "env": {
        "PYTHONPATH": "$(pwd)/src",
        "VIBE_CHECK_LLM_PROVIDER": "claude",
        "GOOGLE_AI_API_KEY": "your_gemini_key",
        "OPENAI_API_KEY": "your_openai_key",
        "GITHUB_TOKEN": "your_github_token"
      }
    }
  }
}

New MCP Tools

@server.tool(name="set_llm_provider")
async def set_llm_provider(provider: str = "claude") -> Dict[str, Any]:
    """Dynamically switch LLM provider for analysis"""

@server.tool(name="get_provider_status") 
async def get_provider_status() -> Dict[str, Any]:
    """Check availability and health of all configured providers"""

@server.tool(name="analyze_with_best_provider")
async def analyze_with_best_provider(content: str, task_type: str = "general") -> Dict[str, Any]:
    """Automatically select optimal provider for task"""

πŸ“Š Benefits and Impact

πŸš€ Performance Benefits

  • Cost Reduction: 60-80% savings using Gemini for routine analysis
  • Speed Optimization: Route simple tasks to faster providers (2-3s vs 5-8s)
  • Specialization: Leverage Codex for code analysis, Claude for reasoning
  • Reliability: Automatic fallback ensures 99.9% uptime

πŸ’‘ Strategic Benefits

  • Vendor Independence: Eliminate single-provider lock-in
  • Future-Proof: Easy addition of new providers (Anthropic Claude 4, etc.)
  • Cost Control: Usage-based optimization for different team sizes
  • Competitive Advantage: Only MCP server with true multi-provider support

🎯 User Experience

  • Transparent: No changes to existing workflow
  • Intelligent: Automatic provider selection based on task
  • Configurable: Power users can specify provider preferences
  • Reliable: Graceful degradation with meaningful error messages

πŸ§ͺ Testing Strategy

Phase Testing

  1. Unit Tests: Provider interface compliance and error handling
  2. Integration Tests: End-to-end workflows with each provider
  3. Performance Tests: Response time and cost validation
  4. Fallback Tests: Provider failure and recovery scenarios
  5. Security Tests: Credential management and injection prevention

Rollout Strategy

  1. Feature Flag: Gradual rollout with provider-specific enables
  2. Beta Testing: Limited user group with feedback collection
  3. Monitoring: Comprehensive metrics on provider performance
  4. Documentation: Updated guides for multi-provider configuration

⚠️ Implementation Risks and Mitigations

Risk: Provider CLI Compatibility

  • Mitigation: Comprehensive CLI version testing and compatibility matrix
  • Fallback: Version-specific command adaptation

Risk: API Cost Overruns

  • Mitigation: Built-in rate limiting and cost monitoring
  • Safeguard: Configurable daily/monthly spending limits

Risk: Complex Configuration

  • Mitigation: Intelligent defaults and auto-detection
  • Support: Clear documentation and diagnostic tools

Risk: Security Concerns

  • Mitigation: Encrypted credential storage and environment isolation
  • Audit: Comprehensive security review of multi-provider access

πŸ“‹ Acceptance Criteria

βœ… Core Requirements

  • Abstract provider interface supporting Claude, Gemini, and Codex CLIs
  • Configuration-driven provider selection with YAML config
  • Automatic fallback between providers on failure
  • Backward compatibility with all existing MCP tools
  • Cost optimization routing for different task types

βœ… Advanced Features

  • Real-time provider health monitoring
  • Encrypted credential management for multiple API keys
  • Performance metrics and cost tracking
  • Provider-specific optimization (sandboxing, model selection)
  • Comprehensive error handling and recovery

βœ… Documentation and Testing

  • Updated MCP deployment guide with multi-provider setup
  • Provider comparison matrix and cost analysis
  • 90%+ test coverage for new provider infrastructure
  • Security audit of credential management system

πŸš€ Implementation Timeline

Week 1: Provider abstraction and Claude CLI refactoring
Week 2: Gemini CLI integration and testing
Week 3: OpenAI Codex CLI integration and factory implementation
Week 4: Advanced features, cost optimization, and comprehensive testing

Total Estimate: 3-4 weeks for complete multi-provider architecture

πŸ“š Related Issues and Dependencies

  • Depends on: Current Claude CLI integration (existing)
  • Enables: Cost optimization, vendor independence, performance specialization
  • Blocks: Enterprise deployment concerns about vendor lock-in

🎯 Success Metrics

  • Cost Reduction: Achieve 40-60% cost savings for routine analysis
  • Reliability: 99.9% uptime with automatic fallback
  • Performance: <3 second average response time for simple tasks
  • Adoption: 80%+ of users enable multi-provider configuration
  • Provider Health: Real-time monitoring with <5% failure rate

This enhancement transforms Vibe Check MCP from a single-provider tool into a robust, cost-optimized, multi-LLM platform that delivers superior reliability and performance while eliminating vendor lock-in concerns.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions