Skip to main content

Patterns

A pattern is a ready-made arrangement of blocks for a shape of work that comes up often: fan a goal out to parallel workers, have a reviewer check each result, let agents take turns, run analyzers over a finished reply. You call the pattern's function with a config object and place what it returns in a flow like any other block.

Every pattern has a default block for each role it needs, usually a model call, so a config names only what differs from the default. Values written intent/chat or intent/synthesize are model aliases, not model ids; Models says how they resolve. This page covers each pattern, and goalSeekLoop, the loop parallelTasks and planAndExecute run on.

Imports​

NameImport from
parallelTasks, planAndExecute, supervisor, routedSpecialists, eventActors, roundRobin, debate@flow-state-dev/patterns
responseAuditor, createModerator, createJudgeSubpath only: @flow-state-dev/patterns/response-auditor, /debate
createReferee@flow-state-dev/patterns/round-robin, or the root as createRoundRobinReferee
Other exports of a patternIts subpath: /plan-and-execute, /supervisor, /routed-specialists, /event-actors, /round-robin, /debate. parallelTasks has none
goalSeekLoop, taskBoard, mapToVerdict, Verdict, taskWorkerInputSchema@flow-state-dev/orchestration/task-board
defineResource, utility.decomposer, utility.combiner@flow-state-dev/core
biasAnalyzer@thought-fabric/core/metacognition

Signatures of every export are in the generated patterns API. This page lists what a caller observes.

Which patterns run a task board​

PatternTask boardNotes
parallelTasksYes, through goalSeekLoopOne drain, no feedback loop
planAndExecuteYes, through goalSeekLoopAn evaluator decides after each drain whether to continue, replan or complete
supervisorYes, directlyEach task runs as worker, then reviewer, then verdict
eventActorsYes, directlyOne worker per actor
routedSpecialistsNoOne iteration at a time; each iteration is a task in a collection
roundRobin, debateNoA task per (round, agent) turn, kept as an audit record
responseAuditorNo tasksA side-chain sequencer with parallel analyzers

Claim order, the default for what a board does when a task errors, and the board's own options are on Task board. Each pattern's concurrency option and default is in its table below.

Shared options​

Task caps​

parallelTasks, planAndExecute, supervisor and eventActors take maxTotalTasks and maxEnqueuedTasks. The first three also take maxTotalRetries; eventActors has none, because its tasks cannot retry. The defaults are 500, 100 and 50, and each pattern's table repeats them. What the caps mean, how to remove one with null, and what happens when a plan crosses one are on Task board.

  • maxTotalRetries binds only a board whose tasks can retry: supervisor, planAndExecute once maxAttemptsPerTask is above 1, and parallelTasks only for a task the planner gave its own maxAttempts.
  • eventActors checks a batch of dispatches against the caps as one unit. See Re-emission under eventActors.

onSubTaskError​

parallelTasks and supervisor. Default "skip".

ValueEffect
"skip"The failing task is recorded errored and its siblings continue. Its output is left out of what the synthesizer receives. If every task fails, the synthesizer receives an empty array (parallelTasks) or an empty results (supervisor)
"fail"The first failure throws and fails the run
"retry"Not in the type. Passing it logs a warning at construction and behaves as "skip". For supervisor the warning points at maxAttemptsPerTask

taskContext and synthesizeGoal​

planAndExecute and supervisor. parallelTasks has neither: a task carries a context only if the planner emitted one.

OptionValueEffect
taskContext"goal" (default)Each task the planner left without a context gets the goal copied in. A planner-supplied context is kept
falseTasks keep no context unless the planner set one
a blockRuns once over { goal, tasks } and returns { tasks }. The block owns the contexts it returns and is not filtered afterwards
synthesizeGoalfalse (default)The goal is used as given
trueA built-in step rewrites the goal into a self-contained one before planning, reading the last 8 history items. If the model call fails, the original goal is used
a blockMust return { ...input, goal } and handles its own failures

The rewritten goal is what the planner, replanner and synthesizer see. In planAndExecute, tasks a replan adds without a context get the goal copied in, with the default taskContext or a custom block, but not when taskContext is false. A custom block runs on the initial plan only. Replanner output has no context: { id, goal, deps }.

What a block worker receives​

Block workers on parallelTasks and supervisor receive a TaskWorkerInput. Its fields are on Task collections. Where a pattern fills one differently:

  • parallelTasks: input is the task's goal unless the planner set input.
  • supervisor: input is absent unless the planner set it. feedback is the reviewer's feedback on a retry. priorWork holds the outputs of declared dependencies only.

The planAndExecute step executor receives a different shape, given under its section.

