Skip to main content

@flow-state-dev/patterns/plan-and-execute

Interfaces​

PlanAndExecuteConfig​

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Properties​

context?​
context?: GeneratorSlot<any, any>;

Context slot applied to all default blocks.

enableReplanning?​
enableReplanning?: boolean;

Whether the LLM evaluator path is active. Default: false.

evaluator?​
evaluator?: BlockDefinition<any, any, any, any>;

Evaluator block. Default: built-in (no-LLM unless enableReplanning).

executionInstructions?​
executionInstructions?: string;

Instructions appended to the default executor's prompt.

history?​
history?: GeneratorHistoryConfig<any, any>;

History slot applied to default planner and synthesizer.

instructions?​
instructions?: InstructionsSlot<{
goal: string;
}>;

Overall instructions for the pipeline. Composes with executionInstructions / synthesizeInstructions.

maxAttemptsPerTask?​
maxAttemptsPerTask?: number;

Per-task retry budget stamped onto every seeded TaskInit. Default 1 — single attempt, no retries (preserves pre-migration behavior).

maxConcurrency?​
maxConcurrency?: number;

Worker pool size for the underlying taskBoard. Default 1 (sequential drain, matching pre-migration semantics). Bump to fan out independent dep-free steps within a single drain.

maxEnqueuedTasks?​
maxEnqueuedTasks?: number | null;
maxIterations?​
maxIterations?: number;

Hard cap on replan-loop iterations. Default: 3.

maxTotalRetries?​
maxTotalRetries?: number | null;

Cumulative failure retries the internal board may authorize, across every task. Default 50 — a number, or null for explicitly unbounded.

The two bounds above count only new tasks, so a task that keeps failing keeps spending while both sit still. This is the one number that bounds that. At the bound the failing task settles terminal errored instead of re-pending, and the board reports terminationReason: "retry-budget-exhausted". 0 means "run every task once, never retry".

Reachable here because maxAttemptsPerTask can be raised above its default of 1, at which point this board retries and the budget binds it.

maxTotalTasks?​
maxTotalTasks?: number | null;

Creation bounds for the internal board. Defaults 500/100 — unchanged behavior when unset. A planner that legitimately produces more than the enqueue bound would otherwise fail its whole seed with no way to raise the ceiling, so both are reachable here: a number, or null for explicitly unbounded on that axis.

model?​
model?: string;

Model id for default planner / executor / replanner / synthesizer.

name​
name: string;

Name for this plan-and-execute instance. Required.

outputSchema?​
outputSchema?: TOutputSchema;

Output schema for the final synthesized result (default synthesizer only).

planner?​
planner?: BlockDefinition<any, any, any, any>;

Planner block. Default: utility.decomposer().

plannerVisibility?​
plannerVisibility?: ItemVisibility;

Item visibility for default planner. Default: { client: true, history: false }.

replanner?​
replanner?: BlockDefinition<any, any, any, any>;

Replanner block. Invoked when the evaluator returns decision: "replan".

resources?​
resources?: Record<string, any>;

Resources declared on the default executor.

search?: boolean | GeneratorSearchConfig;

Web search applied to default executor.

stepExecutor?​
stepExecutor?: BlockDefinition<any, any, any, any>;

Worker block. Receives { stepId, goal, dependencyResults? } — the legacy P&E worker contract — by default; the pattern adapts the substrate TaskWorkerInput into that shape so existing consumers keep working.

stepExecutorVisibility?​
stepExecutorVisibility?: ItemVisibility;

Item visibility for default executor. Default: { client: true, history: false }.

synthesizeGoal?​
synthesizeGoal?: boolean | BlockDefinition<any, any, any, any>;

Synthesize a self-contained goal from conversation before planning. false (default): use the input goal verbatim. true: run a built-in history-aware synthesizer so history-dependent requests ("now do that for all of them") plan, replan, and synthesize against a coherent objective. A BlockDefinition: supply a custom synthesizer.

synthesizeInstructions?​
synthesizeInstructions?: string;

Instructions appended to the default synthesizer's prompt.

