refactor(memory): migrate lancedb recall to prompt-build hook

This commit is contained in:
Vincent Koc
2026-04-22 10:55:41 -07:00
parent 921a5416e4
commit 1e61279b35
2 changed files with 38 additions and 4 deletions

View File

@@ -165,6 +165,42 @@ describe("memory plugin e2e", () => {
expect(config?.autoRecall).toBe(true);
});
test("registers auto-recall on before_prompt_build instead of the legacy hook", async () => {
const on = vi.fn();
const mockApi = {
id: "memory-lancedb",
name: "Memory (LanceDB)",
source: "test",
config: {},
pluginConfig: {
embedding: {
apiKey: OPENAI_API_KEY,
model: "text-embedding-3-small",
},
dbPath: getDbPath(),
autoCapture: false,
autoRecall: true,
},
runtime: {},
logger: {
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
},
registerTool: vi.fn(),
registerCli: vi.fn(),
registerService: vi.fn(),
on,
resolvePath: (filePath: string) => filePath,
};
memoryPlugin.register(mockApi as any);
expect(on).toHaveBeenCalledWith("before_prompt_build", expect.any(Function));
expect(on).not.toHaveBeenCalledWith("before_agent_start", expect.any(Function));
});
test("passes configured dimensions to OpenAI embeddings API", async () => {
const embeddingsCreate = vi.fn(async () => ({
data: [{ embedding: [0.1, 0.2, 0.3] }],

View File

@@ -40,8 +40,6 @@ type MemorySearchResult = {
score: number;
};
type LegacyBeforeAgentStartContext = { prependContext: string } | undefined;
// ============================================================================
// LanceDB Provider
// ============================================================================
@@ -541,9 +539,9 @@ export default definePluginEntry({
// Lifecycle Hooks
// ========================================================================
// Auto-recall: inject relevant memories before agent starts
// Auto-recall: inject relevant memories during prompt build
if (cfg.autoRecall) {
api.on("before_agent_start", async (event): Promise<LegacyBeforeAgentStartContext> => {
api.on("before_prompt_build", async (event) => {
if (!event.prompt || event.prompt.length < 5) {
return undefined;
}