Item visibility​

Every *Visibility option takes an ItemVisibility, { client, history }. What each flag controls is on Items and the stream. The default for each option is in its table.

parallelTasks​

Fan a goal out into sub-tasks, run them, combine the results. One pass.

  • Input: { goal: string }, schema parallelTasksInputSchema.
  • Output: the synthesizer's result. With the default combiner, { combined: unknown, mergeNotes?: string[] }; with no completed outputs, { combined: [], mergeNotes: ["No artifacts provided; returned an empty combined array."] }.
  • Planner: receives { goal }, returns { tasks: Array<{ goal, id?, title?, assignee?, deps?, dependencies?, priority?, input?, context?, maxAttempts? }> }. id defaults to task-1, task-2, in order. deps falls back to dependencies, then []. priority counts only when it is a number. A title or context of null is treated as absent.
  • Synthesizer: receives unknown[], the output of every completed task that has one.
  • There is no model, uses, context or visibility option. The default planner is a model call with the decomposer's model, openai/gpt-6-luna; the default combiner makes no model call.
OptionTypeDefaultWhat it does
namestringrequiredInstance name and task collection id
workerblockrequiredRuns once per sub-task; receives a TaskWorkerInput
maxConcurrencynumber3Sub-tasks running at once
maxTotalTasks, maxEnqueuedTasks, maxTotalRetries500 / 100 / 50Task caps. maxTotalRetries binds only a task the planner gave its own maxAttempts
plannerblockutility.decomposer()Returns { tasks }
synthesizerblockutility.combiner()Combines the completed outputs
onSubTaskError"skip" | "fail""skip"See onSubTaskError
outputSchemaZod schemanonePassed to the default combiner only; ignored when you supply synthesizer

supervisor​

Plan, run workers in parallel, review each result, retry on rejection, label failures, synthesize.

  • Input: { goal: string }, schema supervisorInputSchema.
  • Output: the synthesizer's output. The default synthesizer returns a string unless outputSchema is set.
  • Giving neither worker nor workers throws [supervisor] "<name>" requires either `worker` or `workers` . The two are alternatives.
  • There is no model option. The planner uses the decomposer's model; the reviewer and synthesizer use intent/synthesize.
OptionTypeDefaultWhat it does
namestringrequiredInstance name and task collection id
workerblocknoneOne worker for every task. Exclusive with workers
workersRecord<assignee, block>noneThe task's assignee picks the worker
instructionsstring or (input, ctx) => stringnoneAdded to the default synthesizer's prompt
reviewCriteriastring[]noneHanded to the reviewer as criteria; the default reviewer renders them as a numbered list
maxAttemptsPerTasknumber3Attempts per task before it fails for good. A planner-supplied maxAttempts wins
maxConcurrencynumber3Workers running at once
maxTotalTasks, maxEnqueuedTasks, maxTotalRetries500 / 100 / 50Task caps. maxTotalRetries binds by default here
plannerblockutility.decomposer()Returns { tasks: [{ id, goal, assignee?, deps?, priority?, context? }] }
taskContext"goal" | false | block"goal"See taskContext
synthesizeGoalboolean | blockfalseSee synthesizeGoal
reviewerblock or falseLLM reviewer, intent/synthesizefalse removes review: output goes straight to complete, and a task that fails is labelled worker-error
synthesizerblockLLM, intent/synthesizeReceives { goal, results, resultItems? }
onSubTaskError"skip" | "fail""skip"See onSubTaskError
outputSchemaZod schemaz.string()Output of the default synthesizer
contextcontext slotnoneForwarded to the default planner, reviewer and synthesizer
historyhistory confignoneForwarded to the default planner and synthesizer
usescapabilitiesnoneForwarded to the default reviewer and synthesizer
reviewerVisibilityItemVisibility{ client: true, history: false }Default reviewer's items
synthesizerVisibilityItemVisibility{ client: true, history: true }Default synthesizer's items

Review​

The worker runs and its output goes to the reviewer. An approve verdict passes the output on as the task's result. reject and needs-revision fail the attempt, with the verdict's feedback as the error text, and the task returns to pending while attempts remain. A worker that throws spends the same attempt budget as a rejection.

ShapeFields
Reviewer input{ taskId, goal, attempts (default 1), workerOutput, criteria? }. criteria is present only when reviewCriteria is non-empty
Reviewer verdict{ decision: "approve" | "reject" | "needs-revision", feedback?: string, criteria?: Array<{ name, score }>, reasoning?: string }
Synthesizer input{ goal, results: unknown[], resultItems?: Array<{ taskId, goal, items }> }. results is the output of every completed task