synthesizer?​
synthesizer?: false | BlockDefinition<any, any, any, any>;

Final synthesizer. Receives the legacy plan shape and returns the pattern's final output. Pass false to disable synthesis (the legacy plan shape is returned directly).

synthesizerVisibility?​
synthesizerVisibility?: ItemVisibility;

Item visibility for default synthesizer. Default: { client: true, history: true }.

taskContext?​
taskContext?: false | BlockDefinition<any, any, any, any> | "goal";

How each task's context is populated when the planner didn't supply one. "goal" (default): copy the (synthesized) goal into every gap-task — free, deterministic, the fix for workers being blind to the data their task needs, and in this mode a planner-emitted context always wins (only gaps are filled). false: leave context empty (older behavior). A BlockDefinition: run once over { goal, tasks } to fill per-task context with a cheap model or a deterministic step; the block owns the returned contexts (it should preserve planner-emitted context itself if desired).

tools?​
tools?: ToolsSlot;

Tools assigned to default blocks.

uses?​
uses?: UsesSlot;

Capabilities to install on default blocks.


SynthesizerPromptInput​

Properties​

completedSteps​
completedSteps: number;
goal​
goal: string;
tasks​
tasks: object[];
error?​
error?: string;
goal​
goal: string;
result?​
result?: unknown;
status​
status: string;

Type Aliases​

EvaluatorVerdict​

type EvaluatorVerdict = z.infer<typeof evaluatorVerdictSchema>;

IterationOutput​

type IterationOutput = z.infer<typeof iterationOutputSchema>;

Plan​

type Plan = z.infer<typeof PlanSchema>;

PlanAndExecuteState​

type PlanAndExecuteState = z.infer<typeof planAndExecuteStateSchema>;

PlanTask​

type PlanTask = z.infer<typeof PlanTaskSchema>;

Variables​

evaluatorVerdictSchema​

const evaluatorVerdictSchema: z.ZodObject<{
decision: z.ZodEnum<["continue", "complete", "replan"]>;
feedback: z.ZodOptional<z.ZodString>;
reasoning: z.ZodOptional<z.ZodString>;
score: z.ZodOptional<z.ZodNumber>;
tasks: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
}, "strip", z.ZodTypeAny, {
decision: "complete" | "continue" | "replan";
feedback?: string;
reasoning?: string;
score?: number;
tasks?: unknown[];
}, {
decision: "complete" | "continue" | "replan";
feedback?: string;
reasoning?: string;
score?: number;
tasks?: unknown[];
}>;

Evaluator output. Custom evaluators may return score / feedback / reasoning for richer telemetry, and may pre-bake tasks to skip the replanner step when decision === "replan".


executorOutputSchema​

const executorOutputSchema: z.ZodObject<{
reason: z.ZodDefault<z.ZodString>;
sources: z.ZodDefault<z.ZodArray<z.ZodObject<{
title: z.ZodDefault<z.ZodString>;
url: z.ZodString;
}, "strip", ZodTypeAny, {
title: string;
url: string;
}, {
title?: string;
url: string;
}>, "many">>;
success: z.ZodBoolean;
summary: z.ZodString;
}, "strip", ZodTypeAny, {
reason: string;
sources: object[];
success: boolean;
summary: string;
}, {
reason?: string;
sources?: object[];
success: boolean;
summary: string;
}>;

Output schema for the default executor generator — a task finding.


iterationOutputSchema​

const iterationOutputSchema: z.ZodObject<{
decision: z.ZodEnum<["continue", "replan", "complete"]>;
}, "strip", z.ZodTypeAny, {
decision: "complete" | "continue" | "replan";
}, {
decision: "complete" | "continue" | "replan";
}>;

Output of each iteration in the replan loop. The loopBack predicate exits when decision === "complete".


planAndExecuteStateSchema​

