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
+5 -1
View File
@@ -34,6 +34,7 @@ import {
type AssistantWeatherDay,
type TrekCard,
} from '@trek/shared';
import { isDeepStrictEqual } from 'node:util';
type ToolArgs = Record<string, unknown>;
@@ -139,6 +140,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 +497,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;