┌─────────────────────────────────────────────────────────────────────────┐
│ ORCHESTRATOR CONTAINER │
│ │
│ ┌─────────────────────┐ ┌─────────────────────┐ │
│ │ Triage Agent │ │ Analysis Agent │ │
│ │ (L1 Support) │ │ (L2 Support) │ │
│ │ │ │ │ │
│ │ • Constraints: │ │ • Constraints: │ │
│ │ - Cost: $0.50/1M │ │ - Cost: $5.00/1M │ │
│ │ - Latency: 2s │ │ - Latency: 5s │ │
│ │ - Accuracy: 0.80 │ │ - Accuracy: 0.90 │ │
│ └──────────┬──────────┘ └──────────┬──────────┘ │
│ │ │ │
│ └────────────────┬───────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────┐ │
│ │ ModelFactory │ │
│ │ │ │
│ │ call_optimized_model( │ │
│ │ prompt, │ │
│ │ constraints, │ │
│ │ optimize_for │ │
│ │ ) │ │
│ │ │ │
│ │ • Lazy client initialization │ │
│ │ • Client caching & reuse │ │
│ │ • Unified provider interface │ │
│ └──────────────┬────────────────────┘ │
│ │ │
└─────────────────────────────┼──────────────────────────────────────────┘
│
│ HTTP POST /route
│ {prompt, constraints, optimize_for}
▼
┌───────────────────────────────────┐
│ MODEL ROUTER SIDECAR │
│ (FastAPI Service - Port 8080) │
│ │
│ ┌─────────────────────────────┐ │
│ │ Routing Engine │ │
│ │ │ │
│ │ 1. Classify task type │ │
│ │ 2. Filter by constraints │ │
│ │ 3. Optimize selection │ │
│ │ 4. Return provider config │ │
│ └─────────────────────────────┘ │
│ │
│ Models Config (YAML): │
│ • gpt-4o-mini ($0.15/1M) │
│ • gpt-4o ($2.50/1M) │
│ • claude-sonnet-4 ($3.00/1M) │
│ • o1-preview ($15.00/1M) │
└──────────────┬────────────────────┘
│
┌────────┴────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────┐
│ Azure OpenAI │ │ Anthropic │
│ │ │ │
│ • gpt-4o-mini │ │ • Claude │
│ • gpt-4o │ │ Sonnet 4 │
│ • o1-preview │ │ │
└──────────────────┘ └──────────────┘
result = ModelFactory.call_optimized_model(
prompt="Classify incident severity",
constraints={
'max_cost_per_1m_tokens': 0.50,
'max_latency_ms': 2000,
'min_accuracy_score': 0.80
},
optimize_for='cost'
)POST http://model-router:8080/route
{
"prompt": "Classify incident severity",
"constraints": {
"max_cost_per_1m_tokens": 0.50,
"max_latency_ms": 2000,
"min_accuracy_score": 0.80
},
"optimize_for": "cost"
}{
"model": "gpt-4o-mini",
"provider": "azure-openai",
"endpoint": "https://your-instance.openai.azure.com/openai/deployments/gpt-4o-mini",
"api_version": "2024-08-01-preview",
"client_hint": "openai",
"reasoning": {
"task_type": "classification",
"cost_per_1m": 0.15,
"estimated_latency_ms": 1200,
"accuracy_score": 0.87,
"why": "gpt-4o-mini selected for classification task. Cost: $0.15/1M tokens..."
}
}# Get or create cached client
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_KEY"),
api_version="2024-08-01-preview",
azure_endpoint="https://your-instance.openai.azure.com"
)
# Make call
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.contentIncident Received
│
▼
┌──────────────────┐
│ L1 Triage │ Cost-optimized (gpt-4o-mini)
│ Agent │
│ │ • Classify severity
│ Constraints: │ • Categorize type
│ - $0.50/1M │ • Suggest quick fix
│ - 2000ms │ • Check escalation
│ - 0.80 accuracy │
└────────┬─────────┘
│
├─────────────────┐
│ │
▼ ▼
Resolved Critical/Complex
(77% of cases) │
│ │
│ ▼
│ ┌──────────────────┐
│ │ L2 Analysis │ Accuracy-optimized
│ │ Agent │ (claude-sonnet-4 or gpt-4o)
│ │ │
│ │ Constraints: │ • Root cause analysis
│ │ - $5.00/1M │ • Impact assessment
│ │ - 5000ms │ • Remediation plan
│ │ - 0.90 accuracy │ • Runbook generation
│ └──────────────────┘
│
▼
Complete
Every incident uses expensive model:
- 10,000 incidents/month × $3.00/1M tokens = $30,000/month
Intelligent tier-based routing:
- 7,700 incidents (L1) × $0.15/1M tokens = $1,155
- 2,300 incidents (L2) × $3.00/1M tokens = $6,900
- Total: $8,055/month
- Savings: $21,945/month (73%)
- Annual savings: $263,340
- Each orchestrator has its own router
- No single point of failure
- Isolated routing decisions per plane
- Clients created only when needed
- Cached for reuse
- Minimal memory footprint
- All model specs in YAML
- Environment-based endpoints
- Easy to update without code changes
- Agents specify what they need
- Router finds optimal match
- Transparent decision making
- Unified interface (OpenAI, Anthropic, etc.)
- Easy to add new providers
- Agents don't care about provider details
docker-compose up -dapiVersion: apps/v1
kind: Deployment
metadata:
name: incident-orchestrator
spec:
template:
spec:
containers:
- name: orchestrator
image: orchestrator:latest
- name: router
image: model-router:latest
ports:
- containerPort: 8080- Router as sidecar container
- Scale to zero when idle
- Pay per request
- Update
router/models.yaml - Restart router
- Done - agents automatically use it
- Create class extending base pattern
- Define constraints
- Use
ModelFactory.call_optimized_model()
- Update
engine.pywith provider specs - Update
factory.pywith client initialization - Add credentials to environment