fix: keep active memory tools available

This commit is contained in:
Peter Steinberger
2026-05-03 12:23:55 +01:00
parent 02c2160478
commit 5e9135f2e2
5 changed files with 301 additions and 16 deletions

View File

@@ -1210,7 +1210,7 @@ describe("qa mock openai server", () => {
}),
});
expect(activeMemorySearch.status).toBe(200);
expect(await activeMemorySearch.text()).toContain('"name":"memory_recall"');
expect(await activeMemorySearch.text()).toContain('"name":"memory_search"');
const activeMemoryStreamSummary = await fetch(`${server.baseUrl}/v1/responses`, {
method: "POST",

View File

@@ -1465,6 +1465,12 @@ async function buildResponsesPayload(
/silent snack recall check/i.test(allInputText)
) {
if (!toolOutput) {
if (!hasDeclaredTool(body, "memory_recall")) {
return buildToolCallEventsWithArgs("memory_search", {
query: "QA movie night snack lemon pepper wings blue cheese",
maxResults: 3,
});
}
return buildToolCallEventsWithArgs("memory_recall", {
query: "QA movie night snack lemon pepper wings blue cheese",
limit: 3,
@@ -1490,6 +1496,23 @@ async function buildResponsesPayload(
}
return buildAssistantEvents("NONE");
}
const results = Array.isArray(toolJson?.results)
? (toolJson.results as Array<Record<string, unknown>>)
: [];
const first = results[0];
if (typeof first?.path === "string") {
const from =
typeof first.startLine === "number"
? Math.max(1, first.startLine)
: typeof first.endLine === "number"
? Math.max(1, first.endLine)
: 1;
return buildToolCallEventsWithArgs("memory_get", {
path: first.path,
from,
lines: 4,
});
}
const memorySnippet = Array.isArray(toolJson?.results)
? JSON.stringify(toolJson.results)
: toolOutput;