mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:00:42 +00:00
refactor(memory): migrate lancedb recall to prompt-build hook
This commit is contained in:
@@ -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] }],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user