fix(assistant): leave room for the attached file tools when loading tool groups

A trip turn with an attached file adds read_attached_file and keep_attached_file to the session's tools, so loading groups now stops two short of the 128 tools OpenAI and Azure accept in one request.
This commit is contained in:
Maurice
2026-11-28 00:32:43 +01:00
parent 6bbe597719
commit 7c6189f504
3 changed files with 33 additions and 3 deletions
@@ -5,6 +5,8 @@
* offered 130 in its first step).
*/
import { ADDON_IDS } from '../../../../src/addons';
import type { AssistantAttachmentSummary } from '../../../../src/db/repositories/AssistantAttachments.repository';
import { attachedPort } from '../../../../src/nest/assistant/assistant-attachment-tools';
import { ASSISTANT_TOOL_GROUPS } from '../../../../src/nest/assistant/assistant-tool-offer';
import { MAX_OFFERED_TOOLS } from '../../../../src/nest/assistant/assistant-tools.constants';
import {
@@ -56,6 +58,14 @@ async function within<T>(
const names = (session: AssistantToolSession) => session.specs().map((spec) => spec.name);
/** A turn with a readable attached file in a trip that keeps files, so both attachment tools come on top. */
const ATTACHED_TURN = {
attached: [{ id: 'att-1', text_status: 'ok' } as AssistantAttachmentSummary],
sentTo: 'model',
keeps: true,
read: () => Promise.resolve({ ok: true, value: '' }),
};
interface LoadAnswer {
loaded: string[];
tools: string[];
@@ -156,6 +166,21 @@ describe('the tools one step offers', () => {
}
});
it('ASTCAP-005b: a trip turn with an attached file stays within the limit whatever the model loads', async () => {
const steps = await within(tripSession(), async (session) => {
const port = attachedPort(session, ATTACHED_TURN);
const counts: Array<{ group: string; offered: number }> = [];
for (const group of GROUPS) {
await session.call('use_addon_tools', { groups: [group] });
counts.push({ group, offered: port.specs().length });
}
await session.call('use_addon_tools', { groups: GROUPS });
counts.push({ group: 'all', offered: port.specs().length });
return counts;
});
for (const { group, offered } of steps) expect(offered, group).toBeLessThanOrEqual(MAX_OFFERED_TOOLS);
});
it('ASTCAP-006: a journey chat offers no more than the limit on either of its pages', async () => {
const { user } = await makeUser(orm);
const journey = await makeJourney(orm, user.id, { title: 'Lisbon' });