feedback is optional in the schema. With none, the retry's error text is Reviewer <decision> the task output, and that text is what the worker receives as feedback on its next attempt. The default reviewer usually includes it.

After the drain, every errored task gets one label. A failed or cancelled task's pending dependents are cancelled by the board and labelled skipped (see Task board).

LabelMeaning
failed-reviewThe last verdict was reject or needs-revision
reviewer-errorThe reviewer threw before returning a verdict
worker-errorThe worker failed before review, or reviewer: false

planAndExecute​

Plan a task graph, run it on a board, evaluate, optionally replan, synthesize.

  • Input: { goal: string }, schema planAndExecuteInputSchema.
  • State: { goal: string (default ""), status?: "planning" | "executing" | "replanning" | "synthesizing" | "completed" | "failed", iteration: number (default 0) }, schema planAndExecuteStateSchema.
  • Output with synthesizer: false: { goal, status: "completed" | "failed", tasks: Array<{ id, goal, status, result?, error? }>, completedSteps, totalSteps }. With a synthesizer, that shape is its input and its return is the output.
  • Replanner output: { tasks: Array<{ id, goal, deps (default []) }> }.
  • Step executor input, the shape your stepExecutor block receives (not a TaskWorkerInput): { stepId, goal, context?, dependencyResults? }. dependencyResults is keyed by dependency task id, holds completed dependencies only, and is absent when there are none.
  • Default step executor output: { summary: string, success: boolean, reason: string (default ""), sources: Array<{ title (default ""), url }> (default []) }. A result with success: false throws its reason (or Task did not produce a result). That fails the task and cancels its dependents, as does any thrown error.
  • An evaluator that throws fails the request.
Output fieldValues and rule
task statuspending, in-progress, completed, failed, skipped. Board errored becomes failed; every cancelled task becomes skipped; other board statuses (blocked, parked) pass through under their own name
task errorThe task's error, or its feedback when it has no error
overall statuscompleted when there are no tasks or at least one non-skipped task completed. failed when no non-skipped task completed (failed, pending or blocked tasks all count), or every task was skipped
completedSteps, totalStepsCount of completed tasks, and of all tasks

Evaluator​

With enableReplanning: false the default evaluator makes no model call. It increments iteration and returns complete once iteration >= maxIterations or no executable work remains, else continue. With enableReplanning: true it is a model call (openai/gpt-6-luna unless model is set) returning { decision, reasoning, tasks? }; the iteration cap forces complete all the same.

A custom evaluator returns { decision: "continue" | "complete" | "replan", score?, feedback?, reasoning?, tasks? }. A replan carrying tasks adds those tasks directly; without them the replanner runs.

Config​

OptionTypeDefaultWhat it does
namestringrequiredInstance name and collection id
plannerblockutility.decomposer()Returns { tasks }
stepExecutorblockLLM executor, intent/synthesizeRuns each task
evaluatorblockbuilt inDecides continue, replan or complete
replannerblockLLM replanner, openai/gpt-6-lunaRuns on replan with no inline tasks
maxIterationsnumber3Drains the loop may run, and the evaluator's iteration cap
enableReplanningbooleanfalsetrue turns on the model-backed evaluator
synthesizerblock or falseLLM synthesizer, openai/gpt-6-lunafalse returns the output shape above
outputSchemaZod schemaz.string()Not read. The default synthesizer always returns a string; pass your own synthesizer for a structured result
modelstringper blockModel for the default planner, replanner, evaluator and synthesizer (all openai/gpt-6-luna) and executor (intent/synthesize)
maxAttemptsPerTasknumber1Attempts stamped on every seeded task; 1 means no retries
maxConcurrencynumber1Board workers. Raise it to run independent tasks together
maxTotalTasks, maxEnqueuedTasks, maxTotalRetries500 / 100 / 50Task caps. maxTotalRetries binds once maxAttemptsPerTask is above 1
taskContext"goal" | false | block"goal"See taskContext
synthesizeGoalboolean | blockfalseSee synthesizeGoal
instructionsstring or functionnoneAdded to the default planner, executor and synthesizer prompts
contextcontext slotnoneDefault planner, executor, replanner and synthesizer. Not the evaluator
historyhistory confignoneDefault planner, replanner and synthesizer
toolstoolsnoneDefault executor, replanner and synthesizer
searchboolean | GeneratorSearchConfignoneDefault executor only
executionInstructionsstringnoneAppended to the default executor's prompt
synthesizeInstructionsstringnoneAppended to the default synthesizer's prompt
usescapabilitiesnoneDefault executor, replanner and synthesizer. Not the planner or the evaluator
stepExecutorVisibilityItemVisibility{ client: true, history: false }Default executor
synthesizerVisibilityItemVisibility{ client: true, history: true }Default synthesizer
resourcesRecord<string, any>noneDeclared on the default executor

routedSpecialists​

A controller picks which specialist block runs next, over a shared workspace, until it says it is done.

  • Input: not schema-bound. A function initialState receives it.
  • Output with synthesizer: false: { workspace, iterations: number, history: Array<{ iteration, specialist, reasoning, output }> }. history lists completed iterations, oldest first; a failed iteration is left out. With a synthesizer, that shape is its input.
  • Controller decision (controllerOutputSchema): { specialist: string | null, done: boolean, reasoning: string }. specialist names a registered specialist while done is false, and is null when done.
  • maxIterations caps loop-backs, not iterations: the controller runs once, then at most maxIterations more times. With maxIterations: 3 and a controller that never says done, 4 iterations run.
  • A specialist that throws leaves its task errored and the loop continues.
  • A decision of done: false with specialist: null creates no task, does not fail the run, and the loop continues.
  • An unregistered specialist name throws with the list of registered names. The iteration's task is created first and is left errored; the loop continues.
  • An empty specialists throws [routedSpecialists] At least one specialist is required in "<name>".
  • Tasks: one per iteration in which the controller picked a specialist. assignee is the specialist's name, goal is the controller's reasoning (or iteration N when blank), output is the specialist's return value. The record's other fields are on Task collections.
  • Emits a routedSpecialists data item after each iteration, a snapshot of the workspace and loop state. See Items and the stream.
OptionTypeDefaultWhat it does
namestringrequiredInstance name; prefix of internal block names
workspaceDefinedResourcerequiredThe shared writable resource. Build it with createWorkspace(stateSchema)
specialistsRecord<string, BlockDefinition>required, at least oneBlocks the controller can pick, by name. Each should declare resources: { workspace }
instructionsstring or (input, ctx) => stringnoneInstructions for the default controller and synthesizer. Ignored when you supply controller or synthesizer
controllerblockLLM controllerReturns the decision above
maxIterationsnumber10Loop-backs, as above
maxHistorynumberunlimitedThe default controller's prompt shows only the latest N completed iterations; the collection keeps all
initialStateobject or (input) => objectnoneApplied with setState once at the start of each run. Without it the workspace keeps what the session holds
modelstring"openai/gpt-6-luna"Default controller and synthesizer
contextcontext slotnoneDefault controller and synthesizer
usescapabilitiesnoneDefault controller and synthesizer
controllerVisibilityItemVisibility{ client: true, history: false }Default controller
synthesizerVisibilityItemVisibility{ client: true, history: true }Default synthesizer
synthesizerblock or falseLLM synthesizerfalse returns { workspace, iterations, history }
outputSchemaZod schemanoneDefault synthesizer only
collectionIdstringnameId of the iteration task collection

eventActors​

Actors subscribe to topics. Emitting an entry runs every actor whose pattern matches it.

  • emit input: an entry { type: string, topic: string, body: unknown }. It appends the entry to the workspace first (unless it is a duplicate), then starts one task per matching actor. Each actor's block receives the entry as its input. If the matching actors would cross a task cap, none of them is dispatched.
  • eventActors({...}) returns { emit, workspace, actors }; actors is frozen.
  • createEventActorsWorkspace({ name: string, entries: ZodTypeAny }) returns { workspace: DefinedResource }. entries is documentation only.
  • actor({ name, watch, block }) returns a frozen descriptor. A watch with no pattern throws [eventActors] Actor "<name>" must have at least one watch pattern.
  • An empty actors throws [eventActors] "<name>" must have at least one actor.
eventActors optionTypeDefaultWhat it does
namestringrequiredInstance name
workspace{ workspace: DefinedResource }requiredResult of createEventActorsWorkspace
actorsActor[]required, at least oneThe subscribers
concurrencynumber4Actors running at once
reEmitbooleanfalseActor outputs shaped like entries are appended and dispatched again
maxDepthnumber3Re-emission depth cap; matters only with reEmit
maxTotalTasks, maxEnqueuedTasksnumber | null500 / 100Task caps. There is no maxTotalRetries

Topic patterns​

A pattern is matched against the string ${type}:${topic}. * matches within one segment (segments are separated by : or .), ** matches any characters including none, and * also matches the empty string. Every other character matches itself. Avoid ? in a pattern: it makes the character before it optional, so slacks? matches slack and slacks.

