Skip to content

Using LiteLLM router (with fallback and retry/cooldown) in an Agent #813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ootkin opened this issue Jun 4, 2025 · 0 comments
Open

Using LiteLLM router (with fallback and retry/cooldown) in an Agent #813

ootkin opened this issue Jun 4, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ootkin
Copy link

ootkin commented Jun 4, 2025

Describe the question

I would like to implement an Agent with a custom and strong retry mechanism with fallback to another llm model if something goes wrong.

LiteLLM implements a router to do that: https://docs.litellm.ai/docs/routing

However I cannot pass a Router instance to the model params of the Agent.

You Documentation says the we need to set the model to an instance of LitellmModel, but there is no way to specify a fallback strategy.

Is there a way to do that?

Debug information

  • Agents SDK version: 0.0.17
  • Python version: 3.12

Repro steps

from litellm.router import Router

router = Router(
    model_list=[
        {
            "model_name": "gemini-1.5-flash",
            "litellm_params": {"model": "gemini/gemini-1.5-flash"},
            "timeout": 120,
            "retries": 1,
        },
        {
            "model_name": "gemini-1.5-pro-latest",
            "litellm_params": {"model": "gemini/gemini-1.5-flash"},
            "timeout": 80,
        },
    ],
    fallbacks=[{"gemini-1.5-flash": ["gemini-1.5-pro-latest"]}],
)

agent = Agent(
    name="My Agent",
    instructions=",
    model=router, # cannot do that
)

Expected behavior

Have the possibility to pass a LiteLLM router or specify a fallback strategy for an Agent

@ootkin ootkin added the bug Something isn't working label Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant