Skip to content

Feat/add litellm provider#23

Open
RheagalFire wants to merge 2 commits into
Xiangyue-Zhang:mainfrom
RheagalFire:feat/add-litellm-provider
Open

Feat/add litellm provider#23
RheagalFire wants to merge 2 commits into
Xiangyue-Zhang:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire
Copy link
Copy Markdown

@RheagalFire RheagalFire commented May 7, 2026

Summary

  • Adds LiteLLM as a new LLM provider, enabling access to 100+ providers (OpenAI, Anthropic, Google, Azure, Bedrock, Ollama, etc.) via a single unified SDK
  • Follows the exact same pattern as _call_anthropic and _call_openai, uses litellm.completion() directly with drop_params=True

Prior art

  • No existing LiteLLM integration
  • No prior LiteLLM PRs

Changes

  • core/agents.py - added _call_litellm() method, wired into _call_llm() dispatch, added "litellm" to SUPPORTED_PROVIDERS
  • config.yaml - documented litellm as a provider option
  • requirements.txt - added litellm>=1.60.0,<2.0.0
  • tests/test_litellm_provider.py - 10 unit tests
  • tests/e2e_litellm.py - live E2E smoke test

Tests

1. Unit tests (10/10 passing):
$ PYTHONPATH=. python -m pytest tests/test_litellm_provider.py -v
test_litellm_in_supported_providers PASSED
test_dispatcher_accepts_litellm_provider PASSED
test_call_litellm_dispatches_to_litellm_completion PASSED
test_call_litellm_includes_drop_params_true PASSED
test_call_litellm_passes_api_key_when_set PASSED
test_call_litellm_omits_api_key_when_not_set PASSED
test_call_litellm_passes_base_url_when_set PASSED
test_call_litellm_formats_messages_correctly PASSED
test_call_litellm_falls_back_to_openai_on_import_error PASSED
test_call_llm_routes_to_litellm PASSED
10 passed in 0.04s

2. Live E2E test (Azure Foundry -> Anthropic Claude):
$ PYTHONPATH=. python tests/e2e_litellm.py
Provider: litellm
Model: anthropic/claude-sonnet-4-6
Base URL: https://***-resource.services.ai.azure.com/anthropic

Response: "4"

E2E PASSED - litellm provider works end-to-end

This proves the full chain: AgentDispatcher._call_litellm() -> litellm.completion() -> Azure Foundry -> Anthropic Claude -> response parsed back as string.

Example usage

# config.yaml
agent:
  provider: "litellm"                                                                                                                                                                                              
  model: "anthropic/claude-sonnet-4-20250514"  # or openai/gpt-4o, azure/gpt-4o, etc.
                                                                                                                                                                                                                   
# LiteLLM reads provider-specific env vars automatically:                                                                                                                                                          
# ANTHROPIC_API_KEY, OPENAI_API_KEY, AZURE_API_KEY, etc.                                                                                                                                                           
# Or set a custom key:                                                                                                                                                                                             
  api_key_env: "MY_CUSTOM_KEY"                                                                                                                                                                                     
  base_url: ""  # optional, for custom endpoints    
from core.agents import AgentDispatcher                                                                                                                                                                            
                                                                                                                                                                                                                   
dispatcher = AgentDispatcher(                                                                                                                                                                                      
    provider="litellm",                                                                                                                                                                                            
    model="anthropic/claude-sonnet-4-20250514",                                                                                                                                                                    
    # LiteLLM reads ANTHROPIC_API_KEY from env automatically.                                                                                                                                                      
    # For custom endpoints, pass api_key= and base_url= explicitly.                                                                                                                                                
)                                                                                                                                                                                                                  
                                                                                                                                                                                                                   
response = dispatcher._call_llm(                                                                                                                                                                                   
    system="You are a research assistant. Be concise.",                                                                                                                                                            
    messages=[{"role": "user", "content": "Summarize recent advances in ViT architectures in 2 sentences."}],                                                                                                      
)                                                                                                                                                                                                                  
print(response)    

  ## Live output (Claude Sonnet via Azure Foundry):                                                                                                                                                                     
# Recent advances in Vision Transformer (ViT) architectures include improved                                                                                                                                         
# efficiency through hierarchical designs (e.g., Swin Transformer), token pruning,                                                                                                                                   
# and hybrid CNN-ViT approaches that reduce computational costs while maintaining                                                                                                                                    
# strong performance. Additionally, innovations like masked image modeling (e.g.,                                                                                                                                    
# MAE), register tokens to reduce artifacts, and scalable architectures (e.g.,                                                                                                                                       
# ViT-22B) have significantly enhanced self-supervised pretraining and scaling                                                                                                                                       
# capabilities for downstream vision tasks.                                   

                                                                                                                                                                                                                                                                                                                                      

See https://docs.litellm.ai/docs/providers for 100+ supported model strings.

Risk / Compatibility

  • Additive only, existing providers untouched
  • litellm is lazy-imported, falls back to openai if not installed
  • drop_params=True silently drops provider-unsupported kwargs
  • Same message format and response parsing as the openai provider

@RheagalFire
Copy link
Copy Markdown
Author

cc @Xiangyue-Zhang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant