bytebot
bytebot copied to clipboard
feat: Add multi-provider support for OpenRouter, Gemini, and enhanced provider management
Multi-Provider Support for ByteBot
Fixes #144
๐ฏ Overview
This PR implements comprehensive multi-provider support for ByteBot, allowing users to seamlessly switch between different AI providers (OpenRouter, Gemini, Anthropic, OpenAI) based on their needs, costs, and preferences.
โจ Features Added
๐๏ธ Core Architecture
-
BaseProvider Interface: Unified contract for all AI providers with methods for
send(),stream(),healthCheck(), andgetAvailableModels() - Provider Manager Service: Central service for managing provider discovery, status, and switching
- Dynamic Provider Detection: Automatic enable/disable based on API key configuration
๐ค New Provider Implementation
- OpenRouter Service: Complete implementation supporting multiple models through unified API
- OpenAI-Compatible Integration: Seamless integration with OpenRouter's API
- Model Enumeration: Support for various models (Claude, GPT, Llama, Mistral, etc.)
๐ง Enhanced Existing Providers
- Anthropic Service: Added BaseProvider interface implementation
- OpenAI Service: Enhanced with health checks and model listing
- Google Gemini Service: Improved with BaseProvider compliance
๐ API Endpoints
New REST endpoints for provider management:
-
GET /providers- List all providers with status -
GET /providers/enabled- Get only enabled providers -
GET /providers/models- Get all available models -
GET /providers/:id/models- Get provider-specific models -
POST /providers/:id/test- Test provider connectivity -
POST /providers/refresh- Refresh provider status
๐ Enhanced API Key Management
- Support for multiple provider API keys
- Secure key storage and validation
- Provider-specific key testing
- Environment variable configuration
๐งช Testing
- Unit Tests: Comprehensive test coverage for all services
- Integration Tests: End-to-end API endpoint testing
- Provider-Specific Tests: OpenRouter service validation
- Mock Testing: Proper mocking of external API calls
๐ Files Added/Modified
New Files:
packages/bytebot-agent/src/
โโโ providers/
โ โโโ base-provider.interface.ts
โ โโโ provider-manager.service.ts
โ โโโ providers.controller.ts
โ โโโ providers.module.ts
โ โโโ tests/
โโโ openrouter/
โ โโโ openrouter.service.ts
โ โโโ openrouter.constants.ts
โ โโโ openrouter.tools.ts
โ โโโ openrouter.module.ts
โ โโโ tests/
โโโ api-keys/
โ โโโ api-keys.service.ts
โ โโโ api-keys.controller.ts
โ โโโ dto/
โโโ docs/multi-provider-support.md
Modified Files:
- Enhanced existing provider services (Anthropic, OpenAI, Google)
- Updated agent processor and modules
- Extended type definitions
๐ Usage
Environment Configuration
ANTHROPIC_API_KEY=your_anthropic_key
OPENAI_API_KEY=your_openai_key
GEMINI_API_KEY=your_gemini_key
OPENROUTER_API_KEY=your_openrouter_key
API Usage Examples
# Get available providers
curl http://localhost:3000/providers
# Get all models
curl http://localhost:3000/providers/models
# Test provider connectivity
curl -X POST http://localhost:3000/providers/openrouter/test
๐ฏ Benefits
- Cost Optimization: Switch providers based on pricing
- Reliability: Graceful fallback when providers are unavailable
- Future-Proof: Easy addition of new providers
- Unified Interface: Consistent API across all providers
- Health Monitoring: Built-in provider status monitoring
๐ Backward Compatibility
- โ Fully backward compatible with existing installations
- โ No breaking changes to existing APIs
- โ Existing provider configurations continue to work
- โ Optional feature - providers work independently
๐ Testing Instructions
-
Install dependencies:
npm install -
Build project:
npm run build -
Run tests:
npm test -
Test specific providers:
npm test -- --testPathPattern="providers"
๐ Documentation
Complete documentation added in docs/multi-provider-support.md including:
- Architecture overview
- Implementation guide
- Usage examples
- Provider addition instructions
โ Issue Requirements Fulfilled
- [x] Define a base provider interface โ
- [x] Build adapters for OpenRouter and Gemini โ
- [x] Make config/UI switch to select provider โ
- [x] Add tests (unit & integration) โ
- [x] Update documentation and usage examples โ
๐ Review Notes
- All changes follow existing code patterns and conventions
- Comprehensive error handling and logging
- Production-ready with proper TypeScript types
- Follows NestJS best practices
- Maintains security standards for API key handling
Ready for review and testing! ๐
May I ask can't we use the existing LiteLLM proxy with the multi-providers you mentioned?