mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
refactor(agents): dedupe memory tool config
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user