diff --git a/src/agents/tools/memory-tool.ts b/src/agents/tools/memory-tool.ts index 953a0582115..e0cb82d6d41 100644 --- a/src/agents/tools/memory-tool.ts +++ b/src/agents/tools/memory-tool.ts @@ -22,10 +22,7 @@ const MemoryGetSchema = Type.Object({ lines: Type.Optional(Type.Number()), }); -export function createMemorySearchTool(options: { - config?: OpenClawConfig; - agentSessionKey?: string; -}): AnyAgentTool | null { +function resolveMemoryToolContext(options: { config?: OpenClawConfig; agentSessionKey?: string }) { const cfg = options.config; if (!cfg) { return null; @@ -37,6 +34,18 @@ export function createMemorySearchTool(options: { if (!resolveMemorySearchConfig(cfg, agentId)) { return null; } + return { cfg, agentId }; +} + +export function createMemorySearchTool(options: { + config?: OpenClawConfig; + agentSessionKey?: string; +}): AnyAgentTool | null { + const ctx = resolveMemoryToolContext(options); + if (!ctx) { + return null; + } + const { cfg, agentId } = ctx; return { label: "Memory Search", name: "memory_search", @@ -91,17 +100,11 @@ export function createMemoryGetTool(options: { config?: OpenClawConfig; agentSessionKey?: string; }): AnyAgentTool | null { - const cfg = options.config; - if (!cfg) { - return null; - } - const agentId = resolveSessionAgentId({ - sessionKey: options.agentSessionKey, - config: cfg, - }); - if (!resolveMemorySearchConfig(cfg, agentId)) { + const ctx = resolveMemoryToolContext(options); + if (!ctx) { return null; } + const { cfg, agentId } = ctx; return { label: "Memory Get", name: "memory_get",