Skip to content

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

fix(bot,ovcli): route explicit providers through VLM adapter and refresh config serialization/docs (#2379)

MaojiaSheng0b8f3f08948f
diff --git a/bot/README.md b/bot/README.md
index b3305d2d4..061a62502 100644
--- a/bot/README.md
+++ b/bot/README.md
@@ -160,6 +160,11 @@ The bot will connect to the remote OpenViking server. Please start the OpenVikin
### Bot Configuration
All configurations are under the `bot` field in `ov.conf`, with default values for configuration items. The optional manual configuration items are described as follows:
- `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`).
+ - `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.
+ - `extra_headers`: Optional extra HTTP headers passed to the model provider.
- `max_tool_iterations`: Maximum number of cycles for a single round of conversation tasks, returns results directly if exceeded
- `memory_window`: Upper limit of conversation rounds for automatically submitting sessions to OpenViking
- `gen_image_model`: Model for generating images
@@ -170,10 +175,11 @@ All configurations are under the `bot` field in `ov.conf`, with default values f
- `mode`: Sandbox mode, optional values are `shared` (all sessions share workspace) or `private` (private, workspace isolated by Channel and session). Default value is `shared`.
- `ov_server`: OpenViking Server configuration.
- If not configured, the OpenViking server information configured in `ov.conf` is used by default
- - If you don't use the locally started OpenViking Server, you can configure the url and the corresponding root user's API Key here
- - root_api_key: In a multi-tenant scenario, the API KEY must have root privileges; otherwise, the bot cannot automatically register multiple OpenViking users, which is used to implement memory isolation.
- - account_id: Defaults to default, which is the account ID of OpenViking. All users under an OpenViking account share resources.
- - api_key_type: Optional `root` or `user`, default `root`. `root` keeps the original root-key fanout behavior; `user` switches the bot to the user-key flow for OpenViking client calls. See #1994 for the full client flow.
+ - If you use a remote OpenViking Server, configure the target service URL and API key here
+ - `server_url`: OpenViking server base URL, for example `https://api.vikingdb.cn-beijing.volces.com/openviking` or `http://localhost:1933`.
+ - `root_api_key`: API key used by the bot when calling the OpenViking server. Despite the historical field name, this field is also used in the `user` key flow.
+ - `account_id`: Defaults to `default`, which is the OpenViking account ID. All users under the same OpenViking account share resources.
+ - `api_key_type`: Optional `root` or `user`, default `root`. `root` keeps the original root-key fanout behavior; `user` switches the bot to the user-key flow for OpenViking client calls. For a hosted remote OpenViking service, `user` is usually the recommended choice.
- exp_write_tools: Optional list of tool names that trigger experience-memory injection before the call (self-evolving agent memory loop, see #2007). Defaults to `["write_file", "edit_file"]`. Injection only fires when the OpenViking server has `memory.agent_memory_enabled` set; otherwise this list is harmless.
- `channels`: Message platform configuration, see [Message Platform Configuration](bot/docs/CHANNEL.md) for details
@@ -181,28 +187,34 @@ All configurations are under the `bot` field in `ov.conf`, with default values f
{
"bot": {
"agents": {
+ "model": "doubao-seed-2-0-pro-260215",
+ "api_key": "<your-ark-api-key>",
+ "api_base": "https://ark.cn-beijing.volces.com/api/v3",
+ "provider": "volcengine",
"max_tool_iterations": 50,
- "memory_window": 50,
- "gen_image_model": "openai/doubao-seedream-4-5-251128"
+ "memory_window": 50
},
"gateway": {
"host": "0.0.0.0",
- "port": 18790
+ "port": 18790,
+ "token": "<set-a-random-gateway-token>"
},
"sandbox": {
"mode": "shared"
},
"ov_server": {
- "server_url": "http://127.0.0.1:1933",
- "root_api_key": "test"
+ "server_url": "https://api.vikingdb.cn-beijing.volces.com/openviking",
+ "root_api_key": "<your-openviking-user-api-key>",
+ "account_id": "default",
+ "api_key_type": "user"
},
"channels": [
{
"type": "feishu",
"enabled": true,
"ov_tools_enable": true,
- "appId": "",
- "appSecret": "",
+ "appId": "<your-feishu-app-id>",
+ "appSecret": "<your-feishu-app-secret>",
"allowFrom": []
}
]
@@ -210,6 +222,19 @@ All configurations are under the `bot` field in `ov.conf`, with default values f
}
```
+If you only want to try the bot through `vikingbot gateway` or `vikingbot chat`, you can set `channels` to an empty list (`[]`).
+
+With the configuration above, you can try the bot directly, or configure Feishu at the same time:
+
+```bash
+# Start the HTTP gateway
+vikingbot gateway
+
+# Or chat with the bot directly in CLI
+vikingbot chat
+vikingbot chat -m "Hello"
+```
+
### OpenViking Agent Tools
Vikingbot provides 7 dedicated OpenViking tools:
diff --git a/bot/README_CN.md b/bot/README_CN.md
index 704aead24..11509b661 100644
--- a/bot/README_CN.md
+++ b/bot/README_CN.md
@@ -144,15 +144,15 @@ ov chat --no-format
> 修改配置后(直接编辑文件),
> 您需要重启网关服务以使更改生效。
-### Openviking Server配置
-bot将连接远程的OpenViking服务器,使用前需启动Openviking Server。 默认使用`ov.conf`中配置的OpenViking server信息
-- Openviking默认启动地址为 127.0.0.1:1933
-- 如果配置了 root_api_key,则开启多租户模式。详见 [多租户](https://github.com/volcengine/OpenViking/blob/main/examples/multi_tenant/README.md)
-- Openviking Server配置示例
+### OpenViking Server 配置
+bot 将连接到远程 OpenViking Server,使用前请先启动 OpenViking Server。默认使用 `ov.conf` 中配置的 OpenViking Server 信息。
+- OpenViking 默认启动地址为 `127.0.0.1:1933`
+- 如果配置了 `root_api_key`,则开启多租户模式。详见 [多租户](https://github.com/volcengine/OpenViking/blob/main/examples/multi_tenant/README.md)
+- OpenViking Server 配置示例
```json
{
"server": {
-
+
"host": "127.0.0.1",
"port": 1933,
"root_api_key": "test"
@@ -160,52 +160,64 @@ bot将连接远程的OpenViking服务器,使用前需启动Openviking Server
}
```
-### bot配置
-全部配置在`ov.conf`中`bot`字段下,配置项自带默认值。可选手动配置项说明如下:
+### Bot 配置
+所有配置都位于 `ov.conf` 的 `bot` 字段下,且各配置项都带有默认值。可选手动配置项说明如下:
- `agents`:Agent 配置
- - max_tool_iterations:单轮对话任务最大循环次数,超过则直接返回结果
- - memory_window:自动提交session到Openviking的对话轮次上限
- - gen_image_model:生成图片的模型
-- gateway:Gateway 配置
+ - `model`:bot 使用的 LLM 模型名。当设置了 `provider` 时,建议直接使用 provider 原生模型名(例如 `doubao-seed-2-0-pro-260215`)。
+ - `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。
+ - `extra_headers`:可选,透传给模型 provider 的额外 HTTP 请求头。
+ - `max_tool_iterations`:单轮对话任务最大循环次数,超过则直接返回结果。
+ - `memory_window`:自动提交 session 到 OpenViking 的对话轮次上限。
+ - `gen_image_model`:生成图片使用的模型。
+- `gateway`:Gateway 配置
- host:Gateway 监听地址,默认值为 `0.0.0.0`
- port:Gateway 监听端口,默认值为 `18790`
-- sandbox:沙箱配置
- - mode:沙箱模式,可选值为 `shared`(所有session共享工作空间)或 `private`(私有,按Channel、session隔离工作空间)。默认值为 `shared`。
-- ov_server:OpenViking Server 配置。
- - 不配置,默认使用`ov.conf`中配置的OpenViking server信息
- - 若不使用本地启动的OpenViking Server,可在此配置url和对应的root user的API Key
- - root_api_key: 多租户场景API KEY必须有root权限,否则bot无法自动注册多个OpenViking用户,用于实现memory的隔离
- - account_id: 默认default,ov的账号ID,OpenViking account下所有user共享resources
- - api_key_type: 可选 `root` 或 `user`,默认 `root`。`root` 保留原有的 root-key fanout 行为;`user` 切换 bot 走 user-key 流程调用 OpenViking 客户端。完整客户端流程详见 #1994。
- - exp_write_tools: 可选,触发经验记忆注入的工具名列表(自演化 agent memory 循环,详见 #2007)。默认 `["write_file", "edit_file"]`。注入仅在 OpenViking server 启用 `memory.agent_memory_enabled` 时生效,否则此列表无作用。
-- channels:消息平台配置,详见 [消息平台配置](bot/docs/CHANNEL.md)
+- `sandbox`:沙箱配置
+ - `mode`:沙箱模式,可选值为 `shared`(所有 session 共享工作空间)或 `private`(私有,按 Channel、session 隔离工作空间)。默认值为 `shared`。
+- `ov_server`:OpenViking Server 配置
+ - 若不配置,默认使用 `ov.conf` 中配置的 OpenViking Server 信息。
+ - 如果你使用远端 OpenViking Server,可以在这里配置目标服务地址和 API Key。
+ - `server_url`:OpenViking Server 基础地址,例如 `https://api.vikingdb.cn-beijing.volces.com/openviking` 或 `http://localhost:1933`。
+ - `root_api_key`:bot 调用 OpenViking Server 时使用的 API Key。尽管字段名保留为 `root_api_key`,但在 `user` key 流程下该字段同样会被使用。
+ - `account_id`:默认值为 `default`,即 OpenViking 的账号 ID。同一 OpenViking account 下的所有 user 共享 resources。
+ - `api_key_type`:可选 `root` 或 `user`,默认 `root`。`root` 保留原有的 root-key fanout 行为;`user` 切换 bot 走 user-key 流程调用 OpenViking 客户端。对于托管型远端 OpenViking 服务,通常推荐使用 `user`。
+ - `exp_write_tools`:可选,触发经验记忆注入的工具名列表(自演化 agent memory 循环,详见 #2007)。默认 `["write_file", "edit_file"]`。注入仅在 OpenViking Server 启用 `memory.agent_memory_enabled` 时生效,否则此列表无作用。
+- `channels`:消息平台配置,详见 [消息平台配置](bot/docs/CHANNEL.md)
```json
{
"bot": {
"agents": {
+ "model": "doubao-seed-2-0-pro-260215",
+ "api_key": "<your-ark-api-key>",
+ "api_base": "https://ark.cn-beijing.volces.com/api/v3",
+ "provider": "volcengine",
"max_tool_iterations": 50,
- "memory_window": 50,
- "gen_image_model": "openai/doubao-seedream-4-5-251128"
+ "memory_window": 50
},
"gateway": {
"host": "0.0.0.0",
- "port": 18790
+ "port": 18790,
+ "token": "<set-a-random-gateway-token>"
},
"sandbox": {
"mode": "shared"
},
"ov_server": {
- "server_url": "http://127.0.0.1:1933",
- "root_api_key": "test"
+ "server_url": "https://api.vikingdb.cn-beijing.volces.com/openviking",
+ "root_api_key": "<your-openviking-user-api-key>",
+ "account_id": "default",
+ "api_key_type": "user"
},
"channels": [
{
"type": "feishu",
"enabled": true,
"ov_tools_enable": true,
- "appId": "",
- "appSecret": "",
+ "appId": "<your-feishu-app-id>",
+ "appSecret": "<your-feishu-app-secret>",
"allowFrom": []
}
]
@@ -213,6 +225,19 @@ bot将连接远程的OpenViking服务器,使用前需启动Openviking Server
}
```
+如果你只是想通过 `vikingbot gateway` 或 `vikingbot chat` 体验 bot,可以将 `channels` 设置为空数组(`[]`)。
+
+使用上述配置时,你可以直接体验 bot,或者同时配置飞书:
+
+```bash
+# 启动 HTTP Gateway
+vikingbot gateway
+
+# 或直接在 CLI 中与 bot 对话
+vikingbot chat
+vikingbot chat -m "Hello"
+```
+
### OpenViking Agent 工具
Vikingbot 提供 7 个专用的 OpenViking 工具:
@@ -305,6 +330,7 @@ Provider 配置从 OpenViking 配置(`ov.conf` 的 `vlm` 部分)读取。
> - **Groq** 通过 Whisper 提供免费的语音转录。如果已配置,Telegram 语音消息将自动转录。
> - **智谱编码计划**:如果您使用智谱的编码计划,请在您的 zhipu 提供商配置中设置 `"apiBase": "https://open.bigmodel.cn/api/coding/paas/v4"`。
> - **MiniMax(中国大陆)**:如果您的 API 密钥来自 MiniMax 的中国大陆平台(minimaxi.com),请在您的 minimax 提供商配置中设置 `"apiBase": "https://api.minimaxi.com/v1"`。
+> - **MiniMax 推荐模型**:`MiniMax-M2.7`(性能更强)和 `MiniMax-M2.7-highspeed`(速度更快、更灵活)。可在 agent 配置中通过 `"model": "MiniMax-M2.7"` 使用。
| 提供商 | 用途 | 获取 API 密钥 |
|----------|---------|-------------|
diff --git a/bot/tests/test_minimax_provider.py b/bot/tests/test_minimax_provider.py
index be61ec4b2..138f906c3 100644
--- a/bot/tests/test_minimax_provider.py
+++ b/bot/tests/test_minimax_provider.py
@@ -88,7 +88,7 @@ class TestMiniMaxModelPrefixResolution:
class TestMiniMaxSystemMessageHandling:
- """Tests for MiniMax system message merging in both LLM providers."""
+ """Tests for MiniMax system message merging in LiteLLMProvider."""
# ------------------------------------------------------------------ #
# Helpers
@@ -103,13 +103,6 @@ class TestMiniMaxSystemMessageHandling:
provider._gateway = None
return provider._handle_system_message(model, messages)
- def _handle_system_openai_compat(self, model: str, messages: list[dict]) -> list[dict]:
- """Call the OpenAICompatibleProvider._handle_system_message."""
- from vikingbot.providers.openai_compatible_provider import OpenAICompatibleProvider
-
- provider = OpenAICompatibleProvider.__new__(OpenAICompatibleProvider)
- return provider._handle_system_message(model, messages)
-
# ------------------------------------------------------------------ #
# LiteLLMProvider tests (model name after prefix resolution)
# ------------------------------------------------------------------ #
@@ -167,35 +160,3 @@ class TestMiniMaxSystemMessageHandling:
]
result = self._handle_system_litellm("anthropic/claude-opus-4-5", messages)
assert result == messages
-
- # ------------------------------------------------------------------ #
- # OpenAICompatibleProvider tests (raw model name, no prefix)
- # ------------------------------------------------------------------ #
-
- def test_openai_compat_system_message_merged_for_m2_7(self):
- """System message is merged for MiniMax-M2.7 in OpenAICompatibleProvider."""
- messages = [
- {"role": "system", "content": "You are a helpful assistant."},
- {"role": "user", "content": "Hello!"},
- ]
- result = self._handle_system_openai_compat("MiniMax-M2.7", messages)
- assert all(m["role"] != "system" for m in result)
- user_content = next(m["content"] for m in result if m["role"] == "user")
- assert "You are a helpful assistant." in user_content
-
- def test_openai_compat_no_system_message_passthrough(self):
- """Messages without a system role pass through unchanged."""
- messages = [
- {"role": "user", "content": "Hello!"},
- ]
- result = self._handle_system_openai_compat("MiniMax-M2.7", messages)
- assert result == messages
-
- def test_openai_compat_system_only_creates_user_message(self):
- """System-only messages create a synthetic user message."""
- messages = [
- {"role": "system", "content": "You are a bot."},
- ]
- result = self._handle_system_openai_compat("MiniMax-M2.7", messages)
- assert any(m["role"] == "user" for m in result)
- assert all(m["role"] != "system" for m in result)
diff --git a/bot/vikingbot/cli/commands.py b/bot/vikingbot/cli/commands.py
index c2cbab44f..8cb803425 100644
--- a/bot/vikingbot/cli/commands.py
+++ b/bot/vikingbot/cli/commands.py
@@ -9,7 +9,7 @@ import sys
import time
import warnings
from pathlib import Path
-from typing import Optional
+from typing import Any, Optional
import typer
from loguru import logger
@@ -243,7 +243,12 @@ def main(
def _make_provider(config, langfuse_client: None = None):
- """Create LiteLLM provider from configuration."""
+ """Create LLM provider from configuration.
+
+ When bot.agents.provider is explicitly set, uses openviking's VLMFactory
+ to create the appropriate VLM backend and wraps it in VLMProviderAdapter.
+ Otherwise falls back to the legacy LiteLLMProvider.
+ """
from vikingbot.providers.litellm_provider import LiteLLMProvider
p = config.agents
@@ -256,6 +261,33 @@ def _make_provider(config, langfuse_client: None = None):
if not model:
raise RuntimeError("No LLM model configured. Please set it in ~/.openviking/ov.conf")
+ # When provider is explicitly set, use VLMFactory to get the correct
+ # backend (e.g. VolcEngineVLM for volcengine, OpenAIVLM for openai).
+ # The VLM backend handles model name resolution internally, so no
+ # manual LiteLLM prefix is needed.
+ if provider_name:
+ from openviking.models.vlm.base import VLMFactory
+ from vikingbot.providers.vlm_adapter import VLMProviderAdapter
+
+ vlm_config: dict[str, Any] = {
+ "provider": provider_name,
+ "model": model,
+ }
+ if api_key:
+ vlm_config["api_key"] = api_key
+ if api_base:
+ vlm_config["api_base"] = api_base
+ if extra_headers:
+ vlm_config["extra_headers"] = extra_headers
+
+ vlm_instance = VLMFactory.create(vlm_config)
+ return VLMProviderAdapter(
+ vlm_instance=vlm_instance,
+ default_model=model,
+ langfuse_client=langfuse_client,
+ )
+
+ # Fallback: legacy LiteLLMProvider (no explicit provider set)
if not api_key and not model.startswith("bedrock/"):
console.print("[yellow]Warning: No API key configured.[/yellow]")
console.print("You can configure providers later in the Console UI.")
diff --git a/bot/vikingbot/providers/__init__.py b/bot/vikingbot/providers/__init__.py
index 6b3910ba8..2650da6d0 100644
--- a/bot/vikingbot/providers/__init__.py
+++ b/bot/vikingbot/providers/__init__.py
@@ -1,6 +1,5 @@
"""LLM provider abstraction module."""
from vikingbot.providers.base import LLMProvider, LLMResponse
-from vikingbot.providers.litellm_provider import LiteLLMProvider
-__all__ = ["LLMProvider", "LLMResponse", "LiteLLMProvider"]
+__all__ = ["LLMProvider", "LLMResponse"]
diff --git a/bot/vikingbot/providers/litellm_provider.py b/bot/vikingbot/providers/litellm_provider.py
index 3865af214..6114b0741 100644
--- a/bot/vikingbot/providers/litellm_provider.py
+++ b/bot/vikingbot/providers/litellm_provider.py
@@ -335,7 +335,7 @@ class LiteLLMProvider(LLMProvider):
pass
# Return error as content for graceful handling
return LLMResponse(
- content=f"Error calling LLM: {str(e)}",
+ content=f"Error calling LLM in LiteLLM: {str(e)}",
finish_reason="error",
)
diff --git a/bot/vikingbot/providers/openai_compatible_provider.py b/bot/vikingbot/providers/openai_compatible_provider.py
deleted file mode 100644
index e7969d3ca..000000000
--- a/bot/vikingbot/providers/openai_compatible_provider.py
+++ /dev/null
@@ -1,325 +0,0 @@
-"""OpenAI-compatible LLM provider implementation.
-
-Supports all LLM providers with OpenAI-compatible API endpoints, including:
-- OpenAI / Anthropic / DeepSeek / Moonshot / MiniMax
-- Zhipu AI / DashScope (Aliyun) / VolcEngine Ark
-- Local deployments: vLLM / Ollama / Llama.cpp
-- Gateways: OpenRouter / AiHubMix / any other OpenAI-compatible gateway
-"""
-
-import json
-from typing import Any
-
-from loguru import logger
-from openai import AsyncOpenAI
-
-from vikingbot.integrations.langfuse import LangfuseClient
-from vikingbot.providers.base import LLMProvider, LLMResponse, ToolCallRequest
-from vikingbot.utils.helpers import cal_str_tokens
-from vikingbot.utils.tracing import get_current_response_id
-
-
-class OpenAICompatibleProvider(LLMProvider):
- """
- LLM provider for any OpenAI-compatible API endpoint.
-
- This replaces the LiteLLM provider with a minimal, secure implementation
- that directly uses the official OpenAI SDK, supporting all providers that
- follow the OpenAI API specification.
- """
-
- def __init__(
- self,
- api_key: str | None = None,
- api_base: str | None = None,
- default_model: str = "claude-3-opus-20240229",
- extra_headers: dict[str, str] | 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.langfuse = langfuse_client or LangfuseClient.get_instance()
-
- # Initialize OpenAI client
- self.client = AsyncOpenAI(
- api_key=api_key,
- base_url=api_base,
- default_headers=extra_headers,
- )
-
- def _handle_system_message(
- self, model: str, messages: list[dict[str, Any]]
- ) -> list[dict[str, Any]]:
- """
- Handle system message for providers that don't support it (e.g. MiniMax).
- Merges system message into the first user message or converts to user role.
- """
- # Check for MiniMax
- if "minimax" in model.lower():
- # Create a copy to avoid modifying the original list
- new_messages = []
-
- # Helper to merge content
- def merge_content(base_content, new_content):
- if isinstance(base_content, str) and isinstance(new_content, str):
- return f"{new_content}\n\n{base_content}"
- if isinstance(base_content, list):
- base_content = list(base_content)
- base_content.insert(0, {"type": "text", "text": f"{new_content}\n\n"})
- return base_content
- return f"{new_content}\n\n{str(base_content)}"
-
- # First pass: identify system messages
- system_contents = []
- cleaned_messages = []
-
- for msg in messages:
- if msg.get("role") == "system":
- system_contents.append(msg.get("content", ""))
- else:
- cleaned_messages.append(msg)
-
- # If no system messages, return as is
- if not system_contents:
- return messages
-
- # Combine all system prompts
- full_system_prompt = "\n\n".join([str(c) for c in system_contents])
-
- # Merge into the first user message if available
- merged = False
- for msg in cleaned_messages:
- if not merged and msg.get("role") == "user":
- msg = msg.copy()
- msg["content"] = merge_content(msg.get("content", ""), full_system_prompt)
- new_messages.append(msg)
- merged = True
- else:
- new_messages.append(msg)
-
- # If no user message found, create one at the beginning
- if not merged:
- new_messages.insert(0, {"role": "user", "content": full_system_prompt})
-
- return new_messages
-
- return messages
-
- async def chat(
- self,
- messages: list[dict[str, Any]],
- tools: list[dict[str, Any]] | None = None,
- model: str | None = None,
- max_tokens: int = 4096,
- temperature: float = 0.7,
- session_id: str | None = None,
- ) -> LLMResponse:
- """
- Send a chat completion request to OpenAI-compatible API.
-
- Args:
- messages: List of message dicts with 'role' and 'content'.
- tools: Optional list of tool definitions in OpenAI format.
- model: Model identifier.
- max_tokens: Maximum tokens in response.
- temperature: Sampling temperature.
- session_id: Optional session ID for tracing.
-
- Returns:
- LLMResponse with content and/or tool calls.
- """
- model = model or self.default_model
-
- # Handle system message for providers that don't support it
- messages = self._handle_system_message(model, messages)
-
- kwargs: dict[str, Any] = {
- "model": model,
- "messages": messages,
- "max_tokens": max_tokens,
- "temperature": temperature,
- }
-
- if tools:
- kwargs["tools"] = tools
- kwargs["tool_choice"] = "auto"
-
- # Langfuse integration
- langfuse_observation = None
- try:
- if self.langfuse.enabled and self.langfuse._client:
- metadata = {"has_tools": tools is not None}
- response_id = get_current_response_id()
- if response_id:
- metadata["response_id"] = response_id
- client = self.langfuse._client
- # Use start_observation with generation type
- if hasattr(client, "start_observation"):
- langfuse_observation = client.start_observation(
- name="llm-chat",
- as_type="generation",
- model=model,
- input=messages,
- metadata=metadata,
- )
- if response_id:
- self.langfuse.register_generation(
- response_id, langfuse_observation, metadata=metadata
- )
-
- response = await self.client.chat.completions.create(**kwargs)
- llm_response = self._parse_response(response)
-
- # Update and end Langfuse observation
- if langfuse_observation:
- output_text = llm_response.content or ""
- if llm_response.tool_calls:
- output_text = (
- output_text
- or f"[Tool calls: {[tc.name for tc in llm_response.tool_calls]}]"
- )
-
- # Update observation with output and usage
- update_kwargs: dict[str, Any] = {
- "output": output_text,
- "metadata": {
- "finish_reason": llm_response.finish_reason,
- **(
- {"response_id": get_current_response_id()}
- if get_current_response_id()
- else {}
- ),
- },
- }
-
- if llm_response.usage:
- # Add usage data using usage_details format
- usage_details: dict[str, Any] = {
- "input": llm_response.usage.get("prompt_tokens", 0),
- "output": llm_response.usage.get("completion_tokens", 0),
- }
-
- # Add cache read tokens if available
- cache_read_tokens = llm_response.usage.get(
- "cache_read_input_tokens"
- ) or llm_response.usage.get("prompt_tokens_details", {}).get("cached_tokens")
- if cache_read_tokens:
- usage_details["cache_read_input_tokens"] = cache_read_tokens
-
- update_kwargs["usage_details"] = usage_details
-
- response_id = get_current_response_id()
- if response_id:
- update_kwargs["metadata"] = self.langfuse.update_generation_metadata(
- response_id,
- update_kwargs.get("metadata", {}),
- )
-
- # Update the observation
- if hasattr(langfuse_observation, "update"):
- try:
- langfuse_observation.update(**update_kwargs)
- except Exception as e:
- logger.debug(f"[LANGFUSE] Failed to update observation: {e}")
-
- # End the observation
- if hasattr(langfuse_observation, "end"):
- try:
- langfuse_observation.end()
- except Exception as e:
- logger.debug(f"[LANGFUSE] Failed to end observation: {e}")
-
- try:
- self.langfuse.flush()
- except Exception as e:
- logger.debug(f"[LANGFUSE] Failed to flush: {e}")
-
- return llm_response
- except Exception as e:
- # End Langfuse observation with error
- if langfuse_observation:
- try:
- if hasattr(langfuse_observation, "update"):
- langfuse_observation.update(
- output=f"Error: {str(e)}",
- metadata={
- "error": str(e),
- **(
- {"response_id": get_current_response_id()}
- if get_current_response_id()
- else {}
- ),
- },
- )
- if hasattr(langfuse_observation, "end"):
- langfuse_observation.end()
- try:
- self.langfuse.flush()
- except Exception:
- pass
- except Exception:
- pass
- # Return error as content for graceful handling
- return LLMResponse(
- content=f"Error calling LLM: {str(e)}",
- finish_reason="error",
- )
-
- def _parse_response(self, response: Any) -> LLMResponse:
- """Parse OpenAI API response into our standard format."""
- choice = response.choices[0]
- message = choice.message
-
- tool_calls = []
- if hasattr(message, "tool_calls") and message.tool_calls:
- for tc in message.tool_calls:
- # Parse arguments from JSON string if needed
- args = tc.function.arguments
- tokens = cal_str_tokens(tc.function.name, text_type="en")
- if isinstance(args, str):
- try:
- tokens += cal_str_tokens(args, text_type="mixed")
- args = json.loads(args)
- except json.JSONDecodeError:
- args = {"raw": args}
-
- tool_calls.append(
- ToolCallRequest(id=tc.id, name=tc.function.name, arguments=args, tokens=tokens)
- )
-
- usage = {}
- if hasattr(response, "usage") and response.usage:
- usage = {
- "prompt_tokens": response.usage.prompt_tokens,
- "completion_tokens": response.usage.completion_tokens,
- "total_tokens": response.usage.total_tokens,
- }
-
- # Extract cached tokens from various provider formats
- # OpenAI style: prompt_tokens_details.cached_tokens
- if hasattr(response.usage, "prompt_tokens_details"):
- details = response.usage.prompt_tokens_details
- if details and hasattr(details, "cached_tokens"):
- cached = details.cached_tokens
- if cached:
- usage["cache_read_input_tokens"] = cached
- # Anthropic style: cache_read_input_tokens
- elif hasattr(response.usage, "cache_read_input_tokens"):
- cached = response.usage.cache_read_input_tokens
- if cached:
- usage["cache_read_input_tokens"] = cached
-
- reasoning_content = getattr(message, "reasoning_content", None)
-
- return LLMResponse(
- content=message.content,
- tool_calls=tool_calls,
- finish_reason=choice.finish_reason or "stop",
- usage=usage,
- reasoning_content=reasoning_content,
- )
-
- def get_default_model(self) -> str:
- """Get the default model."""
- return self.default_model
diff --git a/bot/vikingbot/providers/vlm_adapter.py b/bot/vikingbot/providers/vlm_adapter.py
new file mode 100644
index 000000000..fdafa5f06
--- /dev/null
+++ b/bot/vikingbot/providers/vlm_adapter.py
@@ -0,0 +1,205 @@
+"""VLM-to-LLMProvider adapter.
+
+Wraps openviking VLM backends (VLMBase) to implement the vikingbot
+LLMProvider interface, so that bot.agents.provider / bot.agents.model
+configuration semantics are consistent with openviking server's vlm section.
+"""
+
+from typing import Any
+
+from loguru import logger
+
+from vikingbot.integrations.langfuse import LangfuseClient
+from vikingbot.providers.base import LLMProvider, LLMResponse, ToolCallRequest
+from vikingbot.utils.tracing import get_current_response_id
+
+
+class VLMProviderAdapter(LLMProvider):
+ """Adapter that wraps an openviking VLMBase instance as an LLMProvider.
+
+ When bot.agents.provider is explicitly set, _make_provider() creates the
+ appropriate VLM backend via VLMFactory.create() and wraps it with this
+ adapter. The VLM backend handles model name resolution internally (e.g.
+ VolcEngineVLM passes the model verbatim, LiteLLMVLMProvider auto-detects
+ the provider from model name keywords), so no manual prefixing is needed.
+ """
+
+ def __init__(
+ self,
+ vlm_instance, # VLMBase
+ default_model: str,
+ langfuse_client: LangfuseClient | None = None,
+ ):
+ super().__init__(api_key=None, api_base=None)
+ self._vlm = vlm_instance
+ self._default_model = default_model
+ self._langfuse = langfuse_client or LangfuseClient.get_instance()
+
+ async def chat(
+ self,
+ messages: list[dict[str, Any]],
+ tools: list[dict[str, Any]] | None = None,
+ model: str | None = None,
+ max_tokens: int = 4096,
+ temperature: float = 0.7,
+ session_id: str | None = None,
+ ) -> LLMResponse:
+ effective_model = model or self._default_model
+
+ # --- Langfuse: start observation ---
+ langfuse_observation = None
+ try:
+ if self._langfuse.enabled and self._langfuse._client:
+ metadata: dict[str, Any] = {"has_tools": tools is not None}
+ response_id = get_current_response_id()
+ if response_id:
+ metadata["response_id"] = response_id
+ client = self._langfuse._client
+ if hasattr(client, "start_observation"):
+ langfuse_observation = client.start_observation(
+ name="llm-chat",
+ as_type="generation",
+ model=effective_model,
+ input=messages,
+ metadata=metadata,
+ )
+ if response_id:
+ self._langfuse.register_generation(
+ response_id, langfuse_observation, metadata=metadata
+ )
+
+ # --- Call VLM backend ---
+ result = await self._vlm.get_completion_async(
+ messages=messages,
+ tools=tools,
+ tool_choice="auto" if tools else None,
+ )
+
+ llm_response = self._convert_response(result)
+
+ # --- Langfuse: end observation ---
+ if langfuse_observation:
+ self._end_langfuse_observation(langfuse_observation, llm_response)
+
+ return llm_response
+
+ except Exception as e:
+ if langfuse_observation:
+ self._end_langfuse_observation_error(langfuse_observation, e)
+ return LLMResponse(
+ content=f"Error calling LLM in VLM Adapter: {str(e)}",
+ finish_reason="error",
+ )
+
+ def _convert_response(self, result) -> LLMResponse:
+ """Convert VLMResponse (or str) to LLMResponse."""
+ if isinstance(result, str):
+ return LLMResponse(content=result, finish_reason="stop")
+
+ tool_calls = []
+ for tc in result.tool_calls:
+ tool_calls.append(
+ ToolCallRequest(
+ id=tc.id,
+ name=tc.name,
+ arguments=tc.arguments,
+ tokens=0,
+ )
+ )
+
+ return LLMResponse(
+ content=result.content,
+ tool_calls=tool_calls,
+ finish_reason=result.finish_reason,
+ usage=result.usage,
+ reasoning_content=result.reasoning_content,
+ )
+
+ def get_default_model(self) -> str:
+ return self._default_model
+
+ # ------------------------------------------------------------------
+ # Langfuse helpers (same pattern as LiteLLMProvider.chat())
+ # ------------------------------------------------------------------
+
+ def _end_langfuse_observation(self, obs, llm_response: LLMResponse) -> None:
+ try:
+ output_text = llm_response.content or ""
+ if llm_response.tool_calls:
+ output_text = (
+ output_text
+ or f"[Tool calls: {[tc.name for tc in llm_response.tool_calls]}]"
+ )
+
+ update_kwargs: dict[str, Any] = {
+ "output": output_text,
+ "metadata": {
+ "finish_reason": llm_response.finish_reason,
+ **(
+ {"response_id": get_current_response_id()}
+ if get_current_response_id()
+ else {}
+ ),
+ },
+ }
+
+ if llm_response.usage:
+ usage_details: dict[str, Any] = {
+ "input": llm_response.usage.get("prompt_tokens", 0),
+ "output": llm_response.usage.get("completion_tokens", 0),
+ }
+ cache_read_tokens = llm_response.usage.get(
+ "cache_read_input_tokens"
+ ) or llm_response.usage.get("prompt_tokens_details", {}).get("cached_tokens")
+ if cache_read_tokens:
+ usage_details["cache_read_input_tokens"] = cache_read_tokens
+ update_kwargs["usage_details"] = usage_details
+
+ response_id = get_current_response_id()
+ if response_id:
+ update_kwargs["metadata"] = self._langfuse.update_generation_metadata(
+ response_id,
+ update_kwargs.get("metadata", {}),
+ )
+
+ if hasattr(obs, "update"):
+ try:
+ obs.update(**update_kwargs)
+ except Exception as e:
+ logger.debug(f"[LANGFUSE] Failed to update observation: {e}")
+
+ if hasattr(obs, "end"):
+ try:
+ obs.end()
+ except Exception as e:
+ logger.debug(f"[LANGFUSE] Failed to end observation: {e}")
+
+ try:
+ self._langfuse.flush()
+ except Exception as e:
+ logger.debug(f"[LANGFUSE] Failed to flush: {e}")
+ except Exception:
+ pass
+
+ def _end_langfuse_observation_error(self, obs, error: Exception) -> None:
+ try:
+ if hasattr(obs, "update"):
+ obs.update(
+ output=f"Error: {str(error)}",
+ metadata={
+ "error": str(error),
+ **(
+ {"response_id": get_current_response_id()}
+ if get_current_response_id()
+ else {}
+ ),
+ },
+ )
+ if hasattr(obs, "end"):
+ obs.end()
+ try:
+ self._langfuse.flush()
+ except Exception:
+ pass
+ except Exception:
+ pass
diff --git a/crates/ov_cli/src/config.rs b/crates/ov_cli/src/config.rs
index b99168ea2..d36de9ae2 100644
--- a/crates/ov_cli/src/config.rs
+++ b/crates/ov_cli/src/config.rs
@@ -9,11 +9,20 @@ pub const DEFAULT_SELF_MANAGED_URL: &str = "http://127.0.0.1:1933";
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UploadConfig {
+ #[serde(skip_serializing_if = "Option::is_none")]
pub ignore_dirs: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub exclude: Option<String>,
}
+impl UploadConfig {
+ fn is_default(&self) -> bool {
+ self.ignore_dirs.is_none() && self.include.is_none() && self.exclude.is_none()
+ }
+}
+
impl Default for UploadConfig {
fn default() -> Self {
Self {
@@ -26,30 +35,33 @@ impl Default for UploadConfig {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
- #[serde(default = "default_url")]
+ #[serde(default = "default_url", skip_serializing_if = "is_default_url")]
pub url: String,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub api_key: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub root_api_key: Option<String>,
- #[serde(alias = "account_id")]
+ #[serde(skip_serializing_if = "Option::is_none", alias = "account_id")]
pub account: Option<String>,
- #[serde(alias = "user_id")]
+ #[serde(skip_serializing_if = "Option::is_none", alias = "user_id")]
pub user: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub agent_id: Option<String>,
- #[serde(default = "default_timeout")]
+ #[serde(default = "default_timeout", skip_serializing_if = "is_default_timeout")]
pub timeout: f64,
- #[serde(default = "default_output_format")]
+ #[serde(default = "default_output_format", skip_serializing_if = "is_default_output")]
pub output: String,
- #[serde(default = "default_echo_command")]
+ #[serde(default = "default_echo_command", skip_serializing_if = "is_default_echo_command")]
pub echo_command: bool,
- #[serde(default = "default_show_progress")]
+ #[serde(default = "default_show_progress", skip_serializing_if = "is_default_show_progress")]
pub show_progress: bool,
- #[serde(default = "default_verbose")]
+ #[serde(default = "default_verbose", skip_serializing_if = "is_default_verbose")]
pub verbose: bool,
- #[serde(default)]
+ #[serde(default, skip_serializing_if = "is_default_profile")]
pub profile: bool,
- #[serde(default)]
+ #[serde(default, skip_serializing_if = "UploadConfig::is_default")]
pub upload: UploadConfig,
- #[serde(default, alias = "extra_header")]
+ #[serde(default, alias = "extra_header", skip_serializing_if = "Option::is_none")]
pub extra_headers: Option<std::collections::HashMap<String, String>>,
}
@@ -77,6 +89,34 @@ fn default_verbose() -> bool {
false
}
+fn is_default_url(value: &str) -> bool {
+ value == default_url()
+}
+
+fn is_default_timeout(value: &f64) -> bool {
+ (*value - default_timeout()).abs() < f64::EPSILON
+}
+
+fn is_default_output(value: &str) -> bool {
+ value == default_output_format()
+}
+
+fn is_default_echo_command(value: &bool) -> bool {
+ *value == default_echo_command()
+}
+
+fn is_default_show_progress(value: &bool) -> bool {
+ *value == default_show_progress()
+}
+
+fn is_default_verbose(value: &bool) -> bool {
+ *value == default_verbose()
+}
+
+fn is_default_profile(value: &bool) -> bool {
+ !*value
+}
+
impl Default for Config {
fn default() -> Self {
Self {
diff --git a/docs/en/guides/02-volcengine-purchase-guide.md b/docs/en/guides/02-volcengine-purchase-guide.md
index 4a95ca683..ba0829cba 100644
--- a/docs/en/guides/02-volcengine-purchase-guide.md
+++ b/docs/en/guides/02-volcengine-purchase-guide.md
@@ -58,7 +58,7 @@ Visit: [Model Management Page](https://console.volcengine.com/ark/region:ark+cn-
1. Select **"Provisioning Management"** (开通管理) in the left navigation bar.
2. Select the **"Language Model"** (语言模型) column.
-3. Find the **Doubao-Seed-1.8** model.
+3. Find the **Doubao-Seed-2.0** model.
4. Click the "Activate" (开通) button.
5. Confirm the payment method.
@@ -277,7 +277,7 @@ Error: Connection timeout
| Model Name | Current Version | Release Date |
|------------|-----------------|--------------|
-| Doubao-Seed-1.8 | `doubao-seed-2-0-pro-260215` | 2025-12-28 |
+| Doubao-Seed-2.0 | `doubao-seed-2-0-pro-260215` | 2025-12-28 |
| Doubao-Embedding-Vision | `doubao-embedding-vision-251215` | 2025-06-15 |
> Note: Model versions may be updated, please refer to the Volcano Ark Console for the latest information.
diff --git a/docs/zh/guides/02-volcengine-purchase-guide.md b/docs/zh/guides/02-volcengine-purchase-guide.md
index 4440a9e45..9150a81b3 100644
--- a/docs/zh/guides/02-volcengine-purchase-guide.md
+++ b/docs/zh/guides/02-volcengine-purchase-guide.md
@@ -60,7 +60,7 @@ OpenViking 需要以下模型服务:
1. 在左侧导航栏选择 **"开通管理"**
2. 选择 **"语言模型"** 一列
-3. 找到 **Doubao-Seed-1.8** 模型
+3. 找到 **Doubao-Seed-2.0** 模型
4. 点击"开通"按钮
5. 确认付费方式
@@ -74,7 +74,7 @@ OpenViking 需要以下模型服务:
访问:[模型管理页面](https://console.volcengine.com/ark/region:ark+cn-beijing/model)
-1. 在左侧导航栏选择 **"开通管理"**
+1. 在左侧导航栏选择 **"开通管理"**
2. 选择 **"向量模型"** 一列
3. 找到 **Doubao-Embedding-Vision** 模型
4. 点击"开通"
@@ -279,7 +279,7 @@ Error: Connection timeout
| 模型名称 | 当前版本 | 发布日期 |
|---------|---------|---------|
-| Doubao-Seed-1.8 | `doubao-seed-2-0-pro-260215` | 2025-12-28 |
+| Doubao-Seed-2.0 | `doubao-seed-2-0-pro-260215` | 2025-12-28 |
| Doubao-Embedding-Vision | `doubao-embedding-vision-251215` | 2025-06-15 |
> 注:模型版本可能更新,请以火山方舟控制台显示为准。
diff --git a/openviking_cli/utils/config/ovcli_config.py b/openviking_cli/utils/config/ovcli_config.py
index a89487421..5522446a5 100644
--- a/openviking_cli/utils/config/ovcli_config.py
+++ b/openviking_cli/utils/config/ovcli_config.py
@@ -20,7 +20,7 @@ class OVCLIUploadConfig(BaseModel):
include: Optional[str] = None
exclude: Optional[str] = None
- model_config = {"extra": "forbid"}
+ model_config = {"extra": "ignore"}
class OVCLIConfig(BaseModel):
@@ -36,7 +36,7 @@ class OVCLIConfig(BaseModel):
upload: Optional[OVCLIUploadConfig] = None
extra_headers: Optional[Dict[str, str]] = None
- model_config = {"extra": "forbid"}
+ model_config = {"extra": "ignore"}
@model_validator(mode="before")
@classmethod
@@ -44,13 +44,7 @@ class OVCLIConfig(BaseModel):
if isinstance(data, dict):
# 支持 extra_header 作为 extra_headers 的别名
if "extra_header" in data and "extra_headers" not in data:
- # 复制字典并移除 extra_header,避免 extra: "forbid" 报错
- new_data = {k: v for k, v in data.items() if k != "extra_header"}
- new_data["extra_headers"] = data["extra_header"]
- data = new_data
- elif "extra_headers" in data and "extra_header" in data:
- # 优先使用 extra_headers,移除 extra_header
- data = {k: v for k, v in data.items() if k != "extra_header"}
+ data["extra_headers"] = data["extra_header"]
return data