[Feature Request] Support Using litellm.Router Instance
Is your feature request related to a problem? Please describe.
ADK currently supports using LiteLLM as a model provider. I noticed that while there is a llm_client parameter available, it does not seem to support passing a custom client instance. Moreover, the LiteLLM SDK features a Router that provides powerful load balancing capabilities, which could be particularly useful for managing multiple model deployments.
I prefer programmatic model management over environment variables, especially when working with multiple models that have different base URLs and API keys.
Describe the solution you'd like
I propose either:
- Allowing ADK to globally accept a configured
litellm.Routerinstance, or - Enabling
litellm.Routerto be passed directly via thellm_clientparameter
Describe alternatives you've considered
- LiteLLM Proxy - adds unnecessary external dependency
@Ocyss will check on the possiblities to implement this
@hangfei Looks like it is self assigned to you, is it still valid to contribute
Is somebody working on this? It would be really helpful if this gets added.
@hangfei @boyangsvl if this is valid to contribute, shall I check with this ??
@kavinkumar807 please help.
@selcukgun can provide some guidance.
@hangfei sure I'm happy to help.I will into this.
Hey team, is anyone working on this? This would be very helpful to build reliable agents. I have faced some issues in production because the model APIs were not available and hence impacting the google-adk agents as well. If router is supported then it can fallback to use different models when primary model APIs are not available (happened quite a few times with OpenAI and Gemini Both)
@hangfei Is there any workaround right now to account for model availability issues? What if the model APIs are down? Would be super helpful if you can point me to relevant documentation.
@anand-bakerev, you an do anything like it, but its only a workaround:
from litellm import Router
...
model_list = [
{
"model_name": "gemini-flash",
"litellm_params": {
"model": ...,
"api_key": ...,
},
},
{
"model_name": "gemini-flash",
"litellm_params": {
"model": ...,
"api_key": ...,
},
},
]
router = Router(model_list=model_list)
model = LiteLlm(model='gemini-flash')
model.llm_client = router
root_agent = Agent(
model=model,
...
)
You need make it to don't have problems with pydantic types check, but works perfectily cause the router and the litellm cient have the same function called by the adk
@anand-bakerev, you an do anything like it, but its only a workaround:
from litellm import Router
...
model_list = [ { "model_name": "gemini-flash", "litellm_params": { "model": ..., "api_key": ..., }, }, { "model_name": "gemini-flash", "litellm_params": { "model": ..., "api_key": ..., }, }, ]
router = Router(model_list=model_list)
model = LiteLlm(model='gemini-flash') model.llm_client = router
root_agent = Agent( model=model, ... ) You need make it to don't have problems with pydantic types check, but works perfectily cause the router and the litellm cient have the same function called by the adk
Thank you @tavo-uemg this seems to be working for now!
This issue has been automatically marked as stale because it has not had recent activity after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
@Ocyss Thanks for your request! We are looking into it,This feature is currently under review Thank you for understanding.
litellm.Router already works — assign it to llm_client (it exposes the same acompletion/completion methods):
model = LiteLlm(model="gemini-flash") # matches a model_name in the Router model.llm_client = router # assign after init, not as a constructor arg
Closing as supported.