/** * Runs the registered response-handler evaluators over a Stage-1 message-handler * result, applying each evaluator's patch to the plan — contexts, candidate * actions, parent-action hints, deterministic tool call, reply — in priority * order and collecting a per-evaluator trace of what changed. */ import type { MessageHandlerAction, MessageHandlerDeterministicToolCall, MessageHandlerResult } from "../types/components.js"; import type { AgentContext, ContextDefinition, RoleGateRole } from "../types/contexts.js"; import type { Memory } from "../types/memory.js"; import type { IAgentRuntime } from "../types/runtime.js"; import type { State } from "../types/state.js"; import type { ContextProviderEvent } from "./context-object.js"; import type { DirectActionRoutingRule } from "./direct-action-routing.js"; export interface ResponseHandlerPatch { processMessage?: MessageHandlerAction; requiresTool?: boolean; /** Mark a terminal refusal without granting a completed-effect claim. */ replyEffectStatus?: "non_applied"; setContexts?: readonly AgentContext[]; /** Atomically replace derived intents and invalidate declared inferred-scope fields. */ replaceIntentScope?: { intents: readonly string[]; invalidateFields: readonly string[]; /** Registered, admitted owner; retained only during this evaluator run. */ owner?: DirectActionRoutingRule; }; /** Complete canonical sources authored by trusted evaluators, outside model plans. */ contextSources?: readonly ContextProviderEvent[]; addContexts?: readonly AgentContext[]; addCandidateActions?: readonly string[]; addParentActionHints?: readonly string[]; addContextSlices?: readonly string[]; clearCandidateActions?: boolean; clearParentActionHints?: boolean; deterministicToolCall?: MessageHandlerDeterministicToolCall; clearReply?: boolean; reply?: string; debug?: readonly string[]; } type ResponseHandlerEvaluatorResult = ResponseHandlerPatch | undefined; export interface ResponseHandlerEvaluatorContext { /** Runtime-only invalidations from earlier applied patches in this run. * Never populated from model output, plan extensions, or stored history. */ invalidatedScopeFields?: ReadonlySet; wholeRequestOwner?: DirectActionRoutingRule; runtime: IAgentRuntime; message: Memory; state: State; messageHandler: MessageHandlerResult; availableContexts: readonly ContextDefinition[]; userRoles?: readonly RoleGateRole[]; } export interface ResponseHandlerEvaluator { name: string; description?: string; priority?: number; /** Exact action names this evaluator may select for deterministic execution. */ deterministicActions?: readonly string[]; shouldRun(context: ResponseHandlerEvaluatorContext): boolean | Promise; evaluate(context: ResponseHandlerEvaluatorContext): ResponseHandlerEvaluatorResult | Promise; } export interface ResponseHandlerPatchTrace { evaluatorName: string; debug: string[]; changed: string[]; } export interface ResponseHandlerEvaluationRunResult { contextSources?: ContextProviderEvent[]; activeEvaluators: string[]; appliedPatches: ResponseHandlerPatchTrace[]; candidateActionsAddedByEvaluators: string[]; candidateActionsClearedByEvaluators: boolean; errors: Array<{ evaluatorName: string; error: string; }>; } export declare function runResponseHandlerEvaluators(args: { runtime: IAgentRuntime; message: Memory; state: State; messageHandler: MessageHandlerResult; availableContexts: readonly ContextDefinition[]; userRoles?: readonly RoleGateRole[]; evaluators?: readonly ResponseHandlerEvaluator[]; }): Promise; export {};