PatternMatchesDoes not match
observation:*observation:slackobservation:slack.msg
observation:**observation:slack.msg.editevent:slack
*:slackobservation:slack, event:slack
observation:slack.*observation:slack.messageobservation:slack.a.b
**everything
observation:slacks?observation:slack, observation:slacksobservation:slackx

Re-emission​

With reEmit, an actor's output is read as entries: an array, a bare entry object, or { entries: [...] }. Only objects with a string type, a string topic and a body key count; anything else is dropped. Each counted entry is appended, then dispatched to its matching actors as new tasks one level deeper. One actor's entries are dispatched as a batch: if the actors they match would cross a task cap, none is dispatched, the entries stay appended, and the source task errors. The first dispatch is depth 1, re-emitted tasks are depth 2, 3 and so on. At maxDepth the actor runs and its entries are appended, but nothing is dispatched from them. Task metadata carries { depth, type, topic }.

Duplicates and failures​

  • An entry whose type and topic already appear in the workspace is not appended again and emits no rb-entry item. A duplicate entry, whether passed to emit or re-emitted, dispatches its matching actors but is not appended again.
  • createAppendEntry(name, workspaceResource, resourceKey = "workspace") appends the entry and emits its rb-entry item, unless one with the same type and topic is already there, in which case it does neither. It returns nothing either way: compose it with .tap(), because .step() would hand the next step undefined.
  • A failing actor records an errored task and the rest of the chain continues.

Tasks and items​

  • Tasks: one per matching actor, in a request-scoped collection with id eventActors:<name>. assignee is the actor name and input is the entry. See Task collections.
  • Emits an rb-entry data item per appended entry. See Items and the stream.

roundRobin​

A fixed roster takes turns in declared order for up to maxRounds rounds. An optional referee audits each round. A synthesizer writes the result up.

  • Input: { goal: string }, schema roundRobinInputSchema.
  • Each round runs every roster entry in declaration order, then the referee if set, then the exit check. After the last round, the synthesizer receives RoundRobinFinalShape, or that shape is returned when synthesizer: false.
  • Exit: after each round the loop ends if the round count has reached maxRounds; otherwise terminateWhen(ctx) is called and true ends it. At most maxRounds rounds run, and exactly that many when terminateWhen never fires.
  • terminateWhen(ctx: BlockContext) => boolean: ctx.sequencer.state holds the round counter (round) and the referee critiques (refereeCritiques); ctx.session.state is available. It should be pure and total. A throw surfaces as a loop runtime error.
  • Construction errors: empty roster (roster must contain at least 1 entry); a roster entry with an empty name; duplicate names (duplicate roster name "<n>"); maxRounds not above 0 (maxRounds must be > 0); outputSchema with synthesizer: false (cannot set outputSchema when synthesizer: false).
  • Transcript entry: { round, agentName, text }, round >= 1. One audit task per (round, agent) turn: goal is <agent> (round <n>), assignee is the roster name, output is { text }. See Task collections for the task record.
  • Output RoundRobinFinalShape: { rounds: number (rounds executed), contributions: Array<{ round, agentName, text }>, refereeCritiques: Array<{ round, critique }> }. refereeCritiques is empty with no referee. It is the output when synthesizer: false and the synthesizer's input otherwise.
OptionTypeDefaultWhat it does
namestringrequiredInstance name
rosterRosterEntry[]required, at least 1, unique namesWho speaks, in order
maxRoundsnumber5Round cap; above 0
terminateWhen(ctx) => booleannoneEarly exit, after each round
contributionsDefinedResourceone per callShared transcript resource
refereeblocknonePer-round audit; with none the step is absent
synthesizerblock or falseLLM synthesizerfalse returns the raw shape
outputSchemaZod schemaz.string()Default synthesizer only; refused with synthesizer: false
instructionsstring or functionnoneDefault roster agents and synthesizer
modelstringnoneDefault roster agents and synthesizer. With no value, agents use intent/chat and the synthesizer intent/synthesize
uses, tools, contextnoneDefault roster agents and synthesizer
synthesizerVisibilityItemVisibility{ client: true, history: true }Default synthesizer
collectionIdstringnameAudit task collection id
accessorKeystring"contributions"Accessor key of the contributions resource

RosterEntry:

FieldMeaning
nameUnique, non-empty
role?Injected into the default agent's prompt; ignored when block is set
block?Overrides the default agent

Roster agents​

The default agent is a model call that streams plain text, with no outputSchema; each item it emits carries the roster name as agentName. It sees the goal, the round, earlier contributions and the referee critiques. It uses intent/chat unless model is set, with visibility { client: true, history: false }. For structured output, supply a block.

