Rebuild graph edges on changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -273,8 +273,6 @@ ${a.system}`,
|
|||||||
promise = (async () => {
|
promise = (async () => {
|
||||||
let tools: AiTool[] = options.tools || this.ai.options.llm?.tools || [];
|
let tools: AiTool[] = options.tools || this.ai.options.llm?.tools || [];
|
||||||
const prompts: string[] = [];
|
const prompts: string[] = [];
|
||||||
// `history` is the single source of truth from here on - mutated in place by
|
|
||||||
// this call AND by any nested/delegated agent calls sharing the same array
|
|
||||||
let history = options.history || [];
|
let history = options.history || [];
|
||||||
if(message) history.push({role: 'user', content: message, timestamp: Date.now()});
|
if(message) history.push({role: 'user', content: message, timestamp: Date.now()});
|
||||||
|
|
||||||
@@ -330,7 +328,8 @@ ${r.description}
|
|||||||
${r.content}
|
${r.content}
|
||||||
`).join('\n---\n')}
|
`).join('\n---\n')}
|
||||||
` : ''}${listed.length ? `
|
` : ''}${listed.length ? `
|
||||||
Also relevant but not preloaded (use \`memory_recall\`): ${listed.map(r => r.name).join(', ')}
|
Additional relevant memories (use \`memory_recall\`):
|
||||||
|
${listed.map(r => r.name).join(', ')}
|
||||||
` : ''}`.trim());
|
` : ''}`.trim());
|
||||||
}
|
}
|
||||||
if(mem.tool) tools.push(this.memoryManager.tools.read(mem.memory));
|
if(mem.tool) tools.push(this.memoryManager.tools.read(mem.memory));
|
||||||
@@ -345,8 +344,6 @@ Also relevant but not preloaded (use \`memory_recall\`): ${listed.map(r => r.nam
|
|||||||
if(aborted) throw Object.assign(new Error('Aborted'), {name: 'AbortError'});
|
if(aborted) throw Object.assign(new Error('Aborted'), {name: 'AbortError'});
|
||||||
|
|
||||||
prompts.unshift(options.system || this.ai.options.llm?.system || '');
|
prompts.unshift(options.system || this.ai.options.llm?.system || '');
|
||||||
// Message already appended to shared `history` above - pass '' so the provider
|
|
||||||
// doesn't push a duplicate user turn
|
|
||||||
request = this.models[m].ask('', {...options, tools, system: prompts.filter(Boolean).join('\n\n')});
|
request = this.models[m].ask('', {...options, tools, system: prompts.filter(Boolean).join('\n\n')});
|
||||||
let resp = await request;
|
let resp = await request;
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export class MemoryCache {
|
|||||||
|
|
||||||
add(memory: Memory): void {
|
add(memory: Memory): void {
|
||||||
this.memories.push(memory);
|
this.memories.push(memory);
|
||||||
|
rebuildGraph(this.memories);
|
||||||
this.rebuild();
|
this.rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ export class MemoryCache {
|
|||||||
} else {
|
} else {
|
||||||
this.memories.push(memory);
|
this.memories.push(memory);
|
||||||
}
|
}
|
||||||
|
rebuildGraph(this.memories);
|
||||||
this.rebuild();
|
this.rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +62,7 @@ export class MemoryCache {
|
|||||||
const idx = this.memories.findIndex(m => m.name === name);
|
const idx = this.memories.findIndex(m => m.name === name);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
this.memories.splice(idx, 1);
|
this.memories.splice(idx, 1);
|
||||||
|
rebuildGraph(this.memories);
|
||||||
this.rebuild();
|
this.rebuild();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user