Skip to main content

@flow-state-dev/patterns/supervisor

Interfaces​

SupervisorConfig​

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Properties​

context?​
context?: GeneratorSlot<any, any>;
history?​
history?: GeneratorHistoryConfig<any, any>;
instructions?​
instructions?: InstructionsSlot<{
goal: string;
}>;
maxAttemptsPerTask?​
maxAttemptsPerTask?: number;

Per-task retry budget for review rejection. Default 3.

maxConcurrency?​
maxConcurrency?: number;

Worker pool size. Default 3.

maxEnqueuedTasks?​
maxEnqueuedTasks?: number | null;
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 it BINDS this pattern out of the box: maxAttemptsPerTask defaults to 3, so a supervisor board retries by default and a large plan on a flaky day can reach the ceiling legitimately. Without this option the default would be an un-opt-out-able ceiling on an existing pattern.

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.

name​
name: string;
onSubTaskError?​
onSubTaskError?: SubTaskErrorStrategy;
outputSchema?​
outputSchema?: TOutputSchema;
planner?​
planner?: BlockDefinition<any, any, any, any>;
reviewCriteria?​
reviewCriteria?: string[];
reviewer?​
reviewer?: false | BlockDefinition<any, any, any, any>;

Reviewer block. Pass false to disable per-task review entirely.

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

Synthesize a self-contained goal from conversation before planning. false (default) uses the input goal verbatim; true runs a built-in synthesizer; a BlockDefinition supplies a custom one.

synthesizer?​
synthesizer?: BlockDefinition<any, any, any, any>;
synthesizerVisibility?​
synthesizerVisibility?: ItemVisibility;
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) copies the goal into every gap-task; false leaves it empty; a BlockDefinition fills per-task context in one call. A planner-emitted context always wins.

uses?​
uses?: UsesSlot;
worker?​
worker?: BlockDefinition<any, any, any, any>;

Single uniform worker. Mutually exclusive with workers.

workers?​
workers?: Record<string, BlockDefinition<any, any, any, any>>;

Worker registry — Record<assignee, BlockDefinition>.

Type Aliases​

PlannerOutput​

type PlannerOutput = z.infer<typeof plannerOutputSchema>;

ReviewerInput​

type ReviewerInput = z.infer<typeof reviewerInputSchema>;

ReviewerVerdict​

type ReviewerVerdict = z.infer<typeof reviewerVerdictSchema>;

SubTaskErrorStrategy​

type SubTaskErrorStrategy = "skip" | "fail";

SupervisorInput​

type SupervisorInput = z.infer<typeof supervisorInputSchema>;

SupervisorState​

type SupervisorState = z.infer<typeof supervisorStateSchema>;

Variables​

plannerOutputSchema​

const plannerOutputSchema: z.ZodObject<{
tasks: z.ZodArray<z.ZodObject<{
assignee: z.ZodOptional<z.ZodString>;
context: z.ZodOptional<z.ZodString>;
deps: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
goal: z.ZodString;
id: z.ZodString;
priority: z.ZodOptional<z.ZodEnum<["high", "medium", "low"]>>;
}, "strip", z.ZodTypeAny, {
assignee?: string;
context?: string;
deps?: string[];
goal: string;
id: string;
priority?: "high" | "low" | "medium";
}, {
assignee?: string;
context?: string;
deps?: string[];
goal: string;
id: string;
priority?: "high" | "low" | "medium";
}>, "many">;
}, "strip", z.ZodTypeAny, {
tasks: object[];
}, {
tasks: object[];
}>;

Planner output — task list.


supervisorInputSchema​

const supervisorInputSchema: z.ZodObject<{
goal: z.ZodString;
}, "strip", z.ZodTypeAny, {
goal: string;
}, {
goal: string;
}>;

supervisorStateSchema​

const supervisorStateSchema: z.ZodObject<{
goal: z.ZodDefault<z.ZodString>;
iteration: z.ZodDefault<z.ZodNumber>;
reviewMetadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
entered: z.ZodOptional<z.ZodBoolean>;
lastVerdict: z.ZodOptional<z.ZodEnum<["approve", "reject", "needs-revision"]>>;
}, "strip", z.ZodTypeAny, {
entered?: boolean;
lastVerdict?: "approve" | "needs-revision" | "reject";
}, {
entered?: boolean;
lastVerdict?: "approve" | "needs-revision" | "reject";
}>>>;
status: z.ZodOptional<z.ZodEnum<["planning", "executing", "replanning", "synthesizing", "completed", "failed"]>>;
}, "strip", z.ZodTypeAny, {
goal: string;
iteration: number;
reviewMetadata: Record<string, {
entered?: boolean;
lastVerdict?: "approve" | "needs-revision" | "reject";
}>;
status?: | "completed"
| "executing"
| "failed"
| "planning"
| "replanning"
| "synthesizing";
}, {
goal?: string;
iteration?: number;
reviewMetadata?: Record<string, {
entered?: boolean;
lastVerdict?: "approve" | "needs-revision" | "reject";
}>;
status?: | "completed"
| "executing"
| "failed"
| "planning"
| "replanning"
| "synthesizing";
}>;

