adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

[Feature Request] Support Using litellm.Router Instance

Open Ocyss opened this issue 1 year ago • 14 comments

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:

  1. Allowing ADK to globally accept a configured litellm.Router instance, or
  2. Enabling litellm.Router to be passed directly via the llm_client parameter

Describe alternatives you've considered

  1. LiteLLM Proxy - adds unnecessary external dependency

Ocyss avatar Apr 12 '25 07:04 Ocyss

@Ocyss will check on the possiblities to implement this

kavinkumar807 avatar Apr 14 '25 11:04 kavinkumar807

@hangfei Looks like it is self assigned to you, is it still valid to contribute

kavinkumar807 avatar Apr 24 '25 06:04 kavinkumar807

Is somebody working on this? It would be really helpful if this gets added.

mdaffan01 avatar May 13 '25 18:05 mdaffan01

@hangfei @boyangsvl if this is valid to contribute, shall I check with this ??

kavinkumar807 avatar May 14 '25 04:05 kavinkumar807

@kavinkumar807 please help.

@selcukgun can provide some guidance.

hangfei avatar May 31 '25 23:05 hangfei

@hangfei sure I'm happy to help.I will into this.

kavinkumar807 avatar Jun 01 '25 07:06 kavinkumar807

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)

anand-bakerev avatar Sep 25 '25 14:09 anand-bakerev

@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 avatar Oct 17 '25 07:10 anand-bakerev

@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

tavo-uemg avatar Oct 17 '25 10:10 tavo-uemg

@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!

anand-bakerev avatar Oct 23 '25 07:10 anand-bakerev

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.

adk-bot avatar Nov 27 '25 06:11 adk-bot

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.

adk-bot avatar Dec 04 '25 06:12 adk-bot

@Ocyss Thanks for your request! We are looking into it,This feature is currently under review Thank you for understanding.

klateefa avatar Dec 09 '25 06:12 klateefa

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.

GWeale avatar Jun 24 '26 22:06 GWeale