@mastra/core
Version:
113 lines • 4.91 kB
TypeScript
import type { MessageList } from '../../../agent/message-list/index.js';
import type { GoalConfig } from '../../../agent/types.js';
import type { Mastra } from '../../../mastra/index.js';
import type { MastraMemory } from '../../../memory/index.js';
import type { ProcessorStreamWriterOptions } from '../../../processors/index.js';
import { RequestContext } from '../../../request-context/index.js';
/** Outcome of a goal evaluation, projected back onto engine state by the glue. */
export type GoalOutcome =
/** A skip-guard fired (or no judge resolves) — the iteration is untouched. */
{
evaluated: false;
}
/**
* An `active` record re-entered already at/over budget — the loop must stop
* without burning a judge call. No signal was sent and no message rotation
* happened, so callers only need to flip `isContinued`.
*/
| {
evaluated: true;
kind: 'budget-guard';
shouldContinue: false;
}
/**
* The objective was paused, cleared, or replaced while the judge ran. The
* verdict is discarded (nothing persisted, no signal sent) and the loop stops.
*/
| {
evaluated: true;
kind: 'superseded';
shouldContinue: false;
}
/**
* The judge ran (or failed and was converted into a paused verdict). The
* transcript gained the goal feedback signal and the response message id may
* have rotated — callers must project `shouldContinue` + `messageId` back
* onto their state (and re-serialize the message list on the durable side).
*/
| {
evaluated: true;
kind: 'judged';
shouldContinue: boolean;
messageId: string;
};
/**
* Shared goal-step behavior: judge a settled iteration against
* the thread's active durable objective. Handles the skip-guards, the budget
* guard, judge/scorer resolution, judge activity streaming, the tri-state
* verdict (done / waiting / keep working, with judge failure → paused), record
* persistence, feedback signal injection, and `goal` chunk emission. Callers
* own how the verdict projects back onto their state shape (flipping
* `isContinued`, updating `messageId`, serializing the message list).
*
* Grading is skipped when: the iteration errored (`reason === 'error'`); no
* goal is configured; a background task result was just injected or the LLM is
* still mid-tool-loop; the iteration only updated working memory; there is no
* active objective record; or no judge model resolves (the judge is the
* activation switch).
*
* Adjudicated drift (previously engine-specific):
* - A judge model-resolver returning `undefined` now falls back to the
* effective `judgeModelId` (record override → agent config) on both engines
* (previously main-only).
* - The default judge scorer always receives an isolated copy of the request
* context so judge-side mutations can't leak into the parent run
* (previously main-only).
* - Judge activity streaming is wrapped so a scorer stream failure can't turn
* into an unhandled rejection (previously durable-only).
* - Chunk emission is best-effort via the injected transport on both engines.
*/
export declare function evaluateGoal(deps: {
goal: GoalConfig | undefined;
stepReason: string | undefined;
backgroundTaskPending: boolean | undefined;
/** Truthy while the LLM is mid-tool-loop — the goal only judges settled turns. */
isContinued: boolean | undefined;
toolCalls: Array<{
toolName?: string;
args?: unknown;
}>;
toolResults: Array<{
toolName?: string;
result?: unknown;
}>;
currentText: string;
runId: string;
agentId?: string;
agentName?: string;
threadId?: string;
resourceId?: string;
customContext?: Record<string, unknown>;
mastra?: Mastra;
/** Parent request context — passed as-is to `judge`/`tools` resolvers, copied for the judge scorer. */
requestContext?: RequestContext;
/** Main-only: fork the default judge into its own memory thread. */
memory?: MastraMemory;
/**
* Live (main) or rehydrated-from-state (durable) transcript; the feedback
* signal is appended here. Lazy so the durable engine only deserializes when
* the iteration is actually judged (all skip-guards run first). Must be
* memoized by the caller: it is resolved once for the scorer context and
* reused for signal injection.
*/
messageList: () => MessageList;
/** Current response message id — rotated via `rotateMessageId` when the signal lands. */
messageId: string;
rotateMessageId: (current: string) => string;
/** Engine transport for the injected feedback signal's data part (optional, like the underlying writers). */
writeSignal?: (data: unknown, options: ProcessorStreamWriterOptions & {
messageId: string;
}) => Promise<void>;
emitChunk: (chunk: unknown) => void | Promise<void>;
}): Promise<GoalOutcome>;
//# sourceMappingURL=goal-core.d.ts.map