byterover-cli
byterover-cli copied to clipboard
Add Cloud Providers (AWS/Azure) to LLM Config
Architecture for Expanding Cipher’s LLM Provider Compatibility: AWS Bedrock & Azure OpenAI Service
1. Title and Overview
Expanding Cipher’s LLM Provider Compatibility: AWS Bedrock & Azure OpenAI Service
This architecture defines the requirements and design for extending Cipher’s LLM integration to fully support AWS Bedrock and Azure OpenAI Service, ensuring all LLM usage points in the system are compatible and configurable with these major cloud providers.
2. Guiding Principles / Design Philosophy
- Modularity: Each LLM provider is encapsulated in its own service class implementing a common interface.
- Extensibility: Adding new providers in the future should require minimal changes.
- Configurability: All provider-specific options are exposed via config/environment and validated.
- Consistency: All LLM usage points (API, CLI, session, tools, reasoning) must work identically regardless of provider.
- Security: Credentials and secrets are handled securely, with clear error reporting for misconfiguration.
- Testability: Provider integrations are covered by unit and integration tests.
3. High-Level Architecture Diagram (Conceptual)
graph TD
subgraph Cipher Core
A[Agent/Session Manager] -->|LLMConfig| B[LLM Service Factory]
B -->|provider: openai| C1[OpenAIService]
B -->|provider: anthropic| C2[AnthropicService]
B -->|provider: openrouter| C3[OpenRouterService]
B -->|provider: ollama| C4[OllamaService]
B -->|provider: aws| C5[AwsService]
B -->|provider: azure| C6[AzureService]
end
C5 -.->|AWS SDK| D1[AWS Bedrock]
C6 -.->|Azure SDK| D2[Azure OpenAI]
C1 & C2 & C3 & C4 & C5 & C6 --> E[ILLMService Interface]
A -->|uses| F[ContextManager/Formatter]
A -->|uses| G[ToolManager]
Explanation:
- The Agent/Session Manager uses the LLM Service Factory to instantiate the correct provider service based on configuration.
- Each provider service implements the
ILLMServiceinterface. - All LLM usage points interact with the service via this interface, ensuring consistency.
4. Detailed Component Breakdown
a. LLM Service Classes
- Location:
src/core/brain/llm/services/ - Role: Implement provider-specific logic for LLM interaction.
- Key Classes:
AwsService,AzureService - Responsibilities:
- Handle authentication, API calls, and error handling for their respective cloud provider.
- Implement all methods from
ILLMService. - Support tool/function calling if the provider allows.
- Interfaces: Implements
ILLMService(generate,directGenerate,getAllTools,getConfig). - Dependencies: AWS SDK (
@aws-sdk/client-bedrock-runtime), Azure SDK (@azure/openai).
b. LLM Service Factory
- Location:
src/core/brain/llm/services/factory.ts - Role: Instantiates the correct LLM service based on config.
- Responsibilities:
- Validate config and credentials.
- Return an instance of the appropriate service class.
c. LLM Configuration Schema
- Location:
src/core/brain/llm/config.ts - Role: Validates and documents all provider-specific config options.
- Responsibilities:
- Ensure all required fields for AWS and Azure are present.
- Provide clear error messages for misconfiguration.
d. Message Formatters
- Location:
src/core/brain/llm/messages/formatters/ - Role: Format messages for each provider’s API.
- Responsibilities:
- Implement provider-specific message structure if needed (e.g., Bedrock, Azure).
- Register new formatters in the formatter registry.
e. LLM Usage Points
- Locations:
src/core/utils/service-initializer.ts(agent init)src/core/session/coversation-session.ts(session)src/core/brain/reasoning/content-detector.ts(reasoning)src/core/brain/tools/definitions/knowledge_graph/intelligent-processor.ts(tools)
- Role: Use the LLM service via the
ILLMServiceinterface. - Responsibilities:
- Ensure all usage points are compatible with new providers.
f. API and CLI
- API Location:
src/app/api/routes/llm.ts - CLI Location:
src/app/index.ts - Role: Expose provider selection and configuration to users.
- Responsibilities:
- Update provider listing and selection logic to include AWS and Azure.
- Validate and pass through all required config fields.
g. Validation Middleware
- Location:
src/app/api/middleware/validation.ts - Role: Validate incoming API requests for LLM config.
- Responsibilities:
- Accept AWS and Azure as valid providers.
- Validate all required fields.
5. Key Interactions and Data Flow (Walkthroughs)
Example: User selects AWS Bedrock as provider
- User sets provider to
awsin config or via API/CLI, providing all required fields. - Agent/session initialization calls LLM Service Factory, which validates config and instantiates
AwsService. AwsServiceuses AWS SDK to interact with Bedrock, handling authentication and message formatting.- All LLM usage points (API, CLI, tools, reasoning) interact with
AwsServiceviaILLMService. - Responses and errors are handled and logged consistently.
Example: Tool Calling with Azure
- User selects
azureas provider and configures endpoint, deployment, etc. AzureServiceis instantiated and uses Azure SDK for completions.- If tool/function calling is supported,
AzureServiceimplements the same tool integration logic as OpenAI. - Results are returned to the user via the same interface.
6. Cross-Cutting Concerns / Non-Functional Requirements
- Error Handling:
- All provider errors are logged with context.
- User-facing errors are clear and actionable.
- Configuration Management:
- All secrets/keys are loaded from environment or config files.
- Validation ensures no missing/invalid fields.
- Scalability:
- Provider services are stateless and can be instantiated per session/agent.
- Security:
- No secrets are logged.
- Use environment variables for credentials.
- Observability:
- Provider, model, and error details are logged at appropriate levels.
- Testing Strategy:
- Unit and integration tests for each provider service.
- End-to-end tests for all LLM usage points with each provider.
7. Implementation Guidelines / Best Practices
- Follow the existing
ILLMServiceinterface for all providers. - Use the factory pattern for instantiation.
- Register new formatters if provider message structure differs.
- Update all validation and provider listing logic to include new providers.
- Write/expand tests for all new code paths.
- Reference and mimic patterns from existing provider integrations (OpenAI, Anthropic).
8. Impacted Files / Modules Summary
src/core/brain/llm/services/aws.ts(expand/complete)src/core/brain/llm/services/azure.ts(expand/complete)src/core/brain/llm/services/factory.ts(ensure correct instantiation)src/core/brain/llm/config.ts(validate all required fields)src/core/brain/llm/messages/formatters/(add/update formatters if needed)src/core/brain/llm/services/__test__/aws.test.ts(expand tests)src/core/brain/llm/services/__test__/azure.test.ts(expand tests)src/core/utils/service-initializer.ts(ensure compatibility)src/core/session/coversation-session.ts(ensure compatibility)src/core/brain/reasoning/content-detector.ts(ensure compatibility)src/core/brain/tools/definitions/knowledge_graph/intelligent-processor.ts(ensure compatibility)src/app/api/routes/llm.ts(update provider listing)src/app/api/middleware/validation.ts(update validation)src/app/index.ts(update CLI provider selection)README.mdand example configs (document usage)
9. Definition of Done / Success Criteria
- [ ] Users can select and configure AWS Bedrock and Azure OpenAI Service as LLM providers via config, API, or CLI.
- [ ] All LLM usage points (agent, session, tools, reasoning, API, CLI) work identically with AWS and Azure as with other providers.
- [ ] All required provider-specific fields are validated and errors are clear.
- [ ] Provider listing endpoints and CLI show AWS and Azure as options.
- [ ] Unit, integration, and end-to-end tests cover all new code paths.
- [ ] Documentation and examples are updated.
10. Open Questions / Future Considerations
- Should we support dynamic model discovery for AWS/Azure, or maintain a static list?
- Are there provider-specific features (e.g., streaming, tool calling) that require special handling?
- Should we support multiple providers simultaneously, or only one active at a time?
- How should we handle provider-specific rate limits and quotas?
- What is the process for adding new providers in the future (e.g., Google, Cohere)?