Outer sequencer state: goal, optional pattern-level status, iteration counter, plus per-task reviewer audit metadata. reviewMetadata is populated by stampReviewEntered / applyVerdict and read by labelFailedReviews to classify terminal task failures. Lives on the supervisor sequencer's own (in-memory, lock-serialized) state instead of the task collection so reviewer writes stay off the request scope's shared mutation queue.

Functions​

buildReviewedWorker()​

function buildReviewedWorker(options):
| BlockDefinition<any, any, any, any>
| SequencerDefinition<any, unknown, ZodObject<{
attempts: ZodDefault<ZodNumber>;
goal: ZodDefault<ZodString>;
taskId: ZodOptional<ZodString>;
workerOutput: ZodOptional<ZodUnknown>;
}, "strip", ZodTypeAny, {
attempts: number;
goal: string;
taskId?: string;
workerOutput?: unknown;
}, {
attempts?: number;
goal?: string;
taskId?: string;
workerOutput?: unknown;
}>, undefined>;

Build a per-task reviewed worker. See module doc for pipeline shape.

Parameters​

options​

BuildReviewedWorkerOptions

Returns​

| BlockDefinition<any, any, any, any> | SequencerDefinition<any, unknown, ZodObject<{ attempts: ZodDefault<ZodNumber>; goal: ZodDefault<ZodString>; taskId: ZodOptional<ZodString>; workerOutput: ZodOptional<ZodUnknown>; }, "strip", ZodTypeAny, { attempts: number; goal: string; taskId?: string; workerOutput?: unknown; }, { attempts?: number; goal?: string; taskId?: string; workerOutput?: unknown; }>, undefined>


createCaptureAndPlan()​

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

Build the entry sequencer; runs once at the top of the pipeline.

Parameters​

options​

CaptureAndPlanOptions

Returns​

BlockDefinition<any, any, any, any>


createLabelFailedReviews()​

function createLabelFailedReviews(options): BlockDefinition<ZodUnknown, ZodTypeAny, unknown, void>;

Build the label-failed-reviews handler.

Parameters​

options​

LabelFailedReviewsOptions

Returns​

BlockDefinition<ZodUnknown, ZodTypeAny, unknown, void>


createSynthesize()​

function createSynthesize(options): SequencerDefinition<any, any, ZodObject<{
goal: ZodDefault<ZodString>;
iteration: ZodDefault<ZodNumber>;
reviewMetadata: ZodDefault<ZodRecord<ZodString, ZodObject<{
entered: ZodOptional<ZodBoolean>;
lastVerdict: ZodOptional<ZodEnum<["approve", "reject", "needs-revision"]>>;
}, "strip", ZodTypeAny, {
entered?: boolean;
lastVerdict?: "approve" | "reject" | "needs-revision";
}, {
entered?: boolean;
lastVerdict?: "approve" | "reject" | "needs-revision";
}>>>;
status: ZodOptional<ZodEnum<["planning", "executing", "replanning", "synthesizing", "completed", "failed"]>>;
}, "strip", ZodTypeAny, {
goal: string;
iteration: number;
reviewMetadata: Record<string, {
entered?: boolean;
lastVerdict?: "approve" | "needs-revision" | "reject";
}>;
status?: | "completed"
| "failed"
| "planning"
| "executing"
| "replanning"
| "synthesizing";
}, {
goal?: string;
iteration?: number;
reviewMetadata?: Record<string, {
entered?: boolean;
lastVerdict?: "approve" | "reject" | "needs-revision";
}>;
status?: | "completed"
| "failed"
| "planning"
| "executing"
| "replanning"
| "synthesizing";
}>, undefined>;

Build the synthesize sequencer.

Parameters​

options​

CreateSynthesizeOptions

Returns​

SequencerDefinition<any, any, ZodObject<{ goal: ZodDefault<ZodString>; iteration: ZodDefault<ZodNumber>; reviewMetadata: ZodDefault<ZodRecord<ZodString, ZodObject<{ entered: ZodOptional<ZodBoolean>; lastVerdict: ZodOptional<ZodEnum<["approve", "reject", "needs-revision"]>>; }, "strip", ZodTypeAny, { entered?: boolean; lastVerdict?: "approve" | "reject" | "needs-revision"; }, { entered?: boolean; lastVerdict?: "approve" | "reject" | "needs-revision"; }>>>; status: ZodOptional<ZodEnum<["planning", "executing", "replanning", "synthesizing", "completed", "failed"]>>; }, "strip", ZodTypeAny, { goal: string; iteration: number; reviewMetadata: Record<string, { entered?: boolean; lastVerdict?: "approve" | "needs-revision" | "reject"; }>; status?: | "completed" | "failed" | "planning" | "executing" | "replanning" | "synthesizing"; }, { goal?: string; iteration?: number; reviewMetadata?: Record<string, { entered?: boolean; lastVerdict?: "approve" | "reject" | "needs-revision"; }>; status?: | "completed" | "failed" | "planning" | "executing" | "replanning" | "synthesizing"; }>, undefined>


supervisor()​

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

Build a supervisor block. See module doc for pipeline shape.

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Parameters​

config​

SupervisorConfig<TOutputSchema>

Returns​

SequencerDefinition<any, any>

References​

reviewerInputSchema​

Re-exports reviewerInputSchema


reviewerVerdictSchema​

Re-exports reviewerVerdictSchema