🐛 fix: fix update memory tools (#11831)

update memory
This commit is contained in:
Arvin Xu
2026-01-26 02:20:48 +08:00
committed by GitHub
parent c3fd2dc785
commit cfc03dd6ad
3 changed files with 50 additions and 21 deletions

View File

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

View File

@@ -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>;

View File

@@ -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({