41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
import { learningToolReason } from "../tool-reason.js";
|
|
import { tool } from "../tool.js";
|
|
import { getInternalBridgeConfig } from "../internalBridge.js";
|
|
|
|
export default tool({
|
|
description:
|
|
"管理长期有效的用户偏好或项目事实。支持 add/list/replace/remove。add 前必须先对同 scope 执行 list 并阅读现有记忆,再决定 add、replace 或 remove;不要跳过读取直接新增。禁止写入 token、password、secret、system prompt 或一次性上下文。scope 仅允许 'user' 或 'workspace'。",
|
|
args: {
|
|
action: tool.schema
|
|
.enum(["add", "list", "replace", "remove"])
|
|
.describe("Memory operation to perform."),
|
|
reason: learningToolReason,
|
|
scope: tool.schema
|
|
.string()
|
|
.describe(
|
|
"Required exact keyword. Use only 'user' for user-level durable preferences/constraints, or 'workspace' for project/environment durable facts. Do not use 'project', Chinese labels, or any alias.",
|
|
),
|
|
content: tool.schema
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
"The durable fact or preference to remember, written as one concise sentence.",
|
|
),
|
|
target_id: tool.schema
|
|
.string()
|
|
.optional()
|
|
.describe("Stable memory entry id used by replace/remove."),
|
|
},
|
|
async execute(args, context) {
|
|
const { baseUrl, internalToken } = getInternalBridgeConfig();
|
|
const response = await fetch(`${baseUrl}/internal/tools/memory-manager`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json", "x-agent-internal-token": internalToken },
|
|
body: JSON.stringify({ session_id: context.sessionID, input: args }),
|
|
});
|
|
const text = await response.text();
|
|
if (!response.ok) throw new Error(`learning tool failed (${response.status}): ${text}`);
|
|
return text;
|
|
},
|
|
});
|