dsh-plugin-agent-memory 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/docs/DETAIL.md +3 -2
- package/index.js +61 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ step as an `<agent-memory>` block, so the model sees them without any tool call.
|
|
|
9
9
|
|
|
10
10
|
The rest of the agent's team assets are available as read-only tools: `am_knowledge_resources`
|
|
11
11
|
(lists wiki and code-graph resources), `am_knowledge_call` (gets a resource's tool list, then runs
|
|
12
|
-
`explore` / `search` / `callers` / `impact` / `read_page` …), `am_skill_search` and `
|
|
12
|
+
`explore` / `search` / `callers` / `impact` / `read_page` …), `am_skill_search`, `am_skill_read`, and `am_memory_search` (on-demand L0/L1 lookup).
|
|
13
13
|
|
|
14
14
|
## Requirements
|
|
15
15
|
|
|
@@ -47,6 +47,7 @@ Open the plugin's settings page (or the panel's gear button) and set:
|
|
|
47
47
|
| `injectMemory` | Recall memories and inject them before each step (default on) |
|
|
48
48
|
| `writeMemory` | Write each turn's user message back to the expert's memory (default off) |
|
|
49
49
|
| `topK` | Max memories per recall (1–10, default 4) |
|
|
50
|
+
| `layers` | Memory layers injected each turn (default `L3,L2`, matching the official proxy) |
|
|
50
51
|
| `timeoutMs` | Per-request timeout (default 6000) |
|
|
51
52
|
| `kernelUrl` | Kernel API base for wiki / code-graph / skills (default: Hub host on port 8420) |
|
|
52
53
|
| `tools` | Register the four read-only asset tools (default on) |
|
package/docs/DETAIL.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
1. 在对话框工具行左侧点「选择专家」,展开后点右上角「设置」,直接填 `Hub 地址`、`实例 ID`、`Userkey` 并点「检测连接」;保存后写入本 profile 的 `cordis.patch.yml`(也可以手改该行)。
|
|
8
8
|
2. 「设置」旁边的「返回列表」回到团队 / agent 列表,先选团队,再选 agent;选中的专家记录在当前会话上。未选择时按钮显示「请选择专家」,且不注入任何记忆——需要默认专家时把 `defaultAgentId` 填上即可。
|
|
9
|
-
3. 每轮对话开始时,Host
|
|
10
|
-
4. 同一份团队资产还能按需取用:插件注册了 4 个只读工具 —— `am_knowledge_resources`(列出 wiki / code-graph 资源)、`am_knowledge_call`(先取该资源的工具清单,再执行 explore / search / callers / impact / read_page 等)、`am_skill_search`(检索技能)、`am_skill_read
|
|
9
|
+
3. 每轮对话开始时,Host 半侧按配置的 `layers` 检索该 agent 的记忆块(默认 `L3,L2`,与官方 proxy 一致——官方每轮只注入 L3 persona 与 L2 场景索引,L0/L1 改由工具按需取,以保护 prompt cache),把命中的记忆以 `<agent-memory>` 段落追加到该 step 的消息里。
|
|
10
|
+
4. 同一份团队资产还能按需取用:插件注册了 4 个只读工具 —— `am_knowledge_resources`(列出 wiki / code-graph 资源)、`am_knowledge_call`(先取该资源的工具清单,再执行 explore / search / callers / impact / read_page 等)、`am_skill_search`(检索技能)、`am_skill_read`(读技能正文)、`am_memory_search`(按需查 L1/L0 等分层记忆)。工具默认绑定当前会话选中的专家所在团队。
|
|
11
11
|
|
|
12
12
|
## 配置项
|
|
13
13
|
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
| `injectMemory` | 关闭后只保留选择器,不注入记忆 |
|
|
21
21
|
| `writeMemory` | 打开后每轮结束时把该轮用户消息写回专家记忆块(插件默认关闭,本实例安装配置里已开启) |
|
|
22
22
|
| `topK` | 每层最多取回的记忆条数(1–10) |
|
|
23
|
+
| `layers` | 每轮预注入的记忆层,逗号分隔,默认 `L3,L2`;需要更细的原文可加 `L1,L0`,或用 `am_memory_search` 按需查 |
|
|
23
24
|
| `timeoutMs` | 单次 Hub 请求超时 |
|
|
24
25
|
| `kernelUrl` | 内核 API 地址(知识库 / code-graph / 技能),默认按 Hub 主机名 + `8420` 推断;显式填写更稳妥 |
|
|
25
26
|
| `tools` | 是否注册上述 4 个资产工具(默认开) |
|
package/index.js
CHANGED
|
@@ -36,6 +36,10 @@ export const Config = z.object({
|
|
|
36
36
|
injectMemory: z.boolean().default(true).description('每轮对话前召回该专家的记忆并注入上下文'),
|
|
37
37
|
writeMemory: z.boolean().default(false).description('每轮对话结束后把用户消息写回记忆库'),
|
|
38
38
|
topK: z.number().min(1).max(10).step(1).default(4).description('每次召回的记忆条数'),
|
|
39
|
+
layers: z
|
|
40
|
+
.string()
|
|
41
|
+
.default('L3,L2')
|
|
42
|
+
.description('每轮预注入的记忆层,逗号分隔按顺序查;默认 L3,L2(与官方一致)。L0/L1 更适合用 am_memory_search 按需取'),
|
|
39
43
|
timeoutMs: z.number().min(1000).step(500).default(6000).description('单次 Hub 请求超时(毫秒)'),
|
|
40
44
|
refreshMs: z
|
|
41
45
|
.number()
|
|
@@ -92,6 +96,19 @@ function writeBackText(text) {
|
|
|
92
96
|
.trim();
|
|
93
97
|
}
|
|
94
98
|
|
|
99
|
+
/**
|
|
100
|
+
* The per-turn injection layers. Official proxy injects L3 (persona) + L2 (scene index)
|
|
101
|
+
* only; L0/L1 stay on demand through tools, which protects the prompt cache.
|
|
102
|
+
*/
|
|
103
|
+
function parseLayers(value) {
|
|
104
|
+
const allowed = new Set(LAYERS);
|
|
105
|
+
const picked = String(value ?? '')
|
|
106
|
+
.split(/[,\s]+/)
|
|
107
|
+
.map((item) => item.trim().toUpperCase())
|
|
108
|
+
.filter((item) => allowed.has(item));
|
|
109
|
+
return picked.length > 0 ? picked : ['L3', 'L2'];
|
|
110
|
+
}
|
|
111
|
+
|
|
95
112
|
function normalizeConfig(config) {
|
|
96
113
|
const value = config ?? {};
|
|
97
114
|
return {
|
|
@@ -102,6 +119,7 @@ function normalizeConfig(config) {
|
|
|
102
119
|
injectMemory: value.injectMemory !== false,
|
|
103
120
|
writeMemory: value.writeMemory === true,
|
|
104
121
|
topK: Number.isFinite(value.topK) ? Math.max(1, Math.min(10, value.topK)) : 4,
|
|
122
|
+
layers: parseLayers(value.layers),
|
|
105
123
|
timeoutMs: Number.isFinite(value.timeoutMs) ? Math.max(1000, value.timeoutMs) : 6000,
|
|
106
124
|
refreshMs: Number.isFinite(value.refreshMs) ? Math.max(3000, Math.min(600000, value.refreshMs)) : DEFAULT_REFRESH_MS,
|
|
107
125
|
kernelUrl: typeof value.kernelUrl === 'string' ? value.kernelUrl.trim().replace(/\/+$/, '') : '',
|
|
@@ -242,18 +260,20 @@ export function apply(ctx, config) {
|
|
|
242
260
|
return match.id;
|
|
243
261
|
}
|
|
244
262
|
|
|
245
|
-
async function recall(selection, query) {
|
|
263
|
+
async function recall(selection, query, overrides = {}) {
|
|
246
264
|
const block = await blockId(selection.teamId, selection.agentId);
|
|
265
|
+
const layers = overrides.layers ?? settings.layers;
|
|
266
|
+
const limit = overrides.limit ?? settings.topK;
|
|
247
267
|
const collected = [];
|
|
248
268
|
const seen = new Set();
|
|
249
|
-
for (const layer of
|
|
269
|
+
for (const layer of layers) {
|
|
250
270
|
let data;
|
|
251
271
|
try {
|
|
252
272
|
data = await chatMemory('search', {
|
|
253
273
|
block_id: block,
|
|
254
274
|
layer,
|
|
255
275
|
query,
|
|
256
|
-
limit
|
|
276
|
+
limit,
|
|
257
277
|
});
|
|
258
278
|
} catch {
|
|
259
279
|
continue;
|
|
@@ -264,9 +284,9 @@ export function apply(ctx, config) {
|
|
|
264
284
|
if (body === '' || seen.has(body)) continue;
|
|
265
285
|
seen.add(body);
|
|
266
286
|
collected.push({ layer, body });
|
|
267
|
-
if (collected.length >=
|
|
287
|
+
if (collected.length >= limit * 2) break;
|
|
268
288
|
}
|
|
269
|
-
if (collected.length >=
|
|
289
|
+
if (collected.length >= limit) break;
|
|
270
290
|
}
|
|
271
291
|
return collected;
|
|
272
292
|
}
|
|
@@ -589,6 +609,40 @@ export function apply(ctx, config) {
|
|
|
589
609
|
},
|
|
590
610
|
}),
|
|
591
611
|
);
|
|
612
|
+
disposers.push(
|
|
613
|
+
tools.register({
|
|
614
|
+
name: 'am_memory_search',
|
|
615
|
+
description:
|
|
616
|
+
'按需检索当前专家的分层记忆。默认查 L1(原子记忆)与 L0(原始对话);需要稳定结论时也可传 L2/L3。每轮预注入会使用的层由配置 layers 决定(默认 L3,L2),这里用于补充更细的细节。',
|
|
617
|
+
parameters: {
|
|
618
|
+
type: 'object',
|
|
619
|
+
properties: {
|
|
620
|
+
query: { type: 'string', description: '检索问题或关键词。' },
|
|
621
|
+
layers: { type: 'string', description: '层,逗号分隔,默认 L1,L0;可用 L3,L2,L1,L0。' },
|
|
622
|
+
limit: { type: 'number', description: '每层返回条数,1-10,默认 5。' },
|
|
623
|
+
},
|
|
624
|
+
required: ['query'],
|
|
625
|
+
additionalProperties: false,
|
|
626
|
+
},
|
|
627
|
+
output: textOutput,
|
|
628
|
+
isConcurrencySafe: () => true,
|
|
629
|
+
async execute(args, exec) {
|
|
630
|
+
const query = String(args.query ?? '').trim();
|
|
631
|
+
if (query === '') throw new Error('query 不能为空');
|
|
632
|
+
const layers = parseLayers(
|
|
633
|
+
typeof args.layers === 'string' && args.layers.trim() !== '' ? args.layers : 'L1,L0',
|
|
634
|
+
);
|
|
635
|
+
const limit = Number.isFinite(args.limit) ? Math.max(1, Math.min(10, args.limit)) : 5;
|
|
636
|
+
const scope = await toolScope(exec);
|
|
637
|
+
if (!scope.agentId) throw new Error('当前会话还没有选专家:请先在「请选择专家」里选一个,再检索它的记忆');
|
|
638
|
+
const hits = (await recall(scope, query, { layers, limit })).slice(0, limit);
|
|
639
|
+
if (hits.length === 0) {
|
|
640
|
+
return `在「${scope.teamName}」/ ${scope.agentId || '默认 agent'} 的 ${layers.join('/')} 层没有命中。`;
|
|
641
|
+
}
|
|
642
|
+
return hits.map((hit, index) => `${index + 1}. (${hit.layer}) ${hit.body}`).join('\n');
|
|
643
|
+
},
|
|
644
|
+
}),
|
|
645
|
+
);
|
|
592
646
|
disposers.push(
|
|
593
647
|
tools.register({
|
|
594
648
|
name: 'am_skill_search',
|
|
@@ -772,6 +826,7 @@ export function apply(ctx, config) {
|
|
|
772
826
|
injectMemory: settings.injectMemory,
|
|
773
827
|
writeMemory: settings.writeMemory,
|
|
774
828
|
topK: settings.topK,
|
|
829
|
+
layers: settings.layers.join(','),
|
|
775
830
|
refreshMs: settings.refreshMs,
|
|
776
831
|
kernelUrl: kernelBase(),
|
|
777
832
|
tools: settings.tools,
|
|
@@ -870,6 +925,7 @@ export function apply(ctx, config) {
|
|
|
870
925
|
if (typeof body.injectMemory === 'boolean') patch.injectMemory = body.injectMemory;
|
|
871
926
|
if (typeof body.writeMemory === 'boolean') patch.writeMemory = body.writeMemory;
|
|
872
927
|
if (Number.isFinite(body.topK)) patch.topK = Math.max(1, Math.min(10, body.topK));
|
|
928
|
+
if (typeof body.layers === 'string') patch.layers = parseLayers(body.layers).join(',');
|
|
873
929
|
if (Number.isFinite(body.timeoutMs)) patch.timeoutMs = Math.max(1000, body.timeoutMs);
|
|
874
930
|
if (Number.isFinite(body.refreshMs)) {
|
|
875
931
|
patch.refreshMs = Math.max(3000, Math.min(600000, body.refreshMs));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-agent-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Tencent agent-memory integration: pick a team agent as an expert at the composer, recall its memories into each turn, and expose its wiki, code-graph and skill assets as tools.",
|
|
6
6
|
"license": "MIT",
|