mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 01:12:16 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5e0447fd0 | |||
| 4c05f6f051 |
@@ -35,6 +35,8 @@ import {
|
|||||||
type TrekCard,
|
type TrekCard,
|
||||||
} from '@trek/shared';
|
} from '@trek/shared';
|
||||||
|
|
||||||
|
import { isDeepStrictEqual } from 'node:util';
|
||||||
|
|
||||||
type ToolArgs = Record<string, unknown>;
|
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 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.`;
|
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. */
|
/** 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);
|
const unknownPlace = 'error' in prepared ? null : placeIdRefusal(call.name, prepared.args, turn.knownPlaceIds);
|
||||||
if (unknownPlace) prepared = { error: unknownPlace };
|
if (unknownPlace) prepared = { error: unknownPlace };
|
||||||
if (kind === 'write' && !('error' in prepared)) {
|
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 (refused) prepared = { error: refused };
|
||||||
}
|
}
|
||||||
if (kind === 'read' && !('error' in prepared)) reads += 1;
|
if (kind === 'read' && !('error' in prepared)) reads += 1;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ const KINDS: Record<string, AssistantToolKind> = {
|
|||||||
get_weather: 'read',
|
get_weather: 'read',
|
||||||
get_place_details: 'read',
|
get_place_details: 'read',
|
||||||
create_place: 'write',
|
create_place: 'write',
|
||||||
|
create_packing_item: 'write',
|
||||||
open_trip_chat: 'read',
|
open_trip_chat: 'read',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -284,6 +285,40 @@ describe('runAgentLoop', () => {
|
|||||||
expect(t.chunks.at(-1)).toEqual({ type: 'finish', finishReason: 'tool-calls' });
|
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 () => {
|
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 => ({
|
const calls = Array.from({ length: MAX_WRITES_PER_STEP + 1 }, (_, i): AiChatEvent => ({
|
||||||
type: 'tool-call',
|
type: 'tool-call',
|
||||||
|
|||||||
Reference in New Issue
Block a user