feat(llm): add LiteLLM AI gateway as a backend for LLMProvider - #143
Open
RheagalFire wants to merge 2 commits into
Open
feat(llm): add LiteLLM AI gateway as a backend for LLMProvider#143RheagalFire wants to merge 2 commits into
RheagalFire wants to merge 2 commits into
Conversation
Author
|
cc @wjw12 |
Author
|
@rexdotsh do you have any update on this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds LiteLLM as an embedded AI gateway backend in
LLMProvider, opt-in viaprovider="litellm". It is not a separate proxy server. The framework imports thelitellmSDK directly and routesevery completion through
litellm.completion/litellm.acompletion, so a singleLLMProviderinstance can talk to OpenAI, Anthropic, Vertex AI, Bedrock, Azure, Cohere, Mistral, Groq, Ollama, and 90+ otherhosted backends without configuring each SDK individually.
What it does:
core/llm.py:call_llm_litellm,call_llm_with_tools_litellm, plus async variants. Same call-site contract as the existingcall_llm/call_llm_with_tools, but routes throughLiteLLM.
providerparameter toLLMProvider.__init__(default"heurist", new option"litellm"). When"litellm", the existingcall()method dispatches to the new functions.litellm>=1.60,<1.85as a dependency.Why:
large_model_idand the relevant env var.ANTHROPIC_API_KEY,OPENAI_API_KEY,AWS_ACCESS_KEY_ID,AZURE_API_KEY, ...) by default, with optionalapi_key/base_urlfor OpenAI-compatiblecustom endpoints (private LiteLLM proxies, Azure Foundry deployments, etc.).
drop_params=Trueis on by default so kwargs that some providers reject (presence_penalty/frequency_penaltyon Anthropic, Gemini, Bedrock;response_formaton Bedrock; etc.) are silently droppedinstead of raising
UnsupportedParamsError.Backward compatibility: the default backend stays
"heurist". All existingLLMProvider(...)call sites inagents/,mesh/,interfaces/, andcore/examples/are unchanged.Usage:
##How Has This Been Tested?
Unit tests (17 / 17 pass)
Added
tests/test_litellm_provider.pycovering:_litellm_kwargsbuilder (drop_params default, credential propagation, user-kwargs override).call_llm_litellmreturns content dict, propagates tool calls, raisesLLMErroron failure, forwards temperature /max_tokens/litellm_kwargs.call_llm_litellm_asyncandcall_llm_with_tools_litellm_asyncvariants.LLMProviderinit: default backend, litellm backend skips Heurist env, accepts explicit credentials, rejects unknown backend.LLMProvider._dispatchpicks the correct call functions for each backend.LLMProvider.call()with provider="litellm" actually routes throughlitellm.completion.The tool-calling test instantiates a FakeToolManager whose execute_tool returns a string, then verifies the full chain: Anthropic returns tool_calls, LiteLLM normalizes the response shape, LLMProvider.call()
extracts the call, dispatches to tool_manager.execute_tool, and merges the result back into the text.
Reproduce
uv sync export ANTHROPIC_API_KEY=sk-ant-... uv run pytest tests/test_litellm_provider.pyChecklist
mesh/tests/that instantiates my mesh agent and calls itshandle_messagewith example input.Additional Notes