An override block must return a string or { text: string }. Any other value is coerced with String() and a warning is logged once per agent. Override blocks do not receive instructions, uses, tools or context: those reach the default blocks only.

Referee​

A referee block returns { critique: string }, once per round after the roster. The critique is stored with its round and shown to the default roster agents of later rounds. An override roster block reads refereeCritiques from sequencer state itself. The referee does not control termination or order.

createReferee(opts) builds one; pass its result as referee. It is not applied automatically.

createReferee optionDefault
name, contributionsrequired; contributions is the resource passed to roundRobin
modelintent/synthesize
context, uses, tools, instructionsnone
itemVisibility{ client: true, history: false }
accessorKeycontributions

The default referee never declares a winner and never decides whether more rounds are needed.

Synthesizer and contributions​

The default synthesizer is a model call that combines the transcript and the referee critiques, using intent/synthesize unless model is set. A block replaces it and receives RoundRobinFinalShape.

By default each roundRobin() call makes its own contributions resource. Pass one made with createRoundRobinContributions() to read the transcript from another block after the loop, and register it in the flow's resources so that block can declare it (see Resources). The pattern empties it at the start of every run. When several round-robins share a sequencer chain, give each a distinct accessorKey: one accessor key cannot point at two resources.

debate​

Debaters argue assigned stances. A judge rules once at the end. An optional moderator runs each round.

  • Input: { question: string }, schema debateInputSchema.
  • Without a moderator, every debater speaks each round in declared order, then the judge, then the optional synthesizer. With a moderator, it opens each round and decides who speaks. Only its nextSpeakers run, one at a time. The judge and synthesizer follow.
  • Each turn sees all earlier rounds plus earlier speakers in the current round. Debaters in one round speak one after another. Default debaters see earlier arguments tagged by stance only ([stance] text), never by name.
  • Termination is checked after each round, in this order: round >= maxRounds; the moderator's last decision has done: true; terminateWhen(ctx) returns true. terminateWhen works with or without a moderator, should be pure and total, and an error it throws propagates as a run error.
  • Construction errors: fewer than 2 debaters (debaters must contain at least 2 entries); a debater with an empty name or empty stance; duplicate names; maxRounds not above 0; outputSchema with synthesizer: false; moderator: false (moderator cannot be set to false ... use undefined to opt out).
  • Construction warnings: maxRounds above 4 (unusually high ... diminishing); anonymizeTranscript: false with the default judge and model set.
  • Transcript entry: { round, agentName, stance, text }, one per turn. One audit task per (round, debater) turn: goal is <name> (round <n>), assignee is the debater name, output is { text }, in the collection collectionId. See Task collections.
  • Output DebateRawOutput: { rounds, question, transcript: Array<{ round, agentName, stance, text }>, verdict: { verdict, winner: string | null, reasoning }, moderatorDecisions: Array<{ round, nextSpeakers, briefing, newAngle, done }> }. With synthesizer: false this is the output. moderatorDecisions is [] without a moderator.
  • Debater block override: returns a string or { text: string }; other shapes are coerced with String() and warned about once per agent.
debate optionTypeDefaultWhat it does
namestringrequiredInstance name
debatersDebaterConfig[]required, at least 2The roster
maxRoundsnumber2Round cap; above 0; above 4 logs a warning
judgeblockLLM judgeRules once, after the loop
synthesizerblock or falseLLM synthesizerfalse returns DebateRawOutput
moderatorblocknoneOpens each round. See Moderator
terminateWhen(ctx) => booleannoneEarly exit
transcriptDefinedResourceone per callShared transcript resource
outputSchemaZod schemaz.string()Default synthesizer only; refused with synthesizer: false
instructionsstring or functionnoneDefault blocks only
modelstringper blockintent/chat for default debaters; intent/synthesize for the default judge and synthesizer. Not applied to a moderator
uses, tools, contextnoneDefault debaters, judge and synthesizer
judgeVisibilityItemVisibility{ client: true, history: true }Default judge
synthesizerVisibilityItemVisibility{ client: true, history: true }Default synthesizer
debaterVisibilityItemVisibility{ client: true, history: false }Default debaters
anonymizeTranscriptbooleantrueJudge's view, below
shuffleForJudgebooleantrueJudge's view, below
collectionIdstringnameAudit task collection id

DebaterConfig:

FieldMeaning
nameUnique
stanceRequired, non-empty
role?Persona line in the default debater's prompt; ignored with block
block?Overrides the default debater

Judge​

The default judge reads the question and the transcript and returns a verdict. An override returns { verdict: string, winner: string | null, reasoning: string }; winner: null marks a synthesis verdict. judge: false is a type error. With anonymizeTranscript: true the judge sees [stance] text, with names removed; false renders [name, stance] text. With shuffleForJudge: true the order of arguments within each round is shuffled.

