Understanding multi-provider routing in projects02
Different AI providers (OpenAI, Google Gemini, Anthropic Claude) have different APIs, rate limits, and capabilities. Switching between providers or handling failover requires significant code changes.
Solution: A unified bridge that abstracts provider differences and routes requests to the healthiest available provider automatically.
Maps natural language intents to capabilities using pattern matching.
Converts tool schemas between provider formats (OpenAI, Anthropic, Gemini).
Tracks health, latency, and availability of each provider.
Collects success/failure feedback to improve routing.
The Intent Mapper converts natural language task descriptions into capability requirements. It uses keyword patterns to identify what capabilities are needed.
# Example intent mapping patterns PATTERNS = { "code": ["code_generation", "coding"], "analyze": ["code_analysis", "text_analysis"], "summarize": ["text_summarization"], "translate": ["translation"], } # Input: "Write code to sort a list" # Output: ["code_generation", "coding"]
The Provider Monitor continuously tracks the health of each provider:
OpenAI: 98% success, 450ms avg
Gemini: 95% success, 380ms avg
Claude: 99% success, 520ms avg
When a request comes in, the bridge selects the best provider based on:
def select_provider(capabilities, preference=None): candidates = [] for provider in available_providers: if provider.supports(capabilities): score = provider.health_score() if preference == provider.name: score *= 1.5 # Boost preferred candidates.append((provider, score)) return max(candidates, key=lambda x: x[1])
Different providers expect different tool/function schemas. The Tool Converter handles this:
# OpenAI format {"type": "function", "function": {"name": "search", ...}} # Anthropic format {"name": "search", "input_schema": {...}} # Gemini format {"name": "search", "parameters": {...}}
After each request, feedback is collected and sent to the Learning Layer (M5):
Successful requests boost the provider's score; failures reduce it. This creates a self-improving system that learns which providers work best for which tasks.