Skip to content

Latest commit

 

History

History
261 lines (233 loc) · 10.2 KB

ARCHITECTURE.md

File metadata and controls

261 lines (233 loc) · 10.2 KB

Architecture Overview

System Architecture

┌─────────────────────────────────────────────────────────────────────────┐
│                         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    │   │              │
         └──────────────────┘   └──────────────┘

Request Flow

1. Agent Makes Request

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'
)

2. Factory Calls Router

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"
}

3. Router Returns Decision

{
  "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..."
  }
}

4. Factory Executes Call

# 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.content

Multi-Tier ITSM Workflow

Incident 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

Cost Optimization

Without Routing

Every incident uses expensive model:

  • 10,000 incidents/month × $3.00/1M tokens = $30,000/month

With Routing

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

Key Design Patterns

1. Sidecar Pattern

  • Each orchestrator has its own router
  • No single point of failure
  • Isolated routing decisions per plane

2. Lazy Initialization

  • Clients created only when needed
  • Cached for reuse
  • Minimal memory footprint

3. Configuration as Code

  • All model specs in YAML
  • Environment-based endpoints
  • Easy to update without code changes

4. Constraint-Based Routing

  • Agents specify what they need
  • Router finds optimal match
  • Transparent decision making

5. Provider Abstraction

  • Unified interface (OpenAI, Anthropic, etc.)
  • Easy to add new providers
  • Agents don't care about provider details

Deployment Options

Development (Docker Compose)

docker-compose up -d

Production (Kubernetes)

apiVersion: 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

Serverless (Azure Container Apps)

  • Router as sidecar container
  • Scale to zero when idle
  • Pay per request

Extensibility

Add New Model

  1. Update router/models.yaml
  2. Restart router
  3. Done - agents automatically use it

Add New Agent

  1. Create class extending base pattern
  2. Define constraints
  3. Use ModelFactory.call_optimized_model()

Add New Provider

  1. Update engine.py with provider specs
  2. Update factory.py with client initialization
  3. Add credentials to environment