Split model call and tool loop helpers
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
export type ToolLoopRoundOutcome = {
|
||||
shouldContinue: boolean;
|
||||
maxRoundsReached?: boolean;
|
||||
};
|
||||
|
||||
export async function runToolLoopRounds(params: {
|
||||
maxRounds: number;
|
||||
onRound: (round: number) => Promise<ToolLoopRoundOutcome>;
|
||||
onMaxRoundsReached?: (round: number) => Promise<void> | void;
|
||||
}): Promise<void> {
|
||||
for (let round = 0; round < params.maxRounds; round++) {
|
||||
const outcome = await params.onRound(round);
|
||||
if (!outcome.shouldContinue) {
|
||||
if (outcome.maxRoundsReached) {
|
||||
await params.onMaxRoundsReached?.(round);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await params.onMaxRoundsReached?.(params.maxRounds - 1);
|
||||
}
|
||||
Reference in New Issue
Block a user