Environment:ANative Lab EvoAgentX LiteLLM Dependencies
| Knowledge Sources | |
|---|---|
| Domains | LLM, API, NLP |
| Last Updated | 2026-10-21 00:00 GMT |
Overview
Python 3.10+ environment with `litellm` (>=1.83.10) and provider-specific API keys for multi-provider and local LLM access via LiteLLM.
Description
This environment provides the runtime context for the LiteLLM implementation, which extends OpenAILLM to support multiple cloud providers (OpenAI, Azure, Anthropic, DeepSeek, Gemini, Meta Llama, OpenRouter, Perplexity, Groq) and local models (Ollama, LM Studio). LiteLLM acts as a meta-provider that routes requests to the correct backend based on the model name prefix. Environment variables are set dynamically in `init_model` based on the detected provider company.
= Usage
Use this environment whenever you instantiate LiteLLM with a LiteLLMConfig. It is the mandatory prerequisite for running any AFlow optimizer, workflow optimization, or agent that uses a non-OpenAI-direct provider via LiteLLM. Also supports local models running on Ollama or other OpenAI-compatible local servers.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux / macOS / Windows | OS Independent |
| Hardware | Any CPU | Network-bound for cloud; local server for local models |
| Disk | Minimal | Only for pip packages |
| Network | HTTPS to provider API | Required for cloud providers; localhost for local models |
Dependencies
System Packages
- None OS-specific
Python Packages
- `litellm` >= 1.83.10
- `openai` >= 1.55.3
- `tenacity` (for retry logic)
- `pydantic` >= 2.9.0
Credentials
The following credentials are set as environment variables by `init_model` based on the provider company detected from the model name:
- `OPENAI_API_KEY`: Required for OpenAI models (set `openai_key` in config)
- `AZURE_API_KEY` / `AZURE_API_BASE` / `AZURE_API_VERSION`: Required for Azure OpenAI models (set `azure_key`, `azure_endpoint`, `api_version`)
- `DEEPSEEK_API_KEY`: Required for DeepSeek models (set `deepseek_key`)
- `ANTHROPIC_API_KEY`: Required for Anthropic models (set `anthropic_key`)
- `GEMINI_API_KEY`: Required for Gemini models (set `gemini_key`)
- `LLAMA_API_KEY`: Required for Meta Llama models (set `meta_llama_key`)
- `OPENROUTER_API_KEY` / `OPENROUTER_API_BASE`: Required for OpenRouter models (set `openrouter_key`, `openrouter_base`)
- `PERPLEXITYAI_API_KEY`: Required for Perplexity models (set `perplexity_key`)
- `GROQ_API_KEY`: Required for Groq models (set `groq_key`)
- `api_base` + `api_key`: Required for local models (set `is_local=True`, `api_base`, `api_key`)
Quick Install
# Install core dependencies
pip install litellm>=1.83.10 openai>=1.55.3 tenacity pydantic>=2.9.0
Code Evidence
Provider detection and env var routing from `evoagentx/models/litellm_model.py:31-83`:
company = infer_litellm_company_from_model(self.model)
if self.config.is_local or company == "local":
if not self.api_base:
raise ValueError("api_base is required for local models in LiteLLMConfig")
litellm.api_base = self.api_base
litellm.api_key = self.api_key
else:
if company == "openai":
if not self.config.openai_key:
raise ValueError("OpenAI API key is required for OpenAI models.")
os.environ["OPENAI_API_KEY"] = self.config.openai_key
elif company == "azure":
...
Local model tool calling fallback from `evoagentx/models/litellm_model.py:91-98`:
def supports_native_tool_calling(self) -> bool:
return not bool(self.config.is_local)
Cost computation fallback from `evoagentx/models/litellm_model.py:114-133`:
def _compute_cost(self, usage) -> Cost:
if self.config.is_local:
return Cost(input_tokens=input_tokens, output_tokens=output_tokens, input_cost=0.0, output_cost=0.0)
try:
return super()._compute_cost(usage)
except Exception as e:
logger.warning(f"[LiteLLM] Could not compute cost for model '{self.config.model}': {e}.")
return Cost(input_tokens=input_tokens, output_tokens=output_tokens, input_cost=0.0, output_cost=0.0)
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Unsupported company: xxx` | Model name prefix not recognized | Use a valid provider prefix (e.g., `openai/`, `anthropic/`, `azure/`, `local/`) |
| `api_base is required for local models` | `is_local=True` but no `api_base` set | Set `api_base` to local server URL (e.g., `http://localhost:11434/v1`) |
| `OpenAI API key is required for OpenAI models` | Missing `openai_key` for OpenAI provider | Set `openai_key` in `LiteLLMConfig` |
| `Could not compute cost for model 'xxx'` | Model not in LiteLLM price map | Non-fatal; tokens recorded with zero cost |
Compatibility Notes
- Local models: Set `is_local=True` and provide `api_base`. Local models do not require API keys and cost is recorded as zero.
- Tool calling: Native tool calling is disabled for local models (`supports_native_tool_calling()` returns `False`), falling back to prompt-based tool calling. This is because local model tool support is unreliable.
- Azure: Requires `azure_endpoint` and `azure_key` in addition to the model name. The `api_version` is optional (default: `2024-12-01-preview`).
- Cost tracking: LiteLLM accepts arbitrary model names, and `cost_per_token` raises for models missing from its price map. The implementation catches this and records zero cost rather than failing the call.