Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

add timeout config (#2917)

DuTao9253619a9876
diff --git a/bot/README.md b/bot/README.md
index de27fd549..5d5ad2fb3 100644
--- a/bot/README.md
+++ b/bot/README.md
@@ -168,6 +168,7 @@ All configurations are under the `bot` field in `ov.conf`, with default values f
- `agents`: Agent configuration
- `model`: LLM model name used by the bot. When `provider` is set, use the provider-native model name (for example `doubao-seed-2-0-pro-260215`).
- `temperature`: Sampling temperature for LLM requests. Defaults to `0.7`.
+ - `timeout`: Per-request timeout in seconds for fetching chat results from the model provider. Inherits `vlm.timeout` when omitted (default `60.0`).
- `provider`: Optional model provider name. When set, vikingbot uses OpenViking's `VLMFactory` + adapter path to create the backend directly (for example `volcengine`, `openai`, `deepseek`).
- `api_key`: Optional API key for the agent model provider. Can be configured here directly when you want bot-specific credentials.
- `api_base`: Optional API base for the agent model provider. Useful for provider gateways or custom endpoints such as VolcEngine Ark.
@@ -210,6 +211,7 @@ All configurations are under the `bot` field in `ov.conf`, with default values f
"api_base": "https://ark.cn-beijing.volces.com/api/v3",
"provider": "volcengine",
"temperature": 0.7,
+ "timeout": 60.0,
"max_tool_iterations": 50,
"memory_window": 50
},
diff --git a/bot/README_CN.md b/bot/README_CN.md
index 38d28f5e4..11aab535e 100644
--- a/bot/README_CN.md
+++ b/bot/README_CN.md
@@ -170,6 +170,7 @@ bot 将连接到远程 OpenViking Server,使用前请先启动 OpenViking Serv
- `agents`:Agent 配置
- `model`:bot 使用的 LLM 模型名。当设置了 `provider` 时,建议直接使用 provider 原生模型名(例如 `doubao-seed-2-0-pro-260215`)。
- `temperature`:LLM 请求的采样温度,默认 `0.7`。
+ - `timeout`:访问模型 provider 获取 chat 结果的单次请求超时时间(秒)。未配置时继承 `vlm.timeout`(默认 `60.0`)。
- `provider`:可选的模型 provider 名称。设置后,vikingbot 会通过 OpenViking 的 `VLMFactory` + adapter 路径直接创建后端(例如 `volcengine`、`openai`、`deepseek`)。
- `api_key`:可选,Agent 模型 provider 的 API Key。若希望 bot 使用独立凭证,可直接在这里配置。
- `api_base`:可选,Agent 模型 provider 的 API Base。适用于 provider 网关或自定义端点,例如 VolcEngine Ark。
@@ -212,6 +213,7 @@ bot 将连接到远程 OpenViking Server,使用前请先启动 OpenViking Serv
"api_base": "https://ark.cn-beijing.volces.com/api/v3",
"provider": "volcengine",
"temperature": 0.7,
+ "timeout": 60.0,
"max_tool_iterations": 50,
"memory_window": 50
},
diff --git a/bot/vikingbot/cli/commands.py b/bot/vikingbot/cli/commands.py
index eb29ad17c..65c075fbd 100644
--- a/bot/vikingbot/cli/commands.py
+++ b/bot/vikingbot/cli/commands.py
@@ -275,6 +275,7 @@ def _make_provider(config, langfuse_client: None = None):
api_base = p.api_base if p else None
provider_name = p.provider if p else None
extra_headers = p.extra_headers if p else {}
+ timeout = p.timeout if p else None
if not model:
raise RuntimeError("No LLM model configured. Please set it in ~/.openviking/ov.conf")
@@ -292,6 +293,8 @@ def _make_provider(config, langfuse_client: None = None):
"model": model,
"temperature": temperature,
}
+ if timeout is not None:
+ vlm_config["timeout"] = timeout
if api_key:
vlm_config["api_key"] = api_key
if api_base:
@@ -317,6 +320,7 @@ def _make_provider(config, langfuse_client: None = None):
default_model=model,
extra_headers=extra_headers,
provider_name=provider_name,
+ timeout=timeout,
langfuse_client=langfuse_client,
)
diff --git a/bot/vikingbot/config/loader.py b/bot/vikingbot/config/loader.py
index 82dd54f9f..1cf198877 100644
--- a/bot/vikingbot/config/loader.py
+++ b/bot/vikingbot/config/loader.py
@@ -133,24 +133,29 @@ def _merge_vlm_model_config(bot_data: dict, vlm_data: dict) -> None:
Only sets model parameters - provider config is read directly from OpenVikingConfig.
"""
+ if vlm_data:
+ if "agents" not in bot_data:
+ bot_data["agents"] = {}
+
+ agents = bot_data.get("agents", {})
+ if vlm_data and "timeout" not in agents:
+ agents["timeout"] = vlm_data["timeout"] if "timeout" in vlm_data else 60.0
+
# Set default model from vlm.model
if "agents" in bot_data:
- agents = bot_data["agents"]
if "model" in agents and agents["model"]:
return
if vlm_data.get("model"):
- if "agents" not in bot_data:
- bot_data["agents"] = {}
model = vlm_data["model"]
provider = vlm_data.get("provider")
- bot_data["agents"]["model"] = model
- bot_data["agents"]["provider"] = provider if provider else ""
- bot_data["agents"]["api_base"] = vlm_data.get("api_base", "")
- bot_data["agents"]["api_key"] = vlm_data.get("api_key", "")
- if "temperature" in vlm_data and "temperature" not in bot_data["agents"]:
- bot_data["agents"]["temperature"] = vlm_data["temperature"]
+ agents["model"] = model
+ agents["provider"] = provider if provider else ""
+ agents["api_base"] = vlm_data.get("api_base", "")
+ agents["api_key"] = vlm_data.get("api_key", "")
+ if "temperature" in vlm_data and "temperature" not in agents:
+ agents["temperature"] = vlm_data["temperature"]
if "extra_headers" in vlm_data and vlm_data["extra_headers"] is not None:
- bot_data["agents"]["extra_headers"] = vlm_data["extra_headers"]
+ agents["extra_headers"] = vlm_data["extra_headers"]
def _merge_ov_server_config(bot_data: dict, ov_data: dict) -> str:
diff --git a/bot/vikingbot/config/schema.py b/bot/vikingbot/config/schema.py
index d09538daa..578fe1fc3 100644
--- a/bot/vikingbot/config/schema.py
+++ b/bot/vikingbot/config/schema.py
@@ -439,6 +439,14 @@ class AgentsConfig(BaseModel):
le=2.0,
description="Sampling temperature for LLM requests.",
)
+ timeout: Optional[float] = Field(
+ default=None,
+ gt=0.0,
+ description=(
+ "Per-request timeout in seconds for LLM requests. When omitted, vikingbot "
+ "inherits vlm.timeout from ov.conf if present."
+ ),
+ )
max_tool_iterations: int = 50
memory_window: int = 50
session_context_enabled: bool = False
diff --git a/bot/vikingbot/providers/litellm_provider.py b/bot/vikingbot/providers/litellm_provider.py
index 6c2610df5..b8d4925ca 100644
--- a/bot/vikingbot/providers/litellm_provider.py
+++ b/bot/vikingbot/providers/litellm_provider.py
@@ -39,11 +39,13 @@ class LiteLLMProvider(LLMProvider):
default_model: str = "anthropic/claude-opus-4-5",
extra_headers: dict[str, str] | None = None,
provider_name: str | None = None,
+ timeout: float | None = None,
langfuse_client: LangfuseClient | None = None,
):
super().__init__(api_key, api_base)
self.default_model = default_model
self.extra_headers = extra_headers or {}
+ self.timeout = timeout
self.langfuse = langfuse_client or LangfuseClient.get_instance()
# Detect gateway / local deployment.
@@ -217,6 +219,9 @@ class LiteLLMProvider(LLMProvider):
if self.api_base:
kwargs["api_base"] = self.api_base
+ if self.timeout is not None:
+ kwargs["timeout"] = self.timeout
+
# Pass extra headers (e.g. APP-Code for AiHubMix)
if self.extra_headers:
kwargs["extra_headers"] = self.extra_headers
@@ -373,6 +378,8 @@ class LiteLLMProvider(LLMProvider):
kwargs["api_key"] = self.api_key
if self.api_base:
kwargs["api_base"] = self.api_base
+ if self.timeout is not None:
+ kwargs["timeout"] = self.timeout
if self.extra_headers:
kwargs["extra_headers"] = self.extra_headers
if tools:
diff --git a/bot/vikingbot/tests/unit/test_bot_model_timeout.py b/bot/vikingbot/tests/unit/test_bot_model_timeout.py
new file mode 100644
index 000000000..535d002de
--- /dev/null
+++ b/bot/vikingbot/tests/unit/test_bot_model_timeout.py
@@ -0,0 +1,98 @@
+from types import SimpleNamespace
+from unittest import mock
+
+import pytest
+from pydantic import ValidationError
+
+from vikingbot.config.loader import _merge_vlm_model_config
+from vikingbot.config.schema import AgentsConfig
+from vikingbot.providers.litellm_provider import LiteLLMProvider
+
+
+def _chat_response(content: str = "ok"):
+ return SimpleNamespace(
+ choices=[
+ SimpleNamespace(
+ message=SimpleNamespace(content=content, tool_calls=None),
+ finish_reason="stop",
+ )
+ ],
+ usage=SimpleNamespace(prompt_tokens=1, completion_tokens=1, total_tokens=2),
+ )
+
+
+def test_agents_config_accepts_timeout():
+ config = AgentsConfig(timeout=120.0)
+
+ assert config.timeout == 120.0
+
+
+def test_agents_config_rejects_non_positive_timeout():
+ with pytest.raises(ValidationError):
+ AgentsConfig(timeout=0)
+
+
+def test_bot_agents_timeout_inherits_vlm_timeout_when_omitted():
+ bot_data = {"agents": {"model": "bot-model"}}
+
+ _merge_vlm_model_config(bot_data, {"model": "vlm-model", "timeout": 180.0})
+
+ assert bot_data["agents"]["model"] == "bot-model"
+ assert bot_data["agents"]["timeout"] == 180.0
+
+
+def test_bot_agents_timeout_inherits_vlm_default_timeout_when_omitted():
+ bot_data = {"agents": {"model": "bot-model"}}
+
+ _merge_vlm_model_config(bot_data, {"model": "vlm-model"})
+
+ assert bot_data["agents"]["timeout"] == 60.0
+
+
+def test_bot_agents_timeout_overrides_vlm_timeout():
+ bot_data = {"agents": {"model": "bot-model", "timeout": 45.0}}
+
+ _merge_vlm_model_config(bot_data, {"model": "vlm-model", "timeout": 180.0})
+
+ assert bot_data["agents"]["timeout"] == 45.0
+
+
+async def test_litellm_provider_passes_timeout_to_chat_request(monkeypatch):
+ captured = {}
+
+ async def fake_acompletion(**kwargs):
+ captured.update(kwargs)
+ return _chat_response()
+
+ monkeypatch.setattr("vikingbot.providers.litellm_provider.acompletion", fake_acompletion)
+
+ provider = LiteLLMProvider(
+ api_key="sk-test",
+ api_base="https://example.invalid",
+ default_model="openai/gpt-4o-mini",
+ timeout=75.0,
+ )
+ response = await provider.chat(messages=[{"role": "user", "content": "hi"}])
+
+ assert response.content == "ok"
+ assert captured["timeout"] == 75.0
+
+
+def test_volcengine_vlm_passes_timeout_to_sync_client():
+ from openviking.models.vlm.backends.volcengine_vlm import VolcEngineVLM
+
+ vlm = VolcEngineVLM(
+ {
+ "provider": "volcengine",
+ "model": "doubao-test",
+ "api_key": "ak-test",
+ "api_base": "https://example.invalid/api/v3",
+ "timeout": 88.0,
+ }
+ )
+
+ with mock.patch("volcenginesdkarkruntime.Ark") as fake:
+ vlm.get_client()
+
+ assert fake.call_args.kwargs["timeout"] == 88.0
diff --git a/openviking/models/vlm/backends/volcengine_vlm.py b/openviking/models/vlm/backends/volcengine_vlm.py
index f3f96b6fd..4066e97a5 100644
--- a/openviking/models/vlm/backends/volcengine_vlm.py
+++ b/openviking/models/vlm/backends/volcengine_vlm.py
@@ -81,6 +81,7 @@ class VolcEngineVLM(OpenAIVLM):
self._sync_client = volcenginesdkarkruntime.Ark(
api_key=self.api_key,
base_url=self.api_base,
+ timeout=self.timeout,
)
return self._sync_client
@@ -95,6 +96,7 @@ class VolcEngineVLM(OpenAIVLM):
return volcenginesdkarkruntime.AsyncArk(
api_key=self.api_key,
base_url=self.api_base,
+ timeout=self.timeout,
)
def get_completion(