feat(tools): refactor migrate OpenClaw from custom tool to builtin tool

Create OpenClawTool class inheriting BuiltinTool with dedicated config
Remove all x-openclaw special handling from CustomTool (~270 lines)
Add multi-operation support (print_task, device_query, image_understand, general)
Change ensure_builtin_tools_initialized to incremental mode for auto-provisioning
Fix OperationTool and LangchainAdapter to support OpenClaw operation routing
This commit is contained in:
miao
2026-04-09 18:13:21 +08:00
parent 562ca6c1f1
commit 55b2e05ba8
10 changed files with 503 additions and 475 deletions

View File

@@ -640,17 +640,14 @@ class AgentRunService:
multimodal_service = MultimodalService(self.db, model_info)
processed_files = await multimodal_service.process_files(files)
logger.info(f"处理了 {len(processed_files)} 个文件provider={provider}")
#================= 为 OpenClaw 工具注入运行时上下文==========
# 为需要运行时上下文的工具注入上下文
for t in tools:
if hasattr(t, 'tool_instance') and hasattr(t.tool_instance, '_is_openclaw'):
if t.tool_instance._is_openclaw:
t.tool_instance._user_id = user_id or "anonymous"
t.tool_instance._conversation_id = (
str(conversation_id) if conversation_id else None)
if processed_files:
t.tool_instance._uploaded_files = processed_files
logger.info(f"已注入 _uploaded_files, 数量: {len(processed_files)}")
#================= 为 OpenClaw 工具注入运行时上下文结束==========
if hasattr(t, 'tool_instance') and hasattr(t.tool_instance, 'set_runtime_context'):
t.tool_instance.set_runtime_context(
user_id=user_id or "anonymous",
conversation_id=str(conversation_id) if conversation_id else None,
uploaded_files=processed_files or []
)
# 7. 知识库检索
context = None
@@ -900,18 +897,14 @@ class AgentRunService:
multimodal_service = MultimodalService(self.db, model_info)
processed_files = await multimodal_service.process_files(files)
logger.info(f"处理了 {len(processed_files)} 个文件provider={provider}")
#============为 OpenClaw 工具注入会话session======
# 为 OpenClaw 工具注入运行时上下文
# 为需要运行时上下文的工具注入上下文
for t in tools:
if hasattr(t, 'tool_instance') and hasattr(t.tool_instance, '_is_openclaw'):
if t.tool_instance._is_openclaw:
t.tool_instance._user_id = user_id or "anonymous"
t.tool_instance._conversation_id = (
str(conversation_id) if conversation_id else None)
# 注入用户上传的文件
if processed_files:
t.tool_instance._uploaded_files = processed_files
#============为 OpenClaw 工具注入会话session======
if hasattr(t, 'tool_instance') and hasattr(t.tool_instance, 'set_runtime_context'):
t.tool_instance.set_runtime_context(
user_id=user_id or "anonymous",
conversation_id=str(conversation_id) if conversation_id else None,
uploaded_files=processed_files or []
)
# 7. 知识库检索
context = None