Hold identical assistant changes only once per step

This commit is contained in:
Maurice
2026-12-02 01:32:39 +01:00
parent 10fecf4e80
commit 103631d5fc
2 changed files with 31 additions and 1 deletions
@@ -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,31 @@ 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',