const planAndExecuteStateSchema: z.ZodObject<{
goal: z.ZodDefault<z.ZodString>;
iteration: z.ZodDefault<z.ZodNumber>;
status: z.ZodOptional<z.ZodEnum<["planning", "executing", "replanning", "synthesizing", "completed", "failed"]>>;
}, "strip", z.ZodTypeAny, {
goal: string;
iteration: number;
status?: | "completed"
| "executing"
| "failed"
| "planning"
| "replanning"
| "synthesizing";
}, {
goal?: string;
iteration?: number;
status?: | "completed"
| "executing"
| "failed"
| "planning"
| "replanning"
| "synthesizing";
}>;

Outer sequencer state for plan-and-execute.

Tasks themselves live on the request-scoped TaskCollection — they are NOT stored here. iteration is owned by the replan loop and bumped by evaluatePlanProgress; status is a pattern-level status used for the task-board-meta extensions (planning | executing | replanning | synthesizing).


PlanSchema​

const PlanSchema: z.ZodObject<{
currentStepIndex: z.ZodDefault<z.ZodNumber>;
goal: z.ZodString;
iteration: z.ZodDefault<z.ZodNumber>;
maxIterations: z.ZodDefault<z.ZodNumber>;
status: z.ZodEnum<["planning", "executing", "replanning", "completed", "failed"]>;
tasks: z.ZodArray<z.ZodObject<{
dependencies: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
error: z.ZodOptional<z.ZodString>;
goal: z.ZodString;
id: z.ZodString;
result: z.ZodOptional<z.ZodAny>;
status: z.ZodEnum<["pending", "in-progress", "completed", "failed", "skipped"]>;
}, "strip", z.ZodTypeAny, {
dependencies: string[];
error?: string;
goal: string;
id: string;
result?: any;
status: "completed" | "failed" | "in-progress" | "pending" | "skipped";
}, {
dependencies?: string[];
error?: string;
goal: string;
id: string;
result?: any;
status: "completed" | "failed" | "in-progress" | "pending" | "skipped";
}>, "many">;
}, "strip", z.ZodTypeAny, {
currentStepIndex: number;
goal: string;
iteration: number;
maxIterations: number;
status: "completed" | "executing" | "failed" | "planning" | "replanning";
tasks: object[];
}, {
currentStepIndex?: number;
goal: string;
iteration?: number;
maxIterations?: number;
status: "completed" | "executing" | "failed" | "planning" | "replanning";
tasks: object[];
}>;

Legacy plan shape — preserved for the synthesizer's input contract.


PlanTaskSchema​

const PlanTaskSchema: z.ZodObject<{
dependencies: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
error: z.ZodOptional<z.ZodString>;
goal: z.ZodString;
id: z.ZodString;
result: z.ZodOptional<z.ZodAny>;
status: z.ZodEnum<["pending", "in-progress", "completed", "failed", "skipped"]>;
}, "strip", z.ZodTypeAny, {
dependencies: string[];
error?: string;
goal: string;
id: string;
result?: any;
status: "completed" | "failed" | "in-progress" | "pending" | "skipped";
}, {
dependencies?: string[];
error?: string;
goal: string;
id: string;
result?: any;
status: "completed" | "failed" | "in-progress" | "pending" | "skipped";
}>;

Legacy P&E task shape — preserved for output compatibility.


replannerOutputSchema​

const replannerOutputSchema: z.ZodObject<{
tasks: z.ZodArray<z.ZodObject<{
deps: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
goal: z.ZodString;
id: z.ZodString;
}, "strip", ZodTypeAny, {
deps: string[];
goal: string;
id: string;
}, {
deps?: string[];
goal: string;
id: string;
}>, "many">;
}, "strip", ZodTypeAny, {
tasks: object[];
}, {
tasks: object[];
}>;

Output schema for the default replanner generator — the new tasks to add.

Functions​

buildSynthesizerUserPrompt()​

function buildSynthesizerUserPrompt(input): string;

Builds the user prompt for a plan synthesizer from completed task results. Exported so custom synthesizers can reuse the same formatting.

Parameters​

input​

SynthesizerPromptInput

Returns​

string


createApplyReplan()​