Moderator​

debate() never builds a moderator. Without one, every debater speaks every round. To get a model-backed moderator, call createModerator yourself and pass the result as moderator, sharing one createDebateTranscript() with debate({ transcript }). The pattern-level model, tools, uses, context and instructions do not reach a moderator you pass in.

createModerator optionDefault
name, rosterNames, transcriptrequired
modelintent/synthesize
context, uses, tools, instructionsnone
itemVisibility{ client: true, history: false }

Give it tools or uses for research such as web search. Their results reach debaters only through briefing. Without tools it reasons over the transcript and its earlier decisions.

Decision DebateModeratorOutput: { nextSpeakers: string[], briefing: string | null, newAngle: string | null, done: boolean }.

  • nextSpeakers is the ordered list for this round. A list of one is a single-speaker round, and a name listed twice speaks twice.
  • nextSpeakers: [] with done: false is rejected by the schema (Moderator must return non-empty nextSpeakers when done is false). With done: true it is allowed.
  • done: true lets the current round run, then ends the loop.
  • An unknown name throws at dispatch with the list of available names.
  • The moderator sees speaker names; anonymizeTranscript does not apply to it.
  • Debaters of a round see that round's briefing and newAngle, each nullable on its own. A custom debater reads state.moderatorDecisions.
  • A moderator that throws surfaces as a run error. A hand-written moderator must return debateModeratorOutputSchema output and declare the shared transcript resource, accessor transcript.

Transcript, synthesizer and items​

Pass the same createDebateTranscript() result to debate({ transcript }) and to any custom moderator, judge or synthesizer that declares it. Otherwise debate() makes its own, and a second declaration of the resource is rejected.

The default synthesizer answers the question directly from the verdict and the arguments, without mentioning the debate. It uses intent/synthesize.

Emits debate-turn-pending before each debater, then debate-turn per turn, debate-decision per moderator decision and debate-verdict once. Payloads and keys are on Items and the stream.

responseAuditor​

Runs analyzers over a finished response and surfaces the findings. It is a side-chain sequencer, so the .sideChain() connector must map the pipeline value to its input.

  • Input: { userInput: string, response: string }, schema auditorInputSchema. Each analyzer receives that and returns an AnalyzerResult.
  • Analyzers run in parallel, up to maxConcurrency at once.
  • A failing analyzer is dropped from the results and does not fail the audit.
  • Output: { results: AnalyzerResult[], surfacedResults: AnalyzerResult[], overallScore: number }. overallScore is the average score of the analyzers that did not fail, and 0 with no analyzers or none succeeding. surfacedResults holds every result whose shouldSurface is true or whose score >= threshold.
  • When at least one result surfaces, it emits an audit-annotation data item, one per invocation. When nothing surfaces, no item is emitted. See Items and the stream.
OptionTypeDefaultWhat it does
analyzersblock arrayrequiredThe analyzers. An empty list is accepted and gives overallScore: 0
thresholdnumber0.3A result at or above it surfaces
maxConcurrencynumberall analyzers at onceParallel analyzer limit

AnalyzerResult:

FieldTypeMeaning
analyzerIdstringStable id of the analyzer
categorystringDomain it belongs to
scorenumber, 0 to 1Higher means more to surface
shouldSurfacebooleanForces the result into surfacedResults whatever the score
annotationsarray of AuditAnnotationThe findings
supplementaryrecord, optionalDomain extras a renderer may show

AuditAnnotation: type string, label string, severity ("info", "warning" or "critical"), description string, evidence? string.

captureContext, a building block exported from the @flow-state-dev/patterns/response-auditor subpath, writes userInput and response to state and returns nothing, so use .tap().

biasAnalyzer​

An example analyzer in @thought-fabric/core/metacognition, not in @flow-state-dev/patterns.

  • Input: { userInput: string, aiResponse: string }. The field is aiResponse, not response.
  • It makes three model calls (detect agreement, classify, counterpoint) and two deterministic steps. The counterpoint call is skipped below counterpointThreshold (0.4). Model default intent/utility.
  • Output: { analyzerId: "bias-sycophancy", category: "metacognition", severity, score, label, summary, annotations, counterArguments, sycophancyScore }. severity is info below 0.4, warning below 0.7, else critical. Each annotation is { biasType, confidence, description, evidence }.
  • biasType is one of sycophancy, confirmation_bias, anchoring_bias, authority_deference, recency_bias, false_consensus.
  • It does not satisfy AnalyzerResultSchema as it is. An adapter must rename response to aiResponse on the way in, add shouldSurface on the way out, and map each annotation to { type, label, severity, description, evidence? }.

