mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
Hold identical assistant changes only once per step
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user