runGoal
function runGoal(options): Promise<GoalResult>;Defined in: goal/goal.ts:56
Pursue a goal across rounds, driving runAgent until a Grader is satisfied or the round cap is reached.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | RunGoalOptions | The goal, grader, shared run config, and loop configuration. |
Returns
Promise<GoalResult>
Whether the goal was met, the round count, and the final grade/result.
Remarks
Each round is one full inner run. After it settles the grader judges it: a
done verdict ends the loop with done true; a
not-done verdict re-prompts the next round with the grader's feedback (or the
goal restated when no feedback is given). Hitting
maxRounds ends the loop with done false.
The signal is forwarded to each inner run and
re-checked at the top of every round, so cancellation unwinds promptly — an
abort mid-round rejects that inner run, and an abort between rounds rejects
runGoal before the next round starts.
Throws
The signal's reason (an AbortError) if the run is cancelled.
Example
const outcome = await runGoal({
goal: "Produce a one-paragraph summary with no spelling mistakes.",
grader: modelGrader({ model: fastModel }),
base: { model, memory: new SessionMemoryStore(), sessionId: "demo", tools },
});
console.log(outcome.done, outcome.rounds); // -> true 2