Skip to content

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

fix(bot):Response language, Multi user memory commit (#1329)

yeshion23333aaa7e2a859e3
diff --git a/benchmark/locomo/openclaw/eval.py b/benchmark/locomo/openclaw/eval.py
index 3e6c92c5f..4bc323da9 100644
--- a/benchmark/locomo/openclaw/eval.py
+++ b/benchmark/locomo/openclaw/eval.py
@@ -31,7 +31,7 @@ import requests
# Configuration constants
DEFAULT_BASE_URL = "http://127.0.0.1:18789"
-DEFAULT_AGENT_ID = "main"
+DEFAULT_AGENT_ID = "locomo-eval"
DEFAULT_INGEST_RECORD_PATH = ".ingest_record.json"
# CSV write lock for thread safety
diff --git a/benchmark/locomo/openclaw/run_full_eval.sh b/benchmark/locomo/openclaw/run_full_eval.sh
index 3f1edff11..9429e7b2d 100755
--- a/benchmark/locomo/openclaw/run_full_eval.sh
+++ b/benchmark/locomo/openclaw/run_full_eval.sh
@@ -80,7 +80,7 @@ if [ "$SKIP_IMPORT" = false ]; then
echo "[1/5] 导入数据到 OpenViking 和 OpenClaw..."
# 后台运行 OpenViking 导入
- python "$SCRIPT_DIR/../vikingbot/import_to_ov.py" --input "$INPUT_FILE" $FORCE_INGEST_ARG $SAMPLE_ARG > "$RESULT_DIR/import_ov.log" 2>&1 &
+ python "$SCRIPT_DIR/import_to_ov.py" --no-user-agent-id --input "$INPUT_FILE" $FORCE_INGEST_ARG $SAMPLE_ARG > "$RESULT_DIR/import_ov.log" 2>&1 &
PID_OV=$!
# 后台运行 OpenClaw 导入
diff --git a/bot/vikingbot/agent/context.py b/bot/vikingbot/agent/context.py
index 73ec56d39..01f3e36a7 100644
--- a/bot/vikingbot/agent/context.py
+++ b/bot/vikingbot/agent/context.py
@@ -95,18 +95,6 @@ class ContextBuilder:
f"## Sandbox Environment\n\nYou are running in a sandboxed environment. All file operations and command execution are restricted to the sandbox directory.\nThe sandbox root directory is `{sandbox_cwd}` (use relative paths for all operations)."
)
- # Add session context
- session_context = "## Current Session"
- if session_key and session_key.type:
- session_context += f"\nChannel: {session_key.type}"
- if self._is_group_chat:
- session_context += (
- f"\n**Group chat session.** Current user ID: {self._sender_id}\n"
- f"Multiple users can participate in this conversation. Each user message is prefixed with the user ID in brackets like @<user_id>. "
- f"You should pay attention to who is speaking to understand the context. "
- )
- parts.append(session_context)
-
# Bootstrap files
bootstrap = self._load_bootstrap_files()
if bootstrap:
@@ -166,6 +154,18 @@ Skills with available="false" need dependencies installed first - you can try in
tz = _time.strftime("%Z") or "UTC"
parts.append(f"## Current Time: {now} ({tz})")
+ # Add session context
+ session_context = "## Current Session"
+ if session_key and session_key.type:
+ session_context += f"\nChannel: {session_key.type}"
+ if self._is_group_chat:
+ session_context += (
+ f"\n**Group chat session.** Current user ID: {self._sender_id}\n"
+ f"Multiple users can participate in this conversation. Each user message is prefixed with the user ID in brackets like @<user_id>. "
+ f"You should pay attention to who is speaking to understand the context. "
+ )
+ parts.append(session_context)
+
workspace_id = self.sandbox_manager.to_workspace_id(session_key)
# Viking agent memory
@@ -184,6 +184,8 @@ Skills with available="false" need dependencies installed first - you can try in
f"{viking_memory}"
)
+ parts.append("Reply in the same language as the user's query, ignoring the language of the reference materials. User's query:")
+
return "\n\n---\n\n".join(parts)
async def _get_identity(self, session_key: SessionKey) -> str:
@@ -220,11 +222,10 @@ You have two workspaces:
2. OpenViking workspace: managed via OpenViking tools
- Custom skills: {workspace_display}/skills/{{skill-name}}/SKILL.md
-IMPORTANT: When responding to direct questions or conversations, reply directly with your text response.
-Please keep your reply in the same language as the user's message.
-Only use the 'message' tool when you need to send a message to a specific chat channel (like WhatsApp).
-For normal conversation, just respond with text - do not call the message tool.
-Always be helpful, accurate, and concise. When using tools, think step by step: what you know, what you need, and why you chose this tool.
+IMPORTANT:
+- When responding to direct questions or conversations, reply directly with your text response.
+- Only use the 'message' tool when you need to send a message to a specific chat channel (like WhatsApp).For normal conversation, just respond with text - do not call the message tool.
+- Always be helpful, accurate, and concise. When using tools, think step by step: what you know, what you need, and why you chose this tool.
## Memory
- Remember important facts: using openviking_memory_commit tool to commit"""
diff --git a/bot/vikingbot/agent/loop.py b/bot/vikingbot/agent/loop.py
index d9e712850..d11a8df6a 100644
--- a/bot/vikingbot/agent/loop.py
+++ b/bot/vikingbot/agent/loop.py
@@ -396,7 +396,7 @@ class AgentLoop:
max_ticks = 7
while not long_running_notified and tick_count < max_ticks:
- await asyncio.sleep(40)
+ await asyncio.sleep(60)
if long_running_notified:
break
if msg.metadata:
diff --git a/bot/vikingbot/hooks/builtins/openviking_hooks.py b/bot/vikingbot/hooks/builtins/openviking_hooks.py
index 2cbd51e30..5d36abca4 100644
--- a/bot/vikingbot/hooks/builtins/openviking_hooks.py
+++ b/bot/vikingbot/hooks/builtins/openviking_hooks.py
@@ -1,5 +1,7 @@
import re
+import asyncio
from typing import Any
+from collections import defaultdict
from loguru import logger
@@ -42,11 +44,46 @@ class OpenVikingCompactHook(Hook):
async def execute(self, context: HookContext, **kwargs) -> Any:
vikingbot_session: Session = kwargs.get("session", {})
session_id = context.session_key.safe_name()
+ config = load_config()
+ admin_user_id = config.ov_server.admin_user_id
try:
client = await self._get_client(context.workspace_id)
- result = await client.commit(session_id, vikingbot_session.messages, load_config().ov_server.admin_user_id)
- return result
+
+ # 1. 提交全部的 message 到 admin
+ admin_result = await client.commit(session_id, vikingbot_session.messages, admin_user_id)
+
+ # 2. 根据 message 里的 sender_id 进行分组
+ messages_by_sender = defaultdict(list)
+ for msg in vikingbot_session.messages:
+ sender_id = msg.get("sender_id")
+ if sender_id and sender_id != admin_user_id:
+ messages_by_sender[sender_id].append(msg)
+
+ # 3. 带并发限制地提交到各个 user
+ user_results = []
+ if messages_by_sender:
+ # 限制最大并发数为 5
+ semaphore = asyncio.Semaphore(5)
+
+ async def commit_with_semaphore(user_id: str, user_messages: list):
+ async with semaphore:
+ return await client.commit(f"{session_id}_{user_id}", user_messages, user_id)
+
+ user_tasks = []
+ for user_id, user_messages in messages_by_sender.items():
+ task = commit_with_semaphore(user_id, user_messages)
+ user_tasks.append(task)
+
+ # 等待所有用户任务完成
+ user_results = await asyncio.gather(*user_tasks, return_exceptions=True)
+
+ return {
+ "success": True,
+ "admin_result": admin_result,
+ "user_results": user_results,
+ "users_count": len(messages_by_sender)
+ }
except Exception as e:
logger.exception(f"Failed to add message to OpenViking: {e}")
return {"success": False, "error": str(e)}