Skip to content

Agent Zero AI framework

feat(settings): add LiteLLM global params

linuztx7f66fadb9d78
diff --git a/models.py b/models.py
index 3606d3b02..02997e1c5 100644
--- a/models.py
+++ b/models.py
@@ -18,6 +18,7 @@ from litellm import completion, acompletion, embedding
import litellm
from python.helpers import dotenv
+from python.helpers import settings
from python.helpers.dotenv import load_dotenv
from python.helpers.providers import get_provider_config
from python.helpers.rate_limiter import RateLimiter
@@ -434,7 +435,18 @@ class LocalSentenceTransformerWrapper(Embeddings):
if model.startswith("sentence-transformers/"):
model = model[len("sentence-transformers/") :]
- self.model = SentenceTransformer(model, **kwargs)
+ # Filter kwargs for SentenceTransformer only (no LiteLLM params like 'stream_timeout')
+ st_allowed_keys = {
+ "device",
+ "cache_folder",
+ "use_auth_token",
+ "revision",
+ "trust_remote_code",
+ "model_kwargs",
+ }
+ st_kwargs = {k: v for k, v in (kwargs or {}).items() if k in st_allowed_keys}
+
+ self.model = SentenceTransformer(model, **st_kwargs)
self.model_name = model
self.a0_model_conf = model_config
@@ -542,6 +554,22 @@ def _adjust_call_args(provider_name: str, model_name: str, kwargs: dict):
def _merge_provider_defaults(
provider_type: str, original_provider: str, kwargs: dict
) -> tuple[str, dict]:
+ # Normalize .env-style numeric strings (e.g., "timeout=30") into ints/floats for LiteLLM
+ def _normalize_values(values: dict) -> dict:
+ result: dict[str, Any] = {}
+ for k, v in values.items():
+ if isinstance(v, str):
+ try:
+ result[k] = int(v)
+ except ValueError:
+ try:
+ result[k] = float(v)
+ except ValueError:
+ result[k] = v
+ else:
+ result[k] = v
+ return result
+
provider_name = original_provider # default: unchanged
cfg = get_provider_config(provider_type, original_provider)
if cfg:
@@ -559,6 +587,15 @@ def _merge_provider_defaults(
if key and key not in ("None", "NA"):
kwargs["api_key"] = key
+ # Merge LiteLLM global kwargs (timeouts, stream_timeout, etc.)
+ try:
+ global_kwargs = settings.get_settings().get("litellm_global_kwargs", {}) # type: ignore[union-attr]
+ except Exception:
+ global_kwargs = {}
+ if isinstance(global_kwargs, dict):
+ for k, v in _normalize_values(global_kwargs).items():
+ kwargs.setdefault(k, v)
+
return provider_name, kwargs
diff --git a/python/helpers/settings.py b/python/helpers/settings.py
index db4d9b780..261f75cc1 100644
--- a/python/helpers/settings.py
+++ b/python/helpers/settings.py
@@ -105,6 +105,9 @@ class Settings(TypedDict):
secrets: str
+ # LiteLLM global kwargs applied to all model calls
+ litellm_global_kwargs: dict[str, str]
+
class PartialSettings(Settings, total=False):
pass
@@ -582,6 +585,28 @@ def convert_out(settings: Settings) -> SettingsOutput:
"tab": "external",
}
+ # LiteLLM global config section
+ litellm_fields: list[SettingsField] = []
+
+ litellm_fields.append(
+ {
+ "id": "litellm_global_kwargs",
+ "title": "LiteLLM global parameters",
+ "description": "Global LiteLLM params (e.g. timeout, stream_timeout) in .env format: one KEY=VALUE per line. Example: <code>stream_timeout=30</code>. Applied to all LiteLLM calls unless overridden. See <a href='https://docs.litellm.ai/docs/set_keys' target='_blank'>LiteLLM</a> and <a href='https://docs.litellm.ai/docs/proxy/timeout' target='_blank'>timeouts</a>.",
+ "type": "textarea",
+ "value": _dict_to_env(settings["litellm_global_kwargs"]),
+ "style": "height: 12em",
+ }
+ )
+
+ litellm_section: SettingsSection = {
+ "id": "litellm",
+ "title": "LiteLLM Global Settings",
+ "description": "Configure global parameters passed to LiteLLM for all providers.",
+ "fields": litellm_fields,
+ "tab": "external",
+ }
+
# Agent config section
agent_fields: list[SettingsField] = []
@@ -1205,6 +1230,7 @@ def convert_out(settings: Settings) -> SettingsOutput:
memory_section,
speech_section,
api_keys_section,
+ litellm_section,
secrets_section,
auth_section,
mcp_client_section,
@@ -1441,6 +1467,7 @@ def get_default_settings() -> Settings:
mcp_server_token=create_auth_token(),
a2a_server_enabled=False,
secrets="",
+ litellm_global_kwargs={},
)
diff --git a/webui/public/litellm.svg b/webui/public/litellm.svg
new file mode 100644
index 000000000..14a43d01d
--- /dev/null
+++ b/webui/public/litellm.svg
@@ -0,0 +1,11 @@
+
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
+ <g stroke="#333" stroke-width="7" stroke-miterlimit="10" fill="#000" fill-opacity="0.08">
+ <path d="M511.9 82.5c-.8-.1-1.4-.1-1.9-.1-81.6 0-163.2 0-244.8.1-8.5 0-16.6 2-24.4 5.4-15.7 6.9-27.4 18.8-39 30.7 10.8 0 21.6.1 32.4.1h126.3c1.5 0 2.9 0 4.9 1l-11.7 11.7c-18.7 18.6-37.5 37.1-56.1 55.8-3.4 3.4-6.8 4.9-11.7 4.9-50.7-.2-101.3-.1-152-.1-1.8 0-3.6-.1-5.5-.1-18.4 9.3-36.9 18.7-55.3 28 0 49.8 0 99.7-.1 149.5 0 1.8-.1 3.6-.2 5.5h110.3l69.5-69.8c2.3-2.4 4.7-3.4 8.1-3.4h251c2.1 0 4.2-.1 6.3-.1V85c.2-.8.1-1.6.1-2.5Z"/>
+ <path d="M183.2 374.8 252.9 305c2.3-2.4 4.7-3.4 8.1-3.4h251c2.1 0 4.2-.1 6.3-.1v73.2H296.7H237.3"/>
+ <path d="M30.5 243.1C4.4 260.5-4 286.2 1.7 316.2c6.5 34.3 36.1 58 71.2 58.7V225.4l-42.4 17.7Z"/>
+ <path d="M184.8 171.6h164.5c17.4-17.3 34.9-34.5 52.1-51.9"/>
+ <path d="M511.8 429.6H19c18-18.2 35.9-36.4 53.9-54.6h224.1 209.7v36.5Z"/>
+ <path d="M365.4 119.6H234.2c-10.8 0-21.6-.1-32.4-.1l-17 16.8h164.8c5.4-5.4 9.4-9.4 16.8-16.7Z"/>
+ </g>
+</svg>