refactor(agents): dedupe memory tool config

This commit is contained in:
Peter Steinberger
2026-02-15 16:22:59 +00:00
parent e89c7b7735
commit 95355ba25a

View File

@@ -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",