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: 统一记忆文件的路径,修复路径描述不一致导致工具调用失败的问题
hzx99f0948c39f050
diff --git a/jiuwenclaw/agentserver/prompt_builder.py b/jiuwenclaw/agentserver/prompt_builder.pyindex 9e28eb2106..3aafaac834 100644--- a/jiuwenclaw/agentserver/prompt_builder.py+++ b/jiuwenclaw/agentserver/prompt_builder.py@@ -59,15 +59,15 @@ def _memory_prompt(language: str, is_cron: bool = False) -> str:### 存储层级划分- **会话日志:** `memory/YYYY-MM-DD.md`(存储当日的所有交互记录,包括对话内容、情景记忆和任务指令。支持增量追加,确保每次操作、用户指令和情景变化都被记录。)-- **用户画像:** `USER.md`(稳定的身份属性与偏好信息)-- **知识沉淀:** `MEMORY.md`(经筛选提炼的长期背景知识,非原始流水账))+- **用户画像:** `memory/USER.md`(稳定的身份属性与偏好信息)+- **知识沉淀:** `memory/MEMORY.md`(经筛选提炼的长期背景知识,非原始流水账))#### 历史检索机制**响应任何消息前,建议执行:**-1. **身份确认** — 读取 `USER.md` 确认服务对象+1. **身份确认** — 读取 `memory/USER.md` 确认服务对象2. **上下文获取** — 读取 `memory/YYYY-MM-DD.md`(当日 + 前一日)-3. **长期记忆加载** — **仅限主会话:** 读取 `MEMORY.md`+3. **长期记忆加载** — **仅限主会话:** 读取 `memory/MEMORY.md`4. **历史信息检索(强制)** — **回答任何关于历史事件、日期、人物、过去对话的问题前,必须先调用 `memory_search` 工具检索相关记忆**- 搜索查询应包含问题中的关键信息(人名、日期、事件关键词)- 如果搜索结果不足,尝试用不同的关键词再次搜索@@ -107,15 +107,15 @@ def _memory_prompt(language: str, is_cron: bool = False) -> str:### Storage Hierarchy- **Session Log:** `memory/YYYY-MM-DD.md` (All interaction records for the day, including conversation content, episodic memory, and task instructions. Supports incremental appending to ensure every operation, user instruction, and contextual change is recorded.)-- **User Profile:** `USER.md` (Stable identity attributes and preference information.)-- **Knowledge Repository:** `MEMORY.md` (Filtered and refined long-term background knowledge, not raw logs.)+- **User Profile:** `memory/USER.md` (Stable identity attributes and preference information.)+- **Knowledge Repository:** `memory/MEMORY.md` (Filtered and refined long-term background knowledge, not raw logs.)#### History Retrieval Mechanism**Before responding to any message, it is recommended to execute:**-1. Read `USER.md` — Confirm the user being served+1. Read `memory/USER.md` — Confirm the user being served2. Read `memory/YYYY-MM-DD.md` (today + previous day) to get context-3. **Main session only:** Read `MEMORY.md`+3. **Main session only:** Read `memory/MEMORY.md`4. **Before answering questions about historical events:** Must first call `memory_search` tool to retrieve historical memories**Note:** In cron job mode, only reading and searching memories is supported. Writing or modifying memory files is not allowed.@@ -166,14 +166,14 @@ def _memory_prompt(language: str, is_cron: bool = False) -> str:### 存储层级划分- **会话日志:** `memory/YYYY-MM-DD.md`(存储当日的所有交互记录,包括对话内容、情景记忆和任务指令。支持增量追加,确保每次操作、用户指令和情景变化都被记录。)-- **用户画像:** `USER.md`(稳定的身份属性与偏好信息)-- **知识沉淀:** `MEMORY.md`(经筛选提炼的长期背景知识,非原始流水账)+- **用户画像:** `memory/USER.md`(稳定的身份属性与偏好信息)+- **知识沉淀:** `memory/MEMORY.md`(经筛选提炼的长期背景知识,非原始流水账)### 核心操作规范- 会话本身不具备记忆能力,文件系统是唯一的信息载体。需持久化的内容务必写入文件- **路径限制:** 记忆工具(write_memory/edit_memory/read_memory)仅能操作 memory/ 目录下的文件,其他路径会被拒绝-- 更新 USER.md 或 MEMORY.md 时,必须先读取现有内容再执行修改+- 更新 memory/USER.md 或 memory/MEMORY.md 时,必须先读取现有内容再执行修改- **字段唯一性约束:** 每个字段仅允许出现一次。已存在字段通过 `edit_memory` 更新,新字段通过 `write_memory` 追加### 信息采集、存储操作与记录@@ -181,13 +181,13 @@ def _memory_prompt(language: str, is_cron: bool = False) -> str:对话过程中,发现有价值的信息时,应该立即进行分类、存储,并及时记录,确保不拖延记录过程:1. **用户画像信息(user_profile)**:记录用户的身份信息、偏好、习惯等稳定属性,比如用户的职业、兴趣、工作模式、喜好、不满等。- - **存储**:写入 `USER.md`。+ - **存储**:写入 `memory/USER.md`。2. **情景记忆信息(episodic_memory)**:记录用户经历的具体事件或重要决策,比如用户要求完成的任务、描述的项目进展、某次事件等。- **存储**:写入 `memory/YYYY-MM-DD.md`。3. **语义记忆信息(semantic_memory)**:存储背景知识、技术细节、工具相关的本地配置(SSH、摄像头等)等长期有效信息,比如项目技术栈、工具的配置等。- - **存储**:写入 `MEMORY.md`。+ - **存储**:写入 `memory/MEMORY.md`。4. **摘要记忆(summary_memory)**:提炼对话中的关键信息,帮助后续快速回顾,比如对话中形成的重要决策、核心结论、讨论的要点等。- **存储**:写入 `memory/YYYY-MM-DD.md`。@@ -205,9 +205,9 @@ def _memory_prompt(language: str, is_cron: bool = False) -> str:#### 历史检索机制**响应任何消息前,建议执行:**-1. **身份确认** — 读取 `USER.md` 确认服务对象+1. **身份确认** — 读取 `memory/USER.md` 确认服务对象2. **上下文获取** — 读取 `memory/YYYY-MM-DD.md`(当日 + 前一日)-3. **长期记忆加载** — **仅限主会话:** 读取 `MEMORY.md`+3. **长期记忆加载** — **仅限主会话:** 读取 `memory/MEMORY.md`4. **历史信息检索(强制)** — **回答任何关于历史事件、日期、人物、过去对话的问题前,必须先调用 `memory_search` 工具检索相关记忆**- 搜索查询应包含问题中的关键信息(人名、日期、事件关键词)- 如果搜索结果不足,尝试用不同的关键词再次搜索@@ -244,8 +244,8 @@ def _memory_prompt(language: str, is_cron: bool = False) -> str:#### 更新规则1. 更新前必须先读取现有内容2. 合并新信息,避免全量覆盖-3. MEMORY.md 条目仅记录精炼事实,不含日期/时间戳-4. **USER.md 字段去重:** 已存在字段通过 `edit_memory` 更新,不存在字段通过 `write_memory` 追加+3. memory/MEMORY.md 条目仅记录精炼事实,不含日期/时间戳+4. **memory/USER.md 字段去重:** 已存在字段通过 `edit_memory` 更新,不存在字段通过 `write_memory` 追加""".format(today=today)sections.append(memory_mgmt_prompt)@@ -280,14 +280,14 @@ Each conversation session starts from a blank state. Cross-session information p### Storage Hierarchy- **Session Log:** `memory/YYYY-MM-DD.md` (All interaction records for the day, including conversation content, episodic memory, and task instructions. Supports incremental appending to ensure every operation, user instruction, and contextual change is recorded.)-- **User Profile:** `USER.md` (Stable identity attributes and preference information.)-- **Knowledge Repository:** `MEMORY.md` (Filtered and refined long-term background knowledge, not raw logs.)+- **User Profile:** `memory/USER.md` (Stable identity attributes and preference information.)+- **Knowledge Repository:** `memory/MEMORY.md` (Filtered and refined long-term background knowledge, not raw logs.)### Core Operation Guidelines- The session itself has no memory; the file system is the only carrier. Content requiring persistence must be written to files.- **Path Restriction:** Memory tools (write_memory/edit_memory/read_memory) can only operate on files in the `memory/` directory; other paths will be rejected.- - When updating USER.md or MEMORY.md, existing content must be read first before making modifications.+ - When updating memory/USER.md or memory/MEMORY.md, existing content must be read first before making modifications.- **Field Uniqueness Constraint:** Each field can appear only once. Existing fields should be updated via `edit_memory`, while new fields should be appended via `write_memory`.### Information Collection, Storage Operations, and Recording@@ -295,14 +295,14 @@ Each conversation session starts from a blank state. Cross-session information pWhen valuable information appears during the conversation, classify it and store it immediately. Do not delay recording:1. **User Profile Information (`user_profile`)**: Stable user attributes such as identity, preferences, habits, work style, likes/dislikes.- - **Storage**: Write to `USER.md`.+ - **Storage**: Write to `memory/USER.md`.2. **Episodic Memory (`episodic_memory`)**: Specific events or important decisions, such as assigned tasks, project progress, or notable incidents.- **Storage**: Write to `memory/YYYY-MM-DD.md`.### Operation Trail Automatic Recording (Write to Session Log)3. **Semantic Memory (`semantic_memory`)**: Long-term background knowledge, technical details, and tool-related local configs (SSH, camera, etc.).- - **Storage**: Write to `MEMORY.md`.+ - **Storage**: Write to `memory/MEMORY.md`.4. **Summary Memory (`summary_memory`)**: Distilled key points from the conversation (important decisions, core conclusions, discussion highlights).- **Storage**: Write to `memory/YYYY-MM-DD.md`.@@ -318,9 +318,9 @@ When valuable information appears during the conversation, classify it and store#### History Retrieval Mechanism**Before responding to any message, it is recommended to execute:**-""" + _en_exp_retrieve_item + """2. Read `USER.md` — Confirm the user being served+""" + _en_exp_retrieve_item + """2. Read `memory/USER.md` — Confirm the user being served3. Read `memory/YYYY-MM-DD.md` (today + previous day) to get context-4. **Main session only:** Read `MEMORY.md`+4. **Main session only:** Read `memory/MEMORY.md`5. **Historical information retrieval (mandatory):** Before answering any question about historical events, dates, people, or past conversations, you must call `memory_search` first- Search query should include key information from the question (names, dates, event keywords)- If results are insufficient, retry with different keywords@@ -361,8 +361,8 @@ Before outputting final response text, **you must call the following tools first#### Update Rules1. Must read existing content before updating2. Merge new information, avoid full overwrites-3. MEMORY.md entries should only record refined facts, without dates/timestamps-4. **USER.md Field Deduplication:** Existing fields should be updated via `edit_memory`, non-existing fields should be appended via `write_memory`+3. memory/MEMORY.md entries should only record refined facts, without dates/timestamps+4. **memory/USER.md Field Deduplication:** Existing fields should be updated via `edit_memory`, non-existing fields should be appended via `write_memory`"""sections.append(memory_mgmt_prompt)diff --git a/jiuwenclaw/agentserver/tools/memory_tools.py b/jiuwenclaw/agentserver/tools/memory_tools.pyindex bdb0891816..3c4f7f98e5 100644--- a/jiuwenclaw/agentserver/tools/memory_tools.py+++ b/jiuwenclaw/agentserver/tools/memory_tools.py@@ -29,8 +29,8 @@ def _validate_memory_path(path: str) -> tuple[bool, str]:Only allows:- memory/YYYY-MM-DD.md (date format files)- - USER.md- - MEMORY.md+ - memory/USER.md+ - memory/MEMORY.mdReturns:(is_valid, resolved_path_or_error)@@ -38,15 +38,15 @@ def _validate_memory_path(path: str) -> tuple[bool, str]:if ".." in path or path.startswith("/"):return (False, "Invalid path: directory traversal not allowed")- if path in ("USER.md", "MEMORY.md"):- return (True, f"memory/{path}")+ if path in ("memory/USER.md", "memory/MEMORY.md"):+ return (True, path)if path.startswith("memory/"):filename = path[7:]if re.match(r"^\d{4}-\d{2}-\d{2}\.md$", filename):return (True, path)- return (False, f"Path must be memory/YYYY-MM-DD.md, USER.md, or MEMORY.md. Got: {path}")+ return (False, f"Path must be memory/YYYY-MM-DD.md, memory/USER.md, or memory/MEMORY.md. Got: {path}")def set_global_memory_manager(@@ -257,11 +257,11 @@ async def write_memory(content: str,append: bool = False) -> Dict[str, Any]:- """在 memory 目录下创建或更新记忆文件。仅用于写入记忆相关内容,如 USER.md、MEMORY.md 或 memory/*.md 文件。+ """在 memory 目录下创建或更新记忆文件。仅用于写入记忆相关内容,如 memory/USER.md、memory/MEMORY.md 或 memory/*.md 文件。禁止用于创建代码文件、配置文件或其他非记忆类文件。Args:- path: 文件路径,仅允许 memory/ 目录下的文件(如 "memory/xxx.md" 或 "USER.md")+ path: 文件路径,仅允许 memory/ 目录下的文件(如 "memory/xxx.md" 或 "memory/USER.md")content: 要写入的内容append: 是否追加模式 (默认覆盖)@@ -316,7 +316,7 @@ async def edit_memory(oldText: str,newText: str) -> Dict[str, Any]:- """精确编辑 memory 目录下的文件内容。仅用于更新记忆文件(如 USER.md、MEMORY.md)。+ """精确编辑 memory 目录下的文件内容。仅用于更新记忆文件(如 memory/USER.md、memory/MEMORY.md)。oldText 必须完全匹配文件中的内容。如果 oldText 出现多次,需要更具体地指定。Args:@@ -394,7 +394,7 @@ async def read_memory(offset: Optional[int] = None,limit: Optional[int] = None) -> Dict[str, Any]:- """读取 memory 目录下的文件内容。仅用于读取记忆文件(如 USER.md、MEMORY.md 或 memory/*.md)。+ """读取 memory 目录下的文件内容。仅用于读取记忆文件(如 memory/USER.md、memory/MEMORY.md 或 memory/*.md)。Args:path: 文件路径,仅允许 memory/ 目录下的文件