A complete, production-ready model routing system for cost-optimized multi-agent orchestration.
-
Router Sidecar (
router/)- FastAPI service on port 8080
- Routes prompts to optimal models based on constraints
- Configurable via YAML
- Docker-ready
-
Model Factory (
orchestrator/factory.py)- Single-line LLM calls:
ModelFactory.call_optimized_model() - Lazy client initialization
- Automatic provider abstraction
- Caches connections
- Single-line LLM calls:
-
Example Agents (
orchestrator/agents/)- L1 Triage Agent (cost-optimized, $0.50/1M cap)
- L2 Analysis Agent (accuracy-optimized, $5.00/1M cap)
- Ready to customize for your use cases
-
ITSM Demo (
orchestrator/examples/itsm_demo.py)- Multi-tier incident handling
- Automatic escalation
- Cost tracking
- Real ROI calculations
✅ Cost Optimization: 73% savings vs always using expensive models
✅ Sidecar Pattern: One router per orchestration plane
✅ Lazy Loading: Clients created only when needed
✅ Provider Agnostic: OpenAI, Anthropic, easy to extend
✅ Configuration-Driven: All model specs in YAML
✅ Docker-Ready: Full docker-compose setup
✅ Production-Tested: Follows enterprise patterns
# 1. Navigate to project
cd model-router-sidecar
# 2. Configure
cp .env.example .env
# Edit .env with your API keys
# 3. Start
docker-compose up -d
# 4. Test
docker-compose exec orchestrator python examples/itsm_demo.pymodel-router-sidecar/
├── README.md # Main documentation
├── QUICKSTART.md # Setup guide
├── ARCHITECTURE.md # System design & diagrams
├── docker-compose.yml # Docker orchestration
├── .env.example # Environment template
├── test_local.py # Standalone test (no Docker)
│
├── router/ # Model router sidecar
│ ├── server.py # FastAPI service
│ ├── engine.py # Routing logic
│ ├── models.yaml # Model configurations
│ ├── requirements.txt
│ └── Dockerfile
│
└── orchestrator/ # Agent orchestration plane
├── factory.py # ModelFactory implementation
├── requirements.txt
├── Dockerfile
│
├── agents/ # Example agents
│ ├── triage.py # L1 triage agent
│ └── analysis.py # L2 analysis agent
│
└── examples/ # Demos
└── itsm_demo.py # ITSM automation demo
Without routing (always claude-sonnet-4):
- 10,000 incidents/month × $3.00/1M = $30,000/month
- Annual cost: $360,000
With routing (intelligent tier selection):
- 7,700 L1 incidents × $0.15/1M = $1,155
- 2,300 L2 incidents × $3.00/1M = $6,900
- Monthly cost: $8,055
- Annual cost: $96,660
Savings: $263,340/year (73%)
For ITSM automation proposals:
- Demo the working system
- Show real cost comparisons
- Customize agents for their workflow
- Deploy as sidecar in their infrastructure
Edit router/models.yaml:
models:
your-gpt-4o-deployment:
provider: azure-openai
endpoint: ${AZURE_OPENAI_ENDPOINT}/openai/deployments/your-deployment
api_version: "2024-08-01-preview"
client_hint: openai
cost_per_1m: 2.50
avg_latency_ms: 1800
accuracy_scores:
classification: 0.92
extraction: 0.91
reasoning: 0.88
code: 0.90from factory import ModelFactory
class YourAgent:
def __init__(self):
self.constraints = {
'max_cost_per_1m_tokens': 1.00, # Your budget
'max_latency_ms': 3000, # Your SLA
'min_accuracy_score': 0.85 # Your quality bar
}
def process(self, task):
return ModelFactory.call_optimized_model(
prompt=f"Do something with: {task}",
constraints=self.constraints,
optimize_for='cost' # or 'speed' or 'accuracy'
)- ✅ Test locally:
python test_local.py - ✅ Start Docker:
docker-compose up -d - ✅ Run demo:
docker-compose exec orchestrator python examples/itsm_demo.py - Customize agents for your use cases
- Add your deployed models to
router/models.yaml
- Update models.yaml with your Azure deployments
- Create agents for specific DSI client workflows
- Add logging/metrics for cost tracking
- Deploy as sidecar in client infrastructure
- Document ROI for proposals
Could be productized as:
- Standout.PRO: Optimize AI costs for athlete analytics
- Pattern Match: Route security analysis tasks efficiently
- Any GenAI product: Automatic cost optimization layer
- Agent calls
ModelFactory.call_optimized_model() - Factory sends prompt + constraints to router sidecar
- Router classifies task type (classification/reasoning/code/etc)
- Router filters models by constraints
- Router selects optimal model based on optimize_for
- Returns model name, provider, endpoint, credentials
- Factory lazy-loads client for that provider
- Factory executes call and returns result
- Isolation: Each plane has independent routing
- Performance: Sub-ms local HTTP calls
- Resilience: No single point of failure
- Scaling: Routes scale with workload
Factory handles:
- OpenAI format (Azure OpenAI, OpenAI)
- Anthropic format (Claude)
- Easy to add: Cohere, Mistral, local models
| File | Purpose |
|---|---|
README.md |
Main docs, architecture overview |
QUICKSTART.md |
Setup guide, basic usage |
ARCHITECTURE.md |
System design, diagrams, patterns |
router/server.py |
FastAPI routing service |
router/engine.py |
Core routing logic |
router/models.yaml |
Model configurations |
orchestrator/factory.py |
ModelFactory implementation |
orchestrator/agents/triage.py |
L1 cost-optimized agent |
orchestrator/agents/analysis.py |
L2 accuracy-optimized agent |
orchestrator/examples/itsm_demo.py |
Full workflow demo |
test_local.py |
Standalone test script |
docker-compose.yml |
Docker orchestration |
To modify:
- Add models: Edit
router/models.yaml, restart router - Change constraints: Edit agent files
- New providers: Update
factory.pyandengine.py - Custom agents: Follow pattern in
agents/triage.py
MIT - Use freely in commercial projects.
Built for: Mark Roxberry, Drive Technology LLC / DSI
Use case: Cost-optimized multi-agent AI orchestration
ROI: 73% cost reduction on LLM operations
Status: Production-ready, fully tested