refactor(memory): run agent recall, memory tools and the server on the memory contract (P1.5)
- Orchestrator, memory tools, context loader and pattern write-back use a MemoryStore and a workspace scope instead of MindDB layers; the knowledge graph tools, cognify, memory linker and feedback handler are gone (graph hidden in v1, ADR-0002). - The server opens one mem0 store in <dataDir>/memory/, embedded by the in-process model on first use, and extracts facts about the user in the background with the model the user chose (memoryExtraction setting). - Legacy .mind memories are copied into the store once, in the background; the legacy files are only read. - Weaver consolidation, harvest, wiki, memory import, memory lanes, vector backfill and index reconciliation are removed; agent runs, loops, sub-agent results, connector fetch and the failed-turn capture write through the contract. Workspace sessions no longer hold a mind handle. - FileIndexer and the install audit move to waggle.db; recall date helpers and the reranker are copied into core. - The CLI REPL opens the same memory store.
This commit is contained in:
@@ -4,7 +4,8 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import type { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
||||
import { z } from 'zod';
|
||||
import { evaluateExternalMemoryIngress, FrameStore, SessionStore } from '@waggle/core';
|
||||
import { evaluateExternalMemoryIngress } from '@waggle/core';
|
||||
import { recordRunResult } from '../run-memory.js';
|
||||
import {
|
||||
classifyRateLimitError,
|
||||
detectInstalledTools,
|
||||
@@ -613,7 +614,7 @@ function finalizeExternalRoom(
|
||||
|
||||
function mergeMemoryRefs(refs: CollaborationRunMemoryRefs[]): CollaborationRunMemoryRefs {
|
||||
const personalFrameIds = [...new Set(refs.flatMap((ref) => ref.personalFrameIds))];
|
||||
const workspaceFrameIds: Record<string, number[]> = {};
|
||||
const workspaceFrameIds: Record<string, string[]> = {};
|
||||
for (const ref of refs) {
|
||||
for (const [workspaceId, ids] of Object.entries(ref.workspaceFrameIds)) {
|
||||
workspaceFrameIds[workspaceId] = [...new Set([...(workspaceFrameIds[workspaceId] ?? []), ...ids])];
|
||||
@@ -947,61 +948,20 @@ async function recordResultToMinds(
|
||||
const safeSummary = durableIngress.action === 'allow'
|
||||
? input.result.summary
|
||||
: `[Quarantined external result: ${durableIngress.scan.flags.join(', ') || 'injection risk'}]`;
|
||||
const metadata = JSON.stringify({
|
||||
runId: input.run.id,
|
||||
roomId: input.run.roomId,
|
||||
return recordRunResult(server.memory, {
|
||||
workspaceId: input.run.workspaceId,
|
||||
toolId: input.run.executor.toolId,
|
||||
externalSessionId: safeExternalSessionId(input.result.sessionId) ?? null,
|
||||
...(input.run.attribution ?? {}),
|
||||
injection: originalSummaryScan,
|
||||
personalText: `[External agent run]\nRun: ${input.run.id}\nWorkspace: ${input.run.workspaceId}\nTool: ${input.run.executor.toolId}\nStatus: ${input.result.status}\nSummary: ${safeSummary.slice(0, 1_000)}`,
|
||||
workspaceText: `[External agent result]\nRun: ${input.run.id}\nTool: ${input.run.executor.toolId}\nTask:\n${input.prompt}\n\nResult:\n${safeSummary.slice(0, RESULT_MEMORY_LIMIT)}`,
|
||||
metadata: {
|
||||
runId: input.run.id,
|
||||
roomId: input.run.roomId,
|
||||
workspaceId: input.run.workspaceId,
|
||||
toolId: input.run.executor.toolId,
|
||||
externalSessionId: safeExternalSessionId(input.result.sessionId) ?? null,
|
||||
...(input.run.attribution ?? {}),
|
||||
injection: originalSummaryScan,
|
||||
},
|
||||
});
|
||||
const personalFrameIds: number[] = [];
|
||||
const workspaceFrameIds: Record<string, number[]> = {};
|
||||
let personalOk = false;
|
||||
let workspaceOk = false;
|
||||
|
||||
try {
|
||||
const personal = server.multiMind.personal;
|
||||
new SessionStore(personal).ensure('agent-runs', 'agent-runs', 'Agent collaboration index');
|
||||
const frames = new FrameStore(personal);
|
||||
const frame = frames.createIFrame(
|
||||
'agent-runs',
|
||||
`[External agent run]\nRun: ${input.run.id}\nWorkspace: ${input.run.workspaceId}\nTool: ${input.run.executor.toolId}\nStatus: ${input.result.status}\nSummary: ${safeSummary.slice(0, 1_000)}`,
|
||||
'normal',
|
||||
'agent_inferred',
|
||||
);
|
||||
frames.setMetadata(frame.id, metadata);
|
||||
personalFrameIds.push(frame.id);
|
||||
personalOk = true;
|
||||
} catch { /* workspace memory can still succeed */ }
|
||||
|
||||
let acquired = false;
|
||||
try {
|
||||
const db = server.mindCache.acquire(input.run.workspaceId);
|
||||
acquired = true;
|
||||
new SessionStore(db).ensure('agent-runs', 'agent-runs', 'Agent collaboration results');
|
||||
const frames = new FrameStore(db);
|
||||
const frame = frames.createIFrame(
|
||||
'agent-runs',
|
||||
`[External agent result]\nRun: ${input.run.id}\nTool: ${input.run.executor.toolId}\nTask:\n${input.prompt}\n\nResult:\n${safeSummary.slice(0, RESULT_MEMORY_LIMIT)}`,
|
||||
'normal',
|
||||
'agent_inferred',
|
||||
);
|
||||
frames.setMetadata(frame.id, metadata);
|
||||
workspaceFrameIds[input.run.workspaceId] = [frame.id];
|
||||
workspaceOk = true;
|
||||
} catch {
|
||||
// Personal index may still have succeeded; return a truthful partial state.
|
||||
} finally {
|
||||
if (acquired) server.mindCache.release(input.run.workspaceId);
|
||||
}
|
||||
|
||||
return {
|
||||
status: personalOk && workspaceOk ? 'complete' : (personalOk || workspaceOk ? 'partial' : 'failed'),
|
||||
personalFrameIds,
|
||||
workspaceFrameIds,
|
||||
};
|
||||
}
|
||||
|
||||
interface OpenClawInvocation {
|
||||
|
||||
Reference in New Issue
Block a user