Skip to main content

@flow-state-dev/patterns/round-robin

Interfaces​

RosterEntry​

A single worker in the round-robin roster.

Properties​

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

Optional override block. Replaces the default LLM agent. Must produce a string or { text: string }; other shapes are coerced via String() and a one-time warning is emitted.

name​
name: string;

Stable name used for context attribution and as the audit task's assignee. Must be unique within a roster.

role?​
role?: string;

Role description injected into the default roster agent's prompt (e.g. "aggressive risk reviewer"). Ignored if block is provided.


RoundRobinConfig​

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Properties​

accessorKey?​
accessorKey?: string;

Accessor key the pattern's internal blocks use to declare the contributions resource. Defaults to "contributions".

Override when two or more roundRobin() instances appear in the same sequencer chain: the framework's resource-merge rejects the same accessor key pointing at different defineResource() references, so each instance must pick a distinct key (e.g. "p2Contributions", "p4Contributions").

collectionId?​
collectionId?: string;

Stable id for the audit TaskCollection. Defaults to name.

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

Generator context slot forwarded to defaults.

contributions?​
contributions?: DefinedResource;

Optional shared contributions resource. When omitted, the pattern creates its own internal instance via createRoundRobinContributions().

Pass an external instance when consumer blocks outside the pattern need to read the running transcript via ctx.resources instead of threading it through RoundRobinFinalShape.contributions. Register the shared resource on the flow's resources map so external consumers can declare it on their own resources: slot.

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

Pattern-level instructions injected into default blocks only.

maxRounds?​
maxRounds?: number;

Default 5. Hard cap on round cycling.

model?​
model?: string;

Default model for internal generators. Default "intent/chat".

name​
name: string;
outputSchema?​
outputSchema?: TOutputSchema;

Output schema applied to the synthesizer's output.

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

Optional per-round argument-quality auditor. When provided, runs after every roster round; its { critique } output is appended to outer state as a RoundRobinRefereeCritique and rendered into subsequent rounds' default roster-agent prompts. Does NOT control termination.

roster​
roster: RosterEntry[];
synthesizer?​
synthesizer?: false | BlockDefinition<any, any, any, any>;

Terminal synthesis step. Pass false to return the raw final shape.

synthesizerVisibility?​
synthesizerVisibility?: ItemVisibility;
terminateWhen?​
terminateWhen?: (ctx) => boolean;

Optional runtime predicate evaluated after each round completes. Return true to exit the loop before maxRounds is reached. Reads from ctx.sequencer.state (round counter, referee critiques) and ctx.session.state (consumer-driven termination conditions).

Should be a pure, total function. A throwing predicate surfaces as a loop runtime error.

Parameters​
ctx​

BlockContext

Returns​

boolean

tools?​
tools?: ToolsSlot;

Tools forwarded to default roster agents, referee, synthesizer.

uses?​
uses?: UsesSlot;

Capabilities forwarded to default roster agents, referee, synthesizer.


RoundRobinFinalShape​

Final shape produced by the loop, before optional synthesizer.

Properties​

contributions​
contributions: object[];
agentName​
agentName: string;
round​
round: number;
text​
text: string;
refereeCritiques​
refereeCritiques: object[];
critique​
critique: string;
round​
round: number;
rounds​
rounds: number;

Type Aliases​

RoundRobinContributionEntry​

type RoundRobinContributionEntry = z.infer<typeof roundRobinContributionEntrySchema>;

RoundRobinContributionsState​

type RoundRobinContributionsState = z.infer<typeof roundRobinContributionsStateSchema>;

RoundRobinRefereeCritique​

type RoundRobinRefereeCritique = z.infer<typeof roundRobinRefereeCritiqueSchema>;

RoundRobinRefereeOutput​

type RoundRobinRefereeOutput = z.infer<typeof roundRobinRefereeOutputSchema>;

RoundRobinState​

type RoundRobinState = z.infer<typeof roundRobinStateSchema>;

Variables​

roundRobinContributionEntrySchema​

const roundRobinContributionEntrySchema: z.ZodObject<{
agentName: z.ZodString;
round: z.ZodNumber;
text: z.ZodString;
}, "strip", z.ZodTypeAny, {
agentName: string;
round: number;
text: string;
}, {
agentName: string;
round: number;
text: string;
}>;

A single roster turn — one agent's contribution in one round.


roundRobinContributionsStateSchema​

const roundRobinContributionsStateSchema: z.ZodObject<{
entries: z.ZodDefault<z.ZodArray<z.ZodObject<{
agentName: z.ZodString;
round: z.ZodNumber;
text: z.ZodString;
}, "strip", z.ZodTypeAny, {
agentName: string;
round: number;
text: string;
}, {
agentName: string;
round: number;
text: string;
}>, "many">>;
}, "strip", z.ZodTypeAny, {
entries: object[];
}, {
entries?: object[];
}>;

Session-resource state: the append-only transcript of entries.


roundRobinRefereeCritiqueSchema​

const roundRobinRefereeCritiqueSchema: z.ZodObject<{
critique: z.ZodString;
round: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
critique: string;
round: number;
}, {
critique: string;
round: number;
}>;

A referee critique stashed in outer state, tagged with the round it ran in.


roundRobinRefereeOutputSchema​

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

Output the optional per-round referee returns.


roundRobinStateSchema​

const roundRobinStateSchema: z.ZodObject<{
goal: z.ZodDefault<z.ZodString>;
refereeCritiques: z.ZodDefault<z.ZodArray<z.ZodObject<{
critique: z.ZodString;
round: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
critique: string;
round: number;
}, {
critique: string;
round: number;
}>, "many">>;
round: z.ZodDefault<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
goal: string;
refereeCritiques: object[];
round: number;
}, {
goal?: string;
refereeCritiques?: object[];
round?: number;
}>;

Outer sequencer state.

Functions​

createInitContributions()​

function createInitContributions(opts): BlockDefinition<ZodObject<{
goal: ZodString;
}, "strip", ZodTypeAny, {
goal: string;
}, {
goal: string;
}>, ZodTypeAny, {
goal: string;
}, void>;

Build the init tap. contributions is the session resource holding entries; collectionId is the stable id used by every record-tap in the round executor so all turns land in the same collection.

Parameters​

opts​
accessorKey?​

string

Accessor key used in the block's resources: map. Defaults to "contributions". Set to a unique key when multiple roundRobin() instances coexist in the same sequencer chain to avoid the build-time accessor-key conflict.

collectionId​

string

contributions​

DefinedResource

name​

string

Returns​

BlockDefinition<ZodObject<{ goal: ZodString; }, "strip", ZodTypeAny, { goal: string; }, { goal: string; }>, ZodTypeAny, { goal: string; }, void>


createRecordContribution()​

function createRecordContribution(opts): BlockDefinition<ZodAny, ZodTypeAny, any, void>;

Parameters​

opts​
accessorKey?​

string

Accessor key used in the block's resources: map. Defaults to "contributions". See createInitContributions for rationale.

agentName​

string

collectionId​

string

contributions​

DefinedResource

name​

string

warnedAgents​

Set<string>

Returns​

BlockDefinition<ZodAny, ZodTypeAny, any, void>


createReferee()​

function createReferee(opts): BlockDefinition<ZodTypeAny, ZodObject<{
critique: ZodString;
}, "strip", ZodTypeAny, {
critique: string;
}, {
critique: string;
}>, any, {
critique: string;
}>;

Build the default referee generator.

Parameters​

opts​

CreateRefereeOptions

Returns​

BlockDefinition<ZodTypeAny, ZodObject<{ critique: ZodString; }, "strip", ZodTypeAny, { critique: string; }, { critique: string; }>, any, { critique: string; }>


createRosterAgent()​

function createRosterAgent(opts): BlockDefinition<ZodTypeAny, ZodTypeAny, any, any>;

Build a default roster-agent generator. Renders prior contributions from the resource into the prompt; emits { text }.

Parameters​

opts​

CreateRosterAgentOptions

Returns​

BlockDefinition<ZodTypeAny, ZodTypeAny, any, any>


createRoundRobinContributions()​

function createRoundRobinContributions(): object & ResourceConfig<JsonObject> & object;

Creates a session-scoped writable resource holding the round-robin transcript. The pattern installs this internally; consumers only call the factory directly when they need the canonical resource shape for external read-access (kept available for future expansion).

Returns​

object & ResourceConfig<JsonObject> & object


createSynthesize()​

function createSynthesize(opts): BlockDefinition<ZodTypeAny, ZodTypeAny, unknown, any>;

Build the default round-robin synthesizer.

Parameters​

opts​

CreateSynthesizeOptions

Returns​

BlockDefinition<ZodTypeAny, ZodTypeAny, unknown, any>


roundRobin()​

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

Build a Round Robin coordination pattern. Returns a sequencer block that takes { goal: string } and returns the synthesizer's output (or RoundRobinFinalShape if synthesizer: false).

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Parameters​

config​

RoundRobinConfig<TOutputSchema>

Returns​

SequencerDefinition<any, any>

References​

RoundRobinInput​

Re-exports RoundRobinInput


roundRobinInputSchema​

Re-exports roundRobinInputSchema