Rebuild graph edges on changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/ai-utils",
|
||||
"version": "1.4.3",
|
||||
"version": "1.4.4",
|
||||
"description": "AI Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -273,8 +273,6 @@ ${a.system}`,
|
||||
promise = (async () => {
|
||||
let tools: AiTool[] = options.tools || this.ai.options.llm?.tools || [];
|
||||
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 || [];
|
||||
if(message) history.push({role: 'user', content: message, timestamp: Date.now()});
|
||||
|
||||
@@ -330,7 +328,8 @@ ${r.description}
|
||||
${r.content}
|
||||
`).join('\n---\n')}
|
||||
` : ''}${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());
|
||||
}
|
||||
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'});
|
||||
|
||||
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')});
|
||||
let resp = await request;
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ export class MemoryCache {
|
||||
|
||||
add(memory: Memory): void {
|
||||
this.memories.push(memory);
|
||||
rebuildGraph(this.memories);
|
||||
this.rebuild();
|
||||
}
|
||||
|
||||
@@ -53,6 +54,7 @@ export class MemoryCache {
|
||||
} else {
|
||||
this.memories.push(memory);
|
||||
}
|
||||
rebuildGraph(this.memories);
|
||||
this.rebuild();
|
||||
}
|
||||
|
||||
@@ -60,6 +62,7 @@ export class MemoryCache {
|
||||
const idx = this.memories.findIndex(m => m.name === name);
|
||||
if (idx !== -1) {
|
||||
this.memories.splice(idx, 1);
|
||||
rebuildGraph(this.memories);
|
||||
this.rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user