Skip to content

Commit cfc03dd

Browse files
authored
🐛 fix: fix update memory tools (#11831)
update memory
1 parent c3fd2dc commit cfc03dd

3 files changed

Lines changed: 50 additions & 21 deletions

File tree

packages/builtin-tool-memory/src/manifest.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,43 @@ export const MemoryManifest: BuiltinToolManifest = {
2525
parameters: {
2626
additionalProperties: false,
2727
properties: {
28-
query: { type: 'string' },
28+
query: {
29+
description: 'The search query to find relevant memories',
30+
type: 'string',
31+
},
2932
topK: {
3033
additionalProperties: false,
3134
description:
32-
'Limits on number of memories to return per layer, default to search 3 activities, 0 contexts, 0 experiences, and 0 preferences if not specified.',
35+
'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.',
3336
properties: {
34-
activities: { minimum: 0, type: 'integer' },
35-
contexts: { minimum: 0, type: 'integer' },
36-
experiences: { minimum: 0, type: 'integer' },
37-
preferences: { minimum: 0, type: 'integer' },
37+
activities: {
38+
description: 'Number of activity memories (what happened, when, where). Default: 3',
39+
minimum: 0,
40+
type: 'integer',
41+
},
42+
contexts: {
43+
description:
44+
'Number of context memories (ongoing situations, projects). Default: 0',
45+
minimum: 0,
46+
type: 'integer',
47+
},
48+
experiences: {
49+
description:
50+
'Number of experience memories (lessons learned, insights). Default: 0',
51+
minimum: 0,
52+
type: 'integer',
53+
},
54+
preferences: {
55+
description:
56+
'Number of preference memories (user preferences, directives). Default: 3',
57+
minimum: 0,
58+
type: 'integer',
59+
},
3860
},
39-
required: ['contexts', 'experiences', 'preferences'],
4061
type: 'object',
4162
},
4263
},
43-
required: ['query', 'topK'],
64+
required: ['query'],
4465
type: 'object',
4566
} satisfies JSONSchema7,
4667
},

packages/types/src/userMemory/tools.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@ import {
88
} from './layers';
99

1010
export const searchMemorySchema = z.object({
11-
// TODO: we need to dynamically fetch the available categories/types from the backend
12-
// memoryCategory: z.string().optional(),
13-
// memoryType: z.string().optional(),
1411
query: z.string(),
15-
topK: z.object({
16-
activities: z.coerce.number().int().min(0),
17-
contexts: z.coerce.number().int().min(0),
18-
experiences: z.coerce.number().int().min(0),
19-
preferences: z.coerce.number().int().min(0),
20-
}),
12+
/**
13+
* Optional limits for each memory layer. If omitted, server defaults are used.
14+
* Each field is optional - only specify layers you want to customize.
15+
* Set a layer to 0 to exclude it from search results.
16+
*/
17+
topK: z
18+
.object({
19+
/** Number of activity memories to return */
20+
activities: z.number().int().min(0).optional(),
21+
/** Number of context memories to return */
22+
contexts: z.number().int().min(0).optional(),
23+
/** Number of experience memories to return */
24+
experiences: z.number().int().min(0).optional(),
25+
/** Number of preference memories to return */
26+
preferences: z.number().int().min(0).optional(),
27+
})
28+
.optional(),
2129
});
2230

2331
export type SearchMemoryParams = z.infer<typeof searchMemorySchema>;

src/server/routers/lambda/userMemories.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ const searchUserMemories = async (
146146
});
147147

148148
const limits = {
149-
activities: input.topK?.activities,
150-
contexts: input.topK?.contexts,
151-
experiences: input.topK?.experiences,
152-
preferences: input.topK?.preferences,
149+
activities: input.topK?.activities ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.activities,
150+
contexts: input.topK?.contexts ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.contexts,
151+
experiences: input.topK?.experiences ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.experiences,
152+
preferences: input.topK?.preferences ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.preferences,
153153
};
154154

155155
const layeredResults = await ctx.memoryModel.searchWithEmbedding({

0 commit comments

Comments
 (0)