Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ANative Lab EvoAgentX LiteLLM

From Leeroopedia
Knowledge Sources
Domains LLM, NLP
Last Updated 2026-10-21 00:00 GMT

Overview

Concrete tool for multi-provider LLM generation via the LiteLLM library, supporting OpenAI, Anthropic, DeepSeek, Azure, and local models through a unified interface.

Description

The LiteLLM class extends OpenAILLM and uses the `litellm` library's `completion` and `acompletion` functions to route requests to the appropriate provider based on the model name prefix (e.g., `openai/`, `anthropic/`, `deepseek/`). It automatically sets provider-specific environment variables from the LiteLLMConfig, and supports local models via `is_local=True` with a custom `api_base`.

Usage

  • Workflow optimization: Use as the optimizer LLM in `AFlowOptimizer` to generate workflow improvements across providers.
  • Multi-provider access: Switch between providers (OpenAI, Anthropic, DeepSeek, local) without changing application code.
  • Local models: Connect to local LLM servers (Ollama, LM Studio) via `is_local=True` and `api_base`.

Code Reference

Source Location

  • Repository: EvoAgentX
  • Config File: evoagentx/models/model_configs.py (L62-108)
  • Model File: evoagentx/models/litellm_model.py (L17-193)

Signature

class LiteLLMConfig(LLMConfig):
    llm_type: str = "LiteLLM"
    model: str
    api_base: Optional[str] = None
    is_local: Optional[bool] = False
    api_key: Optional[str] = None
    openai_key: Optional[str] = None
    anthropic_key: Optional[str] = None
    deepseek_key: Optional[str] = None
    gemini_key: Optional[str] = None
    meta_llama_key: Optional[str] = None
    openrouter_key: Optional[str] = None
    azure_endpoint: Optional[str] = None
    azure_key: Optional[str] = None
    temperature: Optional[float] = None
    max_tokens: Optional[int] = None
    max_completion_tokens: Optional[int] = None
    stream: Optional[bool] = None
    tools: Optional[List] = None
    tool_choice: Optional[Union[str, dict]] = None
    response_format: Optional[Union[BaseModel, dict]] = None

class LiteLLM(OpenAILLM):
    def init_model(self) -> None
    def single_generate(self, messages: List[dict], **kwargs) -> str
    async def single_generate_async(self, messages: List[dict], **kwargs) -> str

Import

from evoagentx.models.litellm_model import LiteLLM
from evoagentx.models.model_configs import LiteLLMConfig

I/O Contract

Inputs

Name Type Required Description
config LiteLLMConfig Yes Config with provider model id and API keys
messages List[dict] Yes (for generate) Chat messages in OpenAI format

Outputs

Name Type Description
single_generate returns str LLM completion text
cost Cost Tracked via LiteLLM cost_per_token

Usage Examples

AFlow Optimization with LiteLLM

from evoagentx.models.litellm_model import LiteLLM
from evoagentx.models.model_configs import LiteLLMConfig
from evoagentx.optimizers.aflow_optimizer import AFlowOptimizer
from evoagentx.benchmark.hotpotqa import HotPotQA

# 1. Configure optimizer LLM (generates improvements)
optimizer_llm = LiteLLM(config=LiteLLMConfig(
    model="anthropic/claude-3.5-sonnet",
    anthropic_key="sk-ant-...",
))

# 2. Configure executor LLM (runs the workflow)
executor_llm = LiteLLM(config=LiteLLMConfig(
    model="openai/gpt-4o-mini",
    openai_key="sk-...",
))

# 3. Create optimizer and run
optimizer = AFlowOptimizer(
    question_type="qa",
    graph_path="./examples/aflow/hotpotqa/",
    optimizer_llm=optimizer_llm,
    executor_llm=executor_llm,
    max_rounds=20,
)

benchmark = HotPotQA(mode="dev")
optimizer.optimize(benchmark=benchmark)

Local Model via Ollama

from evoagentx.models.litellm_model import LiteLLM
from evoagentx.models.model_configs import LiteLLMConfig

llm = LiteLLM(config=LiteLLMConfig(
    model="local/llama3",
    is_local=True,
    api_base="http://localhost:11434/v1",
))

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment