JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(tools): Fix the send_file_to_user tool to delete first and then add dynamically
wncbdj2e9ec7a491f3
diff --git a/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py b/jiuwenswarm/agents/harness/common/tools/send_file_to_user.pyindex 3ec523e5f6..cab6369026 100644--- a/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py+++ b/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py@@ -54,6 +54,28 @@ class SendFileToolkit:bool(self._request_metadata),)+ def update_runtime_context(+ self,+ *,+ request_id: str,+ session_id: str,+ channel_id: str,+ metadata: dict[str, Any] | None = None,+ ) -> None:+ """Update per-request runtime context without recreating the toolkit/tool.+ """+ self.request_id = request_id+ self.session_id = session_id+ self.channel_id = channel_id+ self._request_metadata = dict(metadata) if metadata else None+ logger.debug(+ "[SendFileToolkit] update_runtime_context request_id=%s session_id=%s channel_id=%s has_metadata=%s",+ request_id,+ session_id,+ channel_id,+ bool(self._request_metadata),+ )+async def send_file(self, abs_file_path_list: Union[List[str], str]) -> str:"""Send files to user.@@ -189,7 +211,6 @@ class SendFileToolkit:Returns:List of tools for sending files."""- session_id = self.session_iddef make_tool(name: str,diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.pyindex 4eec5a9183..163e11dd39 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py@@ -548,6 +548,7 @@ class JiuWenClawDeepAdapter:self._auto_harness_service: Optional[AutoHarnessService] = Noneself._dreaming_started = Falseself._dreaming_mode: str = "agent"+ self._send_file_toolkit: SendFileToolkit | None = Nonedef set_skill_manager(self, skill_manager: SkillManager) -> None:"""Inject shared SkillManager from facade for tool reuse."""@@ -2995,19 +2996,29 @@ class JiuWenClawDeepAdapter:config_base.get("channels", {}).get(channel, {}).get("send_file_allowed", False))if send_file_enabled and request_id and session_id:- # 先卸载上一次请求遗留的 send_file 工具- for existing in list(self._instance.ability_manager.list() or []):- if getattr(existing, "name", "").startswith("send_file_to_user"):- self._instance.ability_manager.remove(existing.name)- send_file_toolkit = SendFileToolkit(- request_id=request_id,- session_id=session_id,- channel_id=_CRON_TOOL_CHANNEL_ID.get(),- metadata=_CRON_TOOL_METADATA.get(),+ channel_for_tool = _CRON_TOOL_CHANNEL_ID.get()+ metadata_for_tool = _CRON_TOOL_METADATA.get()+ already_registered = any(+ getattr(existing, "name", "").startswith("send_file_to_user")+ for existing in (self._instance.ability_manager.list() or []))- for sf_tool in send_file_toolkit.get_tools():- Runner.resource_mgr.add_tool(sf_tool)- self._instance.ability_manager.add(sf_tool.card)+ if not already_registered:+ self._send_file_toolkit = SendFileToolkit(+ request_id=request_id,+ session_id=session_id,+ channel_id=channel_for_tool,+ metadata=metadata_for_tool,+ )+ for sf_tool in self._send_file_toolkit.get_tools():+ Runner.resource_mgr.add_tool(sf_tool)+ self._instance.ability_manager.add(sf_tool.card)+ else:+ self._send_file_toolkit.update_runtime_context(+ request_id=request_id,+ session_id=session_id,+ channel_id=channel_for_tool,+ metadata=metadata_for_tool,+ )def _refresh_acp_runtime_tools(self,