EXAMPLE: Adapter & Router System Demo
Demonstrate cost-optimized routing across multiple LLM providers and local models
halo
// ============================================================
// EXAMPLE: Adapter & Router System Demo
// PURPOSE: Demonstrate cost-optimized routing across
// multiple LLM providers and local models
// ============================================================
// ── Agents with different providers ─────
// OpenAI cloud model
agent Fast [openai/gpt-4o-mini, temp: 0.3]
// Anthropic cloud model
agent Smart [anthropic/claude-3-5-sonnet, temp: 0.7]
// Local model (free, fast)
agent Local [ollama/llama3.1, temp: 0.5]
// Together AI (cheap alternative)
agent Alt [together/meta-llama/Llama-3.1-8B-Instruct, temp: 0.5]
// ── Router Configuration ─────
// In halo.json or runtime config:
// {
// "router": {
// "strategy": "balanced",
// "maxCostPer1kTokens": 0.01,
// "preferredProviders": ["ollama", "together", "openai"],
// "requiredCapabilities": ["streaming"]
// }
// }
// ── Pipeline: Auto-routes to best model ─────
pipeline AskAnything(question: String) -> Result:
question
|> Fast.prompt("Answer: {{question}}")
|> System.Print()
// ── Pipeline: Cost-optimized ─────
// Router will prefer cheapest option (local > together > openai)
pipeline CheapAnswer(question: String) -> Result:
question
|> Alt.prompt("Quick answer: {{question}}")
|> System.Print()
// ── Pipeline: Performance-optimized ─────
// Router will pick most capable model
pipeline SmartAnswer(question: String) -> Result:
question
|> Smart.prompt("Detailed answer: {{question}}")
|> System.Print()
// ── Execution:
// runtime.setRouterConfig({
// strategy: "cost-optimized",
// maxCostPer1kTokens: 0.005,
// });
// await runtime.execute("CheapAnswer", { question: "What is AI?" });
//
// Router might select: ollama/llama3.1 (free) or together/meta-llama (cheap)
//
// With strategy: "performance":
// Router would select: anthropic/claude-3-5-sonnet (most capable)