function createApplyReplan(options): BlockDefinition<ZodObject<{
tasks: ZodArray<ZodObject<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, "passthrough", ZodTypeAny, objectOutputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, ZodTypeAny, "passthrough">, objectInputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, ZodTypeAny, "passthrough">>, "many">;
}, "passthrough", ZodTypeAny, objectOutputType<{
tasks: ZodArray<ZodObject<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, "passthrough", ZodTypeAny, objectOutputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[..., ...]>>;
}, ZodTypeAny, "passthrough">, objectInputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[..., ...]>>;
}, ZodTypeAny, "passthrough">>, "many">;
}, ZodTypeAny, "passthrough">, objectInputType<{
tasks: ZodArray<ZodObject<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, "passthrough", ZodTypeAny, objectOutputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[..., ...]>>;
}, ZodTypeAny, "passthrough">, objectInputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[..., ...]>>;
}, ZodTypeAny, "passthrough">>, "many">;
}, ZodTypeAny, "passthrough">>, ZodObject<{
decision: ZodDefault<ZodEnum<["continue", "replan", "complete"]>>;
}, "strip", ZodTypeAny, {
decision: "continue" | "replan" | "complete";
}, {
decision?: "continue" | "replan" | "complete";
}>, objectOutputType<{
tasks: ZodArray<ZodObject<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, "passthrough", ZodTypeAny, objectOutputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, ZodTypeAny, "passthrough">, objectInputType<{
dependencies: ZodOptional<ZodArray<ZodString, "many">>;
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
input: ZodOptional<ZodUnknown>;
maxAttempts: ZodOptional<ZodNumber>;
priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>;
}, ZodTypeAny, "passthrough">>, "many">;
}, ZodTypeAny, "passthrough">, {
decision: "continue";
}>;

Build the apply-replan handler. The input may carry the evaluator's pre-baked tasks OR the replanner's output; either way we expect a tasks: TaskInit[] array.

Parameters​

options​

ApplyReplanOptions

Returns​

BlockDefinition<ZodObject<{ tasks: ZodArray<ZodObject<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, "passthrough", ZodTypeAny, objectOutputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, ZodTypeAny, "passthrough">, objectInputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, ZodTypeAny, "passthrough">>, "many">; }, "passthrough", ZodTypeAny, objectOutputType<{ tasks: ZodArray<ZodObject<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, "passthrough", ZodTypeAny, objectOutputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[..., ...]>>; }, ZodTypeAny, "passthrough">, objectInputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[..., ...]>>; }, ZodTypeAny, "passthrough">>, "many">; }, ZodTypeAny, "passthrough">, objectInputType<{ tasks: ZodArray<ZodObject<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, "passthrough", ZodTypeAny, objectOutputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[..., ...]>>; }, ZodTypeAny, "passthrough">, objectInputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[..., ...]>>; }, ZodTypeAny, "passthrough">>, "many">; }, ZodTypeAny, "passthrough">>, ZodObject<{ decision: ZodDefault<ZodEnum<["continue", "replan", "complete"]>>; }, "strip", ZodTypeAny, { decision: "continue" | "replan" | "complete"; }, { decision?: "continue" | "replan" | "complete"; }>, objectOutputType<{ tasks: ZodArray<ZodObject<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, "passthrough", ZodTypeAny, objectOutputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, ZodTypeAny, "passthrough">, objectInputType<{ dependencies: ZodOptional<ZodArray<ZodString, "many">>; deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; input: ZodOptional<ZodUnknown>; maxAttempts: ZodOptional<ZodNumber>; priority: ZodOptional<ZodUnion<[ZodNumber, ZodString]>>; }, ZodTypeAny, "passthrough">>, "many">; }, ZodTypeAny, "passthrough">, { decision: "continue"; }>


createBuildPlanOutput()​

