Compare commits

...

2 Commits

Author SHA1 Message Date
Maurice e5e0447fd0 style(server): format the assistant proposal guard
The Server lint formatting check rejected the assistant agent and its regression test. Apply the repository Prettier configuration to those two files.
2026-12-02 01:39:56 +01:00
Maurice 4c05f6f051 Hold identical assistant changes only once per step 2026-12-02 01:32:39 +01:00
2 changed files with 41 additions and 1 deletions
+6 -1
View File
@@ -35,6 +35,8 @@ import {
type TrekCard,
} from '@trek/shared';
import { isDeepStrictEqual } from 'node:util';
type ToolArgs = Record<string, unknown>;
/**
@@ -139,6 +141,7 @@ interface AgentOutcome {
}
const TOO_MANY_CHANGES = `Too many changes in one step: propose at most ${MAX_WRITES_PER_STEP} at once.`;
const CHANGE_ALREADY_PROPOSED = 'This exact change is already waiting for approval.';
const TOO_MANY_LOOKUPS = `Too many lookups in one step: make at most ${MAX_READS_PER_STEP} at once.`;
/** What a step collects while its calls run: its parts, and the weather its lookups found. */
@@ -495,7 +498,9 @@ async function runCalls(turn: Turn, calls: AiToolCall[], collected: StepParts):
const unknownPlace = 'error' in prepared ? null : placeIdRefusal(call.name, prepared.args, turn.knownPlaceIds);
if (unknownPlace) prepared = { error: unknownPlace };
if (kind === 'write' && !('error' in prepared)) {
const refused = await deps.refusalOf?.(call.name, prepared.args);
const { args } = prepared;
const duplicate = held.some((change) => change.toolName === call.name && isDeepStrictEqual(change.args, args));
const refused = duplicate ? CHANGE_ALREADY_PROPOSED : await deps.refusalOf?.(call.name, args);
if (refused) prepared = { error: refused };
}
if (kind === 'read' && !('error' in prepared)) reads += 1;
@@ -65,6 +65,7 @@ const KINDS: Record<string, AssistantToolKind> = {
get_weather: 'read',
get_place_details: 'read',
create_place: 'write',
create_packing_item: 'write',
open_trip_chat: 'read',
};
@@ -284,6 +285,40 @@ describe('runAgentLoop', () => {
expect(t.chunks.at(-1)).toEqual({ type: 'finish', finishReason: 'tool-calls' });
});
it('holds one proposal when the model repeats the same packing item change in a step', async () => {
const t = setup([
[
{
type: 'tool-call',
call: { id: 'first', name: 'create_packing_item', args: { name: 'Adapter', quantity: 2 } },
},
{
type: 'tool-call',
call: { id: 'repeat', name: 'create_packing_item', args: { quantity: 2, name: 'Adapter' } },
},
{
type: 'tool-call',
call: { id: 'other', name: 'create_packing_item', args: { name: 'Adapter', quantity: 3 } },
},
],
]);
const outcome = await runAgentLoop(t.deps, t.input, t.writer, new AbortController().signal);
expect(outcome.end).toBe('awaiting');
expect(t.memory.held[0].held.map((call) => call.providerCallId)).toEqual(['first', 'other']);
expect(t.chunks.filter((chunk) => chunk.type === 'tool-approval-request')).toHaveLength(2);
expect(t.memory.held[0].step.parts).toContainEqual({
type: 'tool-call',
toolCallId: 'repeat',
toolName: 'create_packing_item',
args: { quantity: 2, name: 'Adapter' },
result: 'This exact change is already waiting for approval.',
isError: true,
});
expect(t.tools.call).not.toHaveBeenCalled();
});
it('ASTAGT-004: more changes than a step may hold go back to the model as an error', async () => {
const calls = Array.from({ length: MAX_WRITES_PER_STEP + 1 }, (_, i): AiChatEvent => ({
type: 'tool-call',