@@ -5,6 +5,11 @@ import { checkLimitReached, type GoalState } from "./state.ts";
|
||||
|
||||
export type SettleDecision = { action: "inject" } | { action: "wait" } | { action: "pause"; reason: string };
|
||||
|
||||
/** An untimed wait never spends model tokens on automatic reconciliation. */
|
||||
export function hasUnresolvedWait(state: GoalState): boolean {
|
||||
return !!state.activeWait && (!state.waitTimeoutSeconds || !state.activeWait.wakeSent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide what the loop does when the agent settles while a goal is active.
|
||||
* stopReason comes from the last assistant message ("stop", "toolUse",
|
||||
@@ -17,7 +22,7 @@ export function decideSettle(state: GoalState, stopReason: string | undefined):
|
||||
if (stopReason === "error") {
|
||||
return { action: "pause", reason: "paused: run error" };
|
||||
}
|
||||
if (state.waitTimeoutSeconds && state.activeWait && !state.activeWait.wakeSent) {
|
||||
if (hasUnresolvedWait(state)) {
|
||||
return { action: "wait" };
|
||||
}
|
||||
if (checkLimitReached(state)) {
|
||||
|
||||
Reference in New Issue
Block a user