From e119ffbcf6b32edee6790b012adbcd68257bf426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B4=AB=E5=BD=B1233?= Date: Wed, 24 Jun 2026 14:55:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20memory=20=E5=B7=A5=E5=85=B7=20descriptio?= =?UTF-8?q?n=20=E5=A2=9E=E5=BC=BA=20=E2=80=94=20=E6=AF=8F=E7=A7=8D=20actio?= =?UTF-8?q?n=20=E7=BB=99=E5=87=BA=E5=AE=8C=E6=95=B4=20JSON=20=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=20+=20=E5=8F=82=E6=95=B0=E6=A0=87=E6=B3=A8=20REQUIRED?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - description 中为 search/add/replace/remove/read_all 提供完整 JSON 格式示例 - 参数 description 加 [action REQUIRED] 前缀标注依赖性 - 错误提示改为含示例 JSON 的完整格式,帮助模型快速修正 --- src/renderer/services/tool-registry.ts | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/renderer/services/tool-registry.ts b/src/renderer/services/tool-registry.ts index db26176..915b64a 100644 --- a/src/renderer/services/tool-registry.ts +++ b/src/renderer/services/tool-registry.ts @@ -357,20 +357,27 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [ type: 'function', function: { name: 'memory', - description: 'Manage agent memories stored in MEMORY.md in the workspace. Supports: search (keyword search across all entries), add (append new entry with auto-generated ID), replace (substring match replace), remove (substring match delete), read_all (read all entries). Memories are automatically injected into system prompt on new conversations.', + description: `Manage agent memories stored in MEMORY.md. Usage by action: +- search: {"action":"search","query":"keywords","limit":8} +- add: {"action":"add","type":"fact","content":"the memory content","importance":8,"tags":["tag1","tag2"]} ← type and content are REQUIRED for add! +- replace: {"action":"replace","old_text":"unique substring","new_content":"replacement"} +- remove: {"action":"remove","old_text":"unique substring"} +- read_all: {"action":"read_all"} + +CRITICAL: For add action, you MUST include both "type" (fact/preference/rule) and "content" fields. If you omit them, the call will fail.`, parameters: { type: 'object', required: ['action'], properties: { - action: { type: 'string', enum: ['search', 'add', 'replace', 'remove', 'read_all'], description: 'Action: search=keyword match search, add=append entry, replace=find by old_text and replace, remove=find by old_text and delete, read_all=return all entries.' }, - query: { type: 'string', description: 'Search query for search action.' }, - limit: { type: 'integer', description: 'Max results for search. Default: 8.' }, - type: { type: 'string', enum: ['fact', 'preference', 'rule'], description: 'Memory type for add. fact=about user, preference=user preference, rule=must follow.' }, - content: { type: 'string', description: 'Memory content for add. Concise and specific.' }, - importance: { type: 'integer', description: 'Importance 1-10 for add. Default: 5.' }, - tags: { type: 'array', items: { type: 'string' }, description: 'Tags for add. 2-5 keywords for search matching.' }, - old_text: { type: 'string', description: 'Unique substring to find the entry for replace/remove.' }, - new_content: { type: 'string', description: 'New content for replace action.' } + action: { type: 'string', enum: ['search', 'add', 'replace', 'remove', 'read_all'], description: 'Which operation to perform.' }, + query: { type: 'string', description: '[search] Keywords to search for.' }, + limit: { type: 'integer', description: '[search] Max results. Default: 8.' }, + type: { type: 'string', enum: ['fact', 'preference', 'rule'], description: '[add REQUIRED] Memory type. fact=user info, preference=user preference, rule=behavior rule.' }, + content: { type: 'string', description: '[add REQUIRED, replace] Memory text. Keep it concise (8-100 chars).' }, + importance: { type: 'integer', description: '[add] Priority 1-10. Default: 5. Use 8+ for critical info.' }, + tags: { type: 'array', items: { type: 'string' }, description: '[add] 2-5 keywords for search matching.' }, + old_text: { type: 'string', description: '[replace, remove REQUIRED] Unique substring to identify the entry.' }, + new_content: { type: 'string', description: '[replace REQUIRED] New text to replace with.' } } } } @@ -788,8 +795,8 @@ export async function executeTool(toolName: string, args: Record