登録して招待リンクを共有すると、動画再生報酬と紹介報酬を獲得できます。

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture 投稿は個人の意見です。
参加 May 2026
286 フォロー中    469 ファン
# Useful but Little-Known Features of ADK 2.0 🌍 What if your agent could dynamically pick the best LLM for each request, balancing cost and quality on the fly? ADK 2.0's model routing uses the RoutedLlm class and LlmRouter function to dynamically select which model handles each request. 📌 Title: Model Routing 🔗 URL: 🧩 Overview The RoutedLlm class enables dynamic model selection from a pool of LLMs on a per-request basis. An LlmRouter function receives the map of available models, the current request, and an error context, then returns the key of the model to use. If a model fails before producing output, the router is called again with the error information, allowing automatic fallback to a different model. Note that you cannot switch models mid-stream once `connect()` has started. 🛠 How to use it Define an LlmRouter function and pass it to RoutedLlm as the agent's model. ```typescript import { BaseLlm, Gemini, LlmRequest, LlmAgent, RoutedLlm } from '@google/adk'; const myRouter = ( models: Readonly>, request: LlmRequest, errorContext?: { failedKeys: ReadonlySet; lastError: unknown }, ) => { if (!errorContext) { return 'primary'; // Try the powerful model first } if (errorContext.failedKeys.has('primary')) { return 'fallback'; // Fall back to the lightweight model on failure } return undefined; // No more options, propagate the error }; const agent = new LlmAgent({ name: 'smart_agent', model: new RoutedLlm({ models: { primary: new Gemini({ model: 'gemini-pro-latest' }), fallback: new Gemini({ model: 'gemini-flash-latest' }), }, router: myRouter, }), instruction: 'Process the task', }); ``` Unlike agent routing (switching between agents), model routing keeps the same agent logic and only changes the underlying model. 🏗 Building it into production ・Configure automatic fallback to a backup model when the primary model fails ・Route based on request complexity to optimize costs between powerful and lightweight models ・Implement A/B testing routers to compare model performance in production ・Log model selection decisions for cost analysis and performance optimization 💡 Use cases 🔄 Automatic failover when the primary model goes down 💰 Cost-optimized routing based on request complexity 🧪 A/B testing new vs. existing models for performance comparison 🌍 Model selection based on request language or region ⚠️ Watch out Model routing is experimental and available in ADK TypeScript v1.0.0 and later. You cannot switch models mid-stream after `connect()` has started. Overly complex router logic becomes hard to debug and maintain — keep your selection criteria simple. Also, verify that your fallback model supports the same capabilities as the primary model before relying on it in production. ✨ Model routing gives you dynamic control over availability, cost, and quality — making agent operations in production far more flexible and resilient. #ADK# #AIAgent#
もっと見る