goalSeekLoop​

Drains a task board, asks a judge whether the work is done, and repeats. Returns a sequencer.

  • Verdict: { decision: "done", reason }, { decision: "continue", reason } or { decision: "replan", reason, tasks?: TaskInit[] }. continue drains again with no new tasks. replan adds tasks, from the inline tasks or, when none, from replanner. reason is required on every decision; a verdict that does not match is malformed.
  • Judge: a block, a sequencer, or a function (input: { collection, drainResult }, ctx) => Verdict | Promise<Verdict>. A block or sequencer judge receives the raw drain result and reads the board from ctx.
  • mapToVerdict(source, { decision, reason?, tasks? }) adapts a decision-only source to a Verdict. decision maps the source to done, continue or replan. A missing reason is filled with converged, continue or replan respectively. tasks is read only for replan. A source mapped this way is never malformed.
  • Termination: the loop records a goal-seek-loop-termination data item with the reason it stopped and the number of drains that ran. See Items and the stream.
OptionTypeDefaultWhat it does
namestringrequiredOuter sequencer name
inputSchemaZod schemaz.unknown()Public input of the loop
activeStatusMessagestringnoneStatus text emitted before the loop runs
boardTaskBoardHandlerequiredThe board to drain. Request- or resource-backed only
stateSchemaZod object schemanoneExtra fields merged into loop state. Must be a z.object, or construction throws
seedblock or sequencernoneWrites the first tasks before the first drain. Optional when initialTasks seeded the board
afterDrainblocknoneRuns after each drain, before the judge
judgeblock, sequencer or functionrequiredReturns a verdict
replannerblocknoneRuns on a replan verdict with no inline tasks. Must emit a non-empty { tasks }
maxAttemptsPerTasknumber1Default attempts for tasks a replan adds
taskContextcontext supplynoneContext for replanned tasks
maxIterationsnumberrequiredTotal drains. A finite positive integer. Separate from the taskBoard's own maxIterations (Task board)
finalizeblock or sequencernoneRuns over the settled board. Omit it to return the board projection as is
onError"skip" | "fail""skip"Judge and replanner errors only
  • When maxIterations runs out without a done verdict, the loop records reason max-iterations, runs finalize over what has settled, and does not throw.
  • onError: "skip" exits with reason judge-error, runs finalize anyway, and covers: the judge throws, the judge returns a malformed verdict, a replan with no tasks and no replanner, and a replanner that emits no tasks. "fail" propagates a request error. A failing seed or drain always propagates.
  • A drain that leaves a task waiting on a user or on an event ends the pass with reason waiting-on-a-user or waiting-on-an-event. What each means is on Task board.
  • Construction throws for: a maxIterations that is not a finite positive integer; a board backed by a sequencer or a factory; a board declared mode: "delegation"; and maxIterations > 1 over a board whose initialTasks include an entry without an id, which would be added again every drain. A single-drain loop is unaffected.
  • There are no cost or time budgets and no stall detection. The loop stops on a done verdict or at maxIterations.

Where each pattern keeps its data​

A part is a session resource, a task collection, or the pattern's sequencer state, which a new run starts fresh. In the Lifetime column, "the run" is one execution of the pattern's sequencer, and "the request" is the client request that started it; a request-backed collection lasts for that request. What each kind means for owner, client access and count is on Resources and Task collections. The parts specific to a pattern:

PartPatternStored asLifetime
Iteration tasksroutedSpecialistsTask collection, id collectionIdThe run
WorkspaceroutedSpecialistsSession resource from createWorkspaceReplaced by initialState each run when set, otherwise carried over
Entry logeventActorsSession resource, accessor eventedActors (spelled differently from the pattern name), state { entries: any[] }, client.expose: ["entries"]Append-only, never cleared by the pattern, unique on type + topic
Actor taskseventActorsRequest-scoped task collection, id eventActors:<name>The request
ContributionsroundRobinSession resource, accessor contributions (set with accessorKey)Emptied at the start of every run
Audit tasksroundRobin, debateTask collection, id collectionIdThe run
TranscriptdebateSession resource, accessor transcript (fixed)Emptied at the start of every run
Board tasksparallelTasks, supervisor, planAndExecuteRequest-backed task collection, id nameThe request
Referee critiques, moderator decisions, reviewer audit data, loop bookkeeping, analyzer stateroundRobin, debate, supervisor, goalSeekLoop, responseAuditorSequencer stateThe run

A roundRobin() or debate() call makes its own resource unless you pass one.