Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: fix update memory tools (#11831)

Arvin Xucfc03dd6ad05
diff --git a/packages/builtin-tool-memory/src/manifest.ts b/packages/builtin-tool-memory/src/manifest.ts
index a5ad0494cf7..3a5695710d7 100644
--- a/packages/builtin-tool-memory/src/manifest.ts
+++ b/packages/builtin-tool-memory/src/manifest.ts
@@ -25,22 +25,43 @@ export const MemoryManifest: BuiltinToolManifest = {
parameters: {
additionalProperties: false,
properties: {
- query: { type: 'string' },
+ query: {
+ description: 'The search query to find relevant memories',
+ type: 'string',
+ },
topK: {
additionalProperties: false,
description:
- 'Limits on number of memories to return per layer, default to search 3 activities, 0 contexts, 0 experiences, and 0 preferences if not specified.',
+ 'Optional. Limits on number of memories to return per layer. If omitted entirely, uses defaults (3 activities, 3 preferences). Set a layer to 0 to exclude it.',
properties: {
- activities: { minimum: 0, type: 'integer' },
- contexts: { minimum: 0, type: 'integer' },
- experiences: { minimum: 0, type: 'integer' },
- preferences: { minimum: 0, type: 'integer' },
+ activities: {
+ description: 'Number of activity memories (what happened, when, where). Default: 3',
+ minimum: 0,
+ type: 'integer',
+ },
+ contexts: {
+ description:
+ 'Number of context memories (ongoing situations, projects). Default: 0',
+ minimum: 0,
+ type: 'integer',
+ },
+ experiences: {
+ description:
+ 'Number of experience memories (lessons learned, insights). Default: 0',
+ minimum: 0,
+ type: 'integer',
+ },
+ preferences: {
+ description:
+ 'Number of preference memories (user preferences, directives). Default: 3',
+ minimum: 0,
+ type: 'integer',
+ },
},
- required: ['contexts', 'experiences', 'preferences'],
type: 'object',
},
},
- required: ['query', 'topK'],
+ required: ['query'],
type: 'object',
} satisfies JSONSchema7,
},
diff --git a/packages/types/src/userMemory/tools.ts b/packages/types/src/userMemory/tools.ts
index fde0fe13f11..14e904780ee 100644
--- a/packages/types/src/userMemory/tools.ts
+++ b/packages/types/src/userMemory/tools.ts
@@ -8,16 +8,24 @@ import {
} from './layers';
export const searchMemorySchema = z.object({
- // TODO: we need to dynamically fetch the available categories/types from the backend
- // memoryCategory: z.string().optional(),
- // memoryType: z.string().optional(),
query: z.string(),
- topK: z.object({
- activities: z.coerce.number().int().min(0),
- contexts: z.coerce.number().int().min(0),
- experiences: z.coerce.number().int().min(0),
- preferences: z.coerce.number().int().min(0),
- }),
+ /**
+ * Optional limits for each memory layer. If omitted, server defaults are used.
+ * Each field is optional - only specify layers you want to customize.
+ * Set a layer to 0 to exclude it from search results.
+ */
+ topK: z
+ .object({
+ /** Number of activity memories to return */
+ activities: z.number().int().min(0).optional(),
+ /** Number of context memories to return */
+ contexts: z.number().int().min(0).optional(),
+ /** Number of experience memories to return */
+ experiences: z.number().int().min(0).optional(),
+ /** Number of preference memories to return */
+ preferences: z.number().int().min(0).optional(),
+ })
+ .optional(),
});
export type SearchMemoryParams = z.infer<typeof searchMemorySchema>;
diff --git a/src/server/routers/lambda/userMemories.ts b/src/server/routers/lambda/userMemories.ts
index c29c544c34f..63c90e9cb43 100644
--- a/src/server/routers/lambda/userMemories.ts
+++ b/src/server/routers/lambda/userMemories.ts
@@ -146,10 +146,10 @@ const searchUserMemories = async (
});
const limits = {
- activities: input.topK?.activities,
- contexts: input.topK?.contexts,
- experiences: input.topK?.experiences,
- preferences: input.topK?.preferences,
+ activities: input.topK?.activities ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.activities,
+ contexts: input.topK?.contexts ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.contexts,
+ experiences: input.topK?.experiences ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.experiences,
+ preferences: input.topK?.preferences ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.preferences,
};
const layeredResults = await ctx.memoryModel.searchWithEmbedding({