function createBuildPlanOutput(options): BlockDefinition<ZodUnknown, ZodObject<{
completedSteps: ZodNumber;
goal: ZodString;
status: ZodEnum<["completed", "failed"]>;
tasks: ZodArray<ZodObject<{
error: ZodOptional<ZodString>;
goal: ZodString;
id: ZodString;
result: ZodOptional<ZodUnknown>;
status: ZodString;
}, "strip", ZodTypeAny, {
error?: string;
goal: string;
id: string;
result?: unknown;
status: string;
}, {
error?: string;
goal: string;
id: string;
result?: unknown;
status: string;
}>, "many">;
totalSteps: ZodNumber;
}, "strip", ZodTypeAny, {
completedSteps: number;
goal: string;
status: "completed" | "failed";
tasks: object[];
totalSteps: number;
}, {
completedSteps: number;
goal: string;
status: "completed" | "failed";
tasks: object[];
totalSteps: number;
}>, unknown, {
completedSteps: number;
goal: string;
status: "completed" | "failed";
tasks: object[];
totalSteps: number;
}>;

Build the legacy { goal, status, tasks, completedSteps, totalSteps } output shape from the request-scoped collection. Wired both as a standalone return value (when synthesizer: false) and as the input to a configured synthesizer.

Parameters​

options​
name​

string

Returns​

BlockDefinition<ZodUnknown, ZodObject<{ completedSteps: ZodNumber; goal: ZodString; status: ZodEnum<["completed", "failed"]>; tasks: ZodArray<ZodObject<{ error: ZodOptional<ZodString>; goal: ZodString; id: ZodString; result: ZodOptional<ZodUnknown>; status: ZodString; }, "strip", ZodTypeAny, { error?: string; goal: string; id: string; result?: unknown; status: string; }, { error?: string; goal: string; id: string; result?: unknown; status: string; }>, "many">; totalSteps: ZodNumber; }, "strip", ZodTypeAny, { completedSteps: number; goal: string; status: "completed" | "failed"; tasks: object[]; totalSteps: number; }, { completedSteps: number; goal: string; status: "completed" | "failed"; tasks: object[]; totalSteps: number; }>, unknown, { completedSteps: number; goal: string; status: "completed" | "failed"; tasks: object[]; totalSteps: number; }>


createCaptureAndPlan()​

function createCaptureAndPlan(options): BlockDefinition<any, any, any, any>;

Build the entry sequencer. The returned block runs once at the top of the plan-and-execute pipeline before the first board drain.

Parameters​

options​

CaptureAndPlanOptions

Returns​

BlockDefinition<any, any, any, any>


createLLMEvaluator()​

function createLLMEvaluator(options): BlockDefinition<ZodTypeAny, ZodObject<{
decision: ZodEnum<["continue", "replan", "complete"]>;
reasoning: ZodString;
tasks: ZodOptional<ZodArray<ZodObject<{
deps: ZodOptional<ZodArray<ZodString, "many">>;
goal: ZodString;
id: ZodOptional<ZodString>;
}, "strip", ZodTypeAny, {
deps?: string[];
goal: string;
id?: string;
}, {
deps?: string[];
goal: string;
id?: string;
}>, "many">>;
}, "strip", ZodTypeAny, {
decision: "continue" | "replan" | "complete";
reasoning: string;
tasks?: object[];
}, {
decision: "continue" | "replan" | "complete";
reasoning: string;
tasks?: object[];
}>, unknown, {
decision: "continue" | "replan" | "complete";
reasoning: string;
tasks?: object[];
}>;

LLM-backed evaluator. The prompt receives a snapshot of the current collection (id/goal/status/output/error/feedback per task) and the caller's overall goal, and returns a { decision, reasoning }.

Parameters​

options​
model?​

string

name​

string

Returns​

BlockDefinition<ZodTypeAny, ZodObject<{ decision: ZodEnum<["continue", "replan", "complete"]>; reasoning: ZodString; tasks: ZodOptional<ZodArray<ZodObject<{ deps: ZodOptional<ZodArray<ZodString, "many">>; goal: ZodString; id: ZodOptional<ZodString>; }, "strip", ZodTypeAny, { deps?: string[]; goal: string; id?: string; }, { deps?: string[]; goal: string; id?: string; }>, "many">>; }, "strip", ZodTypeAny, { decision: "continue" | "replan" | "complete"; reasoning: string; tasks?: object[]; }, { decision: "continue" | "replan" | "complete"; reasoning: string; tasks?: object[]; }>, unknown, { decision: "continue" | "replan" | "complete"; reasoning: string; tasks?: object[]; }>


