Unified Routing for Terraphim
This directory contains the unified routing system for Terraphim AI, providing capability-based routing for both LLM providers and spawned agents.
Crates
terraphim_router
Capability-based routing engine that routes tasks to the best provider based on:
- Keyword extraction from prompts
- Provider capabilities
- Routing strategies (cost, latency, capability match)
terraphim_spawner
Agent process spawner with:
- CLI validation
- API key checking
- Health monitoring (30s heartbeat)
- Output capture with @mention detection
- Auto-restart on failure
terraphim_types (updated)
Added capability types:
Capabilityenum (DeepThinking, CodeGeneration, etc.)Providerstruct (unified LLM/Agent)ProviderTypeenum (Llm vs Agent)CostLevelandLatencyenums
Quick Start
use ;
use ;
use PathBuf;
// Create router
let mut router = new;
// Register LLM provider
router.add_provider;
// Register agent provider
router.add_provider;
// Route a task
let decision = router.route?;
println!;
Provider Configuration
Providers can be configured via markdown files with YAML frontmatter:
id: "claude-opus"
name: "Claude Opus"
type: "llm"
model_id: "claude-3-opus-20240229"
api_endpoint: "https://api.anthropic.com/v1"
capabilities:
- - - -
Anthropic's most capable model.
Routing Strategies
- CostOptimized: Select cheapest provider
- LatencyOptimized: Select fastest provider
- CapabilityFirst: Select provider with most capabilities
- RoundRobin: Distribute load evenly
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Prompt │────▶│ KeywordRouter │────▶│ Capabilities │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ LLM Provider │◀────│ RoutingEngine │◀────│ ProviderRegistry│
│ (API call) │ │ (Strategy) │ │ (Filtered) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐
│ Agent Process │◀────│ AgentSpawner │
│ (Spawned) │ │ (Health + I/O) │
└─────────────────┘ └──────────────────┘
Testing
Examples
See terraphim_router/examples/unified_routing.rs for a complete example.
License
Apache-2.0