diff --git a/package.json b/package.json index f97fe6e..6d39719 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/llm.ts b/src/llm.ts index 242ef08..1ed9fd8 100644 --- a/src/llm.ts +++ b/src/llm.ts @@ -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; diff --git a/src/memory.ts b/src/memory.ts index 22d9223..bc146c0 100644 --- a/src/memory.ts +++ b/src/memory.ts @@ -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(); } }