createSynthesize()​

function createSynthesize(options):
| BlockDefinition<ZodUnknown, ZodObject<{
completedSteps: ZodNumber;
goal: ZodString;
status: ZodEnum<["completed", "failed"]>;
tasks: ZodArray<ZodObject<{
error: ZodOptional<ZodString>;
goal: ZodString;
id: ZodString;
result: ZodOptional<ZodUnknown>;
status: ZodString;
}, "strip", ZodTypeAny, {
error?: string;
goal: string;
id: string;
result?: unknown;
status: string;
}, {
error?: string;
goal: string;
id: string;
result?: unknown;
status: string;
}>, "many">;
totalSteps: ZodNumber;
}, "strip", ZodTypeAny, {
completedSteps: number;
goal: string;
status: "completed" | "failed";
tasks: object[];
totalSteps: number;
}, {
completedSteps: number;
goal: string;
status: "completed" | "failed";
tasks: object[];
totalSteps: number;
}>, unknown, {
completedSteps: number;
goal: string;
status: "completed" | "failed";
tasks: object[];
totalSteps: number;
}>
| SequencerDefinition<any, any, ZodObject<{
goal: ZodDefault<ZodString>;
iteration: ZodDefault<ZodNumber>;
status: ZodOptional<ZodEnum<["planning", "executing", "replanning", "synthesizing", "completed", "failed"]>>;
}, "strip", ZodTypeAny, {
goal: string;
iteration: number;
status?: | "completed"
| "failed"
| "planning"
| "executing"
| "replanning"
| "synthesizing";
}, {
goal?: string;
iteration?: number;
status?: | "completed"
| "failed"
| "planning"
| "executing"
| "replanning"
| "synthesizing";
}>, undefined>;

Build the synthesize block.

  • synthesizer: false → just buildPlanOutput. Output is the legacy plan shape.
  • synthesizer present → sequencer composing boardMetaSynthesizing → buildPlanOutput → synthesizer.

Parameters​

options​

CreateSynthesizeOptions

Returns​

| BlockDefinition<ZodUnknown, ZodObject<{ completedSteps: ZodNumber; goal: ZodString; status: ZodEnum<["completed", "failed"]>; tasks: ZodArray<ZodObject<{ error: ZodOptional<ZodString>; goal: ZodString; id: ZodString; result: ZodOptional<ZodUnknown>; status: ZodString; }, "strip", ZodTypeAny, { error?: string; goal: string; id: string; result?: unknown; status: string; }, { error?: string; goal: string; id: string; result?: unknown; status: string; }>, "many">; totalSteps: ZodNumber; }, "strip", ZodTypeAny, { completedSteps: number; goal: string; status: "completed" | "failed"; tasks: object[]; totalSteps: number; }, { completedSteps: number; goal: string; status: "completed" | "failed"; tasks: object[]; totalSteps: number; }>, unknown, { completedSteps: number; goal: string; status: "completed" | "failed"; tasks: object[]; totalSteps: number; }> | SequencerDefinition<any, any, ZodObject<{ goal: ZodDefault<ZodString>; iteration: ZodDefault<ZodNumber>; status: ZodOptional<ZodEnum<["planning", "executing", "replanning", "synthesizing", "completed", "failed"]>>; }, "strip", ZodTypeAny, { goal: string; iteration: number; status?: | "completed" | "failed" | "planning" | "executing" | "replanning" | "synthesizing"; }, { goal?: string; iteration?: number; status?: | "completed" | "failed" | "planning" | "executing" | "replanning" | "synthesizing"; }>, undefined>


createTaskEvaluator()​

function createTaskEvaluator(options): BlockDefinition<ZodUnknown, ZodObject<{
decision: ZodEnum<["continue", "replan", "complete"]>;
}, "strip", ZodTypeAny, {
decision: "continue" | "replan" | "complete";
}, {
decision: "continue" | "replan" | "complete";
}>, unknown,
| {
decision: "complete";
}
| {
decision: "continue";
}>;

Default no-LLM evaluator. Increments iteration, applies the iteration cap, and resolves to complete when no executable tasks remain in the collection.

Parameters​

options​

DefaultEvaluatorOptions

Returns​

BlockDefinition<ZodUnknown, ZodObject<{ decision: ZodEnum<["continue", "replan", "complete"]>; }, "strip", ZodTypeAny, { decision: "continue" | "replan" | "complete"; }, { decision: "continue" | "replan" | "complete"; }>, unknown, | { decision: "complete"; } | { decision: "continue"; }>


evaluatePlanProgress()​

function evaluatePlanProgress(options):
| BlockDefinition<ZodUnknown, ZodObject<{
decision: ZodEnum<["continue", "replan", "complete"]>;
}, "strip", ZodTypeAny, {
decision: "continue" | "replan" | "complete";
}, {
decision: "continue" | "replan" | "complete";
}>, unknown,
| {
decision: "complete";
}
| {
decision: "continue";
}>
| SequencerDefinition<unknown, objectOutputType<{
decision: ZodEnum<["continue", "replan", "complete"]>;
reasoning: ZodString;
tasks: ZodOptional<ZodArray<ZodUnknown, "many">>;
}, ZodTypeAny, "passthrough">, undefined, undefined>;

Build the active evaluator block based on configuration.

  • enableReplanning: false → createTaskEvaluator (single handler, no LLM, no sequencer overhead).

  • enableReplanning: true → a sequencer composition:

    preflight → .stepIf(!skipLLM, llmEvaluator) → .map(normalize) → .tap(emitReplanningMeta)

    The preflight handler increments iteration, applies the iteration cap, and short-circuits with a synthesised complete verdict when the cap is reached. Otherwise it passes to the LLM evaluator. The trailing .tap() patches status: "replanning" and emits the task-board-meta extension when the verdict is "replan".

The wrapper sequencer intentionally has no stateSchema — that lets ctx.sequencer resolve to the outer pipeline's state container so the preflight and tap can read/patch iteration and status on the pipeline state, not a fresh shadow.

Parameters​

options​

CreateEvaluateProgressOptions

Returns​

| BlockDefinition<ZodUnknown, ZodObject<{ decision: ZodEnum<["continue", "replan", "complete"]>; }, "strip", ZodTypeAny, { decision: "continue" | "replan" | "complete"; }, { decision: "continue" | "replan" | "complete"; }>, unknown, | { decision: "complete"; } | { decision: "continue"; }> | SequencerDefinition<unknown, objectOutputType<{ decision: ZodEnum<["continue", "replan", "complete"]>; reasoning: ZodString; tasks: ZodOptional<ZodArray<ZodUnknown, "many">>; }, ZodTypeAny, "passthrough">, undefined, undefined>


normalizeOutputStatus()​

function normalizeOutputStatus(t): string;

Translate a substrate Task to its legacy P&E status string.

The substrate uses pending | in_progress | completed | errored | cancelled | blocked | parked. The legacy P&E vocabulary — what external consumers depend on — is pending | in-progress | completed | failed | skipped. The mapping:

  • errored → failed
  • cancelled w/ "skipped" label → skipped
  • cancelled (no skipped label) → skipped (treated as cascade-skip)
  • in_progress → in-progress
  • everything else → pass through (pending, completed)

Parameters​

t​

Task

Returns​

string


planAndExecute()​

function planAndExecute<TOutputSchema>(config): SequencerDefinition<any, any>;

Build a planAndExecute block. Composes a taskBoard with a planner front and an evaluator/replanner replan-loop, returning a sequencer that drains task work then synthesizes the result.

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Parameters​

config​

PlanAndExecuteConfig<TOutputSchema>

Returns​

SequencerDefinition<any, any>

References​

PlanAndExecuteInput​

Re-exports PlanAndExecuteInput


planAndExecuteInputSchema​

Re-exports planAndExecuteInputSchema