Skip to content

feat: add LiteLLM as AI gateway engine#191

Open
RheagalFire wants to merge 1 commit into
simular-ai:mainfrom
RheagalFire:feat/add-litellm-provider
Open

feat: add LiteLLM as AI gateway engine#191
RheagalFire wants to merge 1 commit into
simular-ai:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire

@RheagalFire RheagalFire commented Apr 23, 2026

Copy link
Copy Markdown

Summary

  • Adds LMMEngineLiteLLM as a new engine type across all Agent-S versions (s2, s2_5, s3)
  • Gives users access to 100+ LLM providers (OpenAI, Anthropic, Azure, Bedrock, Vertex, Groq, Cohere, Ollama, etc.) through a single unified interface
  • Users switch providers by changing the model string, no code changes needed
  • Follows the exact same LMMEngine pattern used by the existing 8 engines

  • What kind of change does this PR introduce? Feature, adds LiteLLM as a new LLM engine

  • Why was this change needed? Agent-S currently has 8 individual LLM engines (OpenAI, Anthropic, Gemini, Azure, OpenRouter, vLLM, HuggingFace, Parasail), each maintained separately. LiteLLM provides a
    unified interface to 100+ LLM providers through a single completion() call. Users switch providers by changing the model string, no code changes needed.

  • Other information: See sections below.


What Changed

File Change
gui_agents/s2/core/engine.py Added LMMEngineLiteLLM class
gui_agents/s2/core/mllm.py Registered litellm engine type + isinstance check
gui_agents/s2_5/core/engine.py Added LMMEngineLiteLLM class
gui_agents/s2_5/core/mllm.py Registered litellm engine type + isinstance check
gui_agents/s3/core/engine.py Added LMMEngineLiteLLM class
gui_agents/s3/core/mllm.py Registered litellm engine type + isinstance check
setup.py Added litellm>=1.60.0,<2.0.0
requirements.txt Added litellm>=1.60.0,<2.0.0
tests/test_litellm_engine.py 15 unit tests across all versions

Usage

Quick Start

from gui_agents.s3.core.mllm import LMMAgent

agent = LMMAgent(
    engine_params={
        "engine_type": "litellm",
        "model": "anthropic/claude-3-haiku",  # any LiteLLM model string
    },                                                                                                                                                                                                             
    system_prompt="You are a helpful assistant.",
)                                                                                                                                                                                                                  
                
response = agent.get_response(user_message="What is 2+2?")
print(response)

Switching Providers: Just Change the Model String                                                                                                                                                                  
 
# OpenAI                                                                                                                                                                                                           
engine_params = {"engine_type": "litellm", "model": "openai/gpt-4o"}

# Anthropic
engine_params = {"engine_type": "litellm", "model": "anthropic/claude-3-haiku"}
                                                                                                                                                                                                                   
# AWS Bedrock
engine_params = {"engine_type": "litellm", "model": "bedrock/anthropic.claude-v2"}                                                                                                                                 
                
# Google Vertex AI
engine_params = {"engine_type": "litellm", "model": "vertex_ai/gemini-pro"}
                                                                                                                                                                                                                   
# Groq
engine_params = {"engine_type": "litellm", "model": "groq/llama3-70b-8192"}                                                                                                                                        
                
# Local Ollama
engine_params = {"engine_type": "litellm", "model": "ollama/llama3"}

Provider API keys are read from standard environment variables automatically (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.), or pass api_key in engine_params.

Any of the https://docs.litellm.ai/docs/providers works.

Direct Engine Usage (Without LMMAgent)

from gui_agents.s3.core.engine import LMMEngineLiteLLM
                                                                                                                                                                                                                   
engine = LMMEngineLiteLLM(model="openai/gpt-4o", api_key="sk-...")
                                                                                                                                                                                                                   
response = engine.generate(
    messages=[
        {"role": "system", "content": [{"type": "text", "text": "You are helpful."}]},
        {"role": "user", "content": [{"type": "text", "text": "Hello!"}]},                                                                                                                                         
    ],
    temperature=0.7,                                                                                                                                                                                               
    max_new_tokens=100,
)                                                                                                                                                                                                                  
print(response)

Testing

Unit Tests (15/15 Passing)

  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_generate_returns_content PASSED
  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_generate_passes_drop_params PASSED
  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_generate_passes_model PASSED                                                                                                                               
  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_generate_forwards_api_key PASSED                                                                                                                           
  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_generate_omits_api_key_when_none PASSED                                                                                                                    
  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_instance_temperature_overrides_param PASSED                                                                                                                
  tests/test_litellm_engine.py::TestS3EngineLiteLLM::test_default_max_tokens PASSED
  tests/test_litellm_engine.py::TestS2EngineLiteLLM::test_generate_returns_content PASSED                                                                                                                            
  tests/test_litellm_engine.py::TestS2EngineLiteLLM::test_drop_params_default PASSED
  tests/test_litellm_engine.py::TestS25EngineLiteLLM::test_generate_returns_content PASSED                                                                                                                           
  tests/test_litellm_engine.py::TestLMMAgentRegistration::test_s3_agent_creates_litellm_engine PASSED
  tests/test_litellm_engine.py::TestLMMAgentRegistration::test_s3_agent_get_response PASSED                                                                                                                          
  tests/test_litellm_engine.py::TestLMMAgentRegistration::test_s2_agent_creates_litellm_engine PASSED
  tests/test_litellm_engine.py::TestLMMAgentRegistration::test_s2_5_agent_creates_litellm_engine PASSED                                                                                                              
  tests/test_litellm_engine.py::TestLMMAgentRegistration::test_unsupported_engine_raises PASSED                                                                                                                      
  ============================== 15 passed in 0.99s ==============================                                                                                                                                   

Live E2E (Azure AI Foundry, Claude Sonnet via LiteLLM)

Model: azure_ai/claude-sonnet-4-6

LMMEngineLiteLLM.generate() -> "4"
LMMAgent.get_response() -> "1, 2, 3"


Risk / Compatibility

  • Additive only, no existing engine code changed
  • drop_params=True set by default so provider-unsupported kwargs are silently dropped
  • LiteLLM lazily imported inside generate(), users who don't use this engine are unaffected
  • Added to all 3 versions (s2, s2_5, s3) for consistency

@RheagalFire

Copy link
Copy Markdown
Author

cc @alckasoc @Richard-Simular

@RheagalFire

Copy link
Copy Markdown
Author

@eric-xw do you have any update on this PR?

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