diff --git a/extensions/memory-core/index.ts b/extensions/memory-core/index.ts index 20d2b786ae5..c33ba5a1a5d 100644 --- a/extensions/memory-core/index.ts +++ b/extensions/memory-core/index.ts @@ -62,7 +62,7 @@ const MemorySearchSchema = { type: "object", properties: { query: { type: "string" }, - maxResults: { type: "number" }, + maxResults: { type: "integer", minimum: 1 }, minScore: { type: "number" }, corpus: { type: "string", enum: ["memory", "wiki", "all", "sessions"] }, }, diff --git a/extensions/memory-core/src/tools.shared.ts b/extensions/memory-core/src/tools.shared.ts index 79a0832b9b5..1b5e5db2134 100644 --- a/extensions/memory-core/src/tools.shared.ts +++ b/extensions/memory-core/src/tools.shared.ts @@ -30,7 +30,7 @@ export async function loadMemoryToolRuntime(): Promise { export const MemorySearchSchema = Type.Object({ query: Type.String(), - maxResults: Type.Optional(Type.Number()), + maxResults: Type.Optional(Type.Integer({ minimum: 1 })), minScore: Type.Optional(Type.Number()), corpus: Type.Optional(stringEnum(["memory", "wiki", "all", "sessions"])), }); diff --git a/extensions/memory-core/src/tools.test.ts b/extensions/memory-core/src/tools.test.ts index 4a2e4ad41a7..6a819062ab9 100644 --- a/extensions/memory-core/src/tools.test.ts +++ b/extensions/memory-core/src/tools.test.ts @@ -58,6 +58,19 @@ describe("memory_search unavailable payloads", () => { resetMemoryToolMockState({ searchImpl: async () => [] }); }); + it("rejects fractional maxResults before searching", async () => { + const tool = createMemorySearchToolOrThrow(); + + await expect( + tool.execute("fractional-max-results", { + query: "hello", + maxResults: 1.5, + }), + ).rejects.toThrow("maxResults must be a positive integer"); + + expect(getMemorySearchManagerMockCalls()).toBe(0); + }); + it("returns explicit unavailable metadata for quota failures", async () => { setMemorySearchImpl(async () => { throw new Error("openai embeddings failed: 429 insufficient_quota"); diff --git a/extensions/memory-core/src/tools.ts b/extensions/memory-core/src/tools.ts index fbae68dd9f2..04635a08b9e 100644 --- a/extensions/memory-core/src/tools.ts +++ b/extensions/memory-core/src/tools.ts @@ -256,7 +256,7 @@ export function createMemorySearchTool(options: { async (_toolCallId, params) => { const rawParams = asToolParamsRecord(params); const query = readStringParam(rawParams, "query", { required: true }); - const maxResults = readNumberParam(rawParams, "maxResults"); + const maxResults = readPositiveIntegerParam(rawParams, "maxResults"); const minScore = readNumberParam(rawParams, "minScore"); const requestedCorpus = readStringParam(rawParams, "corpus") as | "memory"