mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 09:58:38 +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()),
|
lines: Type.Optional(Type.Number()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export function createMemorySearchTool(options: {
|
function resolveMemoryToolContext(options: { config?: OpenClawConfig; agentSessionKey?: string }) {
|
||||||
config?: OpenClawConfig;
|
|
||||||
agentSessionKey?: string;
|
|
||||||
}): AnyAgentTool | null {
|
|
||||||
const cfg = options.config;
|
const cfg = options.config;
|
||||||
if (!cfg) {
|
if (!cfg) {
|
||||||
return null;
|
return null;
|
||||||
@@ -37,6 +34,18 @@ export function createMemorySearchTool(options: {
|
|||||||
if (!resolveMemorySearchConfig(cfg, agentId)) {
|
if (!resolveMemorySearchConfig(cfg, agentId)) {
|
||||||
return null;
|
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 {
|
return {
|
||||||
label: "Memory Search",
|
label: "Memory Search",
|
||||||
name: "memory_search",
|
name: "memory_search",
|
||||||
@@ -91,17 +100,11 @@ export function createMemoryGetTool(options: {
|
|||||||
config?: OpenClawConfig;
|
config?: OpenClawConfig;
|
||||||
agentSessionKey?: string;
|
agentSessionKey?: string;
|
||||||
}): AnyAgentTool | null {
|
}): AnyAgentTool | null {
|
||||||
const cfg = options.config;
|
const ctx = resolveMemoryToolContext(options);
|
||||||
if (!cfg) {
|
if (!ctx) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const agentId = resolveSessionAgentId({
|
|
||||||
sessionKey: options.agentSessionKey,
|
|
||||||
config: cfg,
|
|
||||||
});
|
|
||||||
if (!resolveMemorySearchConfig(cfg, agentId)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const { cfg, agentId } = ctx;
|
||||||
return {
|
return {
|
||||||
label: "Memory Get",
|
label: "Memory Get",
|
||||||
name: "memory_get",
|
name: "memory_get",
|
||||||
|
|||||||
Reference in New Issue
Block a user