Skip to main content

@flow-state-dev/patterns/debate

Interfaces​

DebateConfig​

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Properties​

anonymizeTranscript?​
anonymizeTranscript?: boolean;

Strip debater names from the judge's view of the transcript. Stances are retained. Default true. Mitigates identity-driven self-bias when the judge model is the same as a debater model.

collectionId?​
collectionId?: string;

Stable id for the audit TaskCollection. Defaults to name.

context?​
context?: GeneratorSlot<any, any>;
debaters​
debaters: DebaterConfig[];

At least 2 entries required; each name must be unique.

debaterVisibility?​
debaterVisibility?: ItemVisibility;
instructions?​
instructions?: InstructionsSlot<{
question: string;
}>;

Pattern-level instructions injected into default blocks only.

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

Judge override. Receives { question } (and reads the transcript resource) and must produce { verdict: string, winner: string | null, reasoning: string }. Pass false is NOT permitted — the verdict is Debate's identity.

judgeVisibility?​
judgeVisibility?: ItemVisibility;
maxRounds?​
maxRounds?: number;

Default 2. >4 emits a one-time warning about diminishing returns.

model?​
model?: string;

Default model for internal generators.

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

Optional moderator block. When provided, opens each round: it picks which debaters speak that round, may supply a briefing and newAngle that those debaters see, and may set done: true to make this the last round (the round still runs; the loop exits after). Sees the full transcript of all PRIOR rounds — the current round's speakers haven't run yet when the moderator decides. When omitted, the debate runs in fixed declared-roster order — every debater every round.

Pass false is NOT permitted; use undefined to opt out.

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

Shuffle argument order within each round when rendered for the judge. Default true. Mitigates LLM-judge position bias.

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

Optional final synthesizer. Pass false to return the raw 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. Useful for session-state-driven early exits independent of the moderator.

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

Parameters​
ctx​

BlockContext

Returns​

boolean

tools?​
tools?: ToolsSlot;
transcript?​
transcript?: DefinedResource;

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

Pass an external instance when a custom moderator, judge, or synthesizer block declares the same transcript resource on its own resources: slot — they must share the resource reference, otherwise the framework's resource-merge rejects two defineResource() instances declared against the same key.

uses?​
uses?: UsesSlot;

DebateRawOutput​

Final shape produced by the loop and judge, before optional synthesizer.

Properties​

moderatorDecisions​
moderatorDecisions: object[];

Always present; empty array when no moderator was configured.

briefing​
briefing: string | null;
done​
done: boolean;
newAngle​
newAngle: string | null;
nextSpeakers​
nextSpeakers: string[];
round​
round: number;
question​
question: string;
rounds​
rounds: number;
transcript​
transcript: object[];
agentName​
agentName: string;
round​
round: number;
stance​
stance: string;
text​
text: string;
verdict​
verdict: object;
reasoning​
reasoning: string;
verdict​
verdict: string;
winner​
winner: string | null;

DebaterConfig​

A single debater worker.

Properties​

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

Optional override block. Replaces the default LLM debater. 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 attribution and as the audit task's assignee. Must be unique within the debaters array.

role?​
role?: string;

Optional persona description injected into the default debater's prompt (e.g. "skeptical engineer"). Ignored if block is provided.

stance​
stance: string;

Assigned position the debater argues. Required — Debate does not derive stances from the question.

Type Aliases​

DebateContributionEntry​

type DebateContributionEntry = z.infer<typeof debateContributionEntrySchema>;

DebateModeratorDecision​

type DebateModeratorDecision = z.infer<typeof debateModeratorDecisionSchema>;

DebateModeratorOutput​

type DebateModeratorOutput = z.infer<typeof debateModeratorOutputSchema>;

DebateState​

type DebateState = z.infer<typeof debateStateSchema>;

DebateTranscriptState​

type DebateTranscriptState = z.infer<typeof debateTranscriptStateSchema>;

DebateVerdict​

type DebateVerdict = z.infer<typeof debateVerdictSchema>;

Variables​

debateContributionEntrySchema​

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

A single debate turn — one debater's argument in one round.


debateModeratorDecisionSchema​

const debateModeratorDecisionSchema: z.ZodObject<{
briefing: z.ZodNullable<z.ZodString>;
done: z.ZodBoolean;
newAngle: z.ZodNullable<z.ZodString>;
nextSpeakers: z.ZodArray<z.ZodString, "many">;
round: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
round: number;
}, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
round: number;
}>;

A stashed moderator decision tagged with the round it opened.


debateModeratorOutputSchema​

const debateModeratorOutputSchema: z.ZodEffects<z.ZodObject<{
briefing: z.ZodNullable<z.ZodString>;
done: z.ZodBoolean;
newAngle: z.ZodNullable<z.ZodString>;
nextSpeakers: z.ZodArray<z.ZodString, "many">;
}, "strip", z.ZodTypeAny, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}>, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}>;

Output the moderator emits at the top of each round.

  • nextSpeakers must be non-empty when done is false (enforced via .refine()); the framework would otherwise loop indefinitely on an empty round.
  • briefing is optional context the moderator gathered for the round — typically a synthesis of tool-fetched information that should be visible to every debater in this round so they argue from the same information base. Rendered into the default debater's prompt.
  • newAngle is an optional reframing or focus question for the round — rendered into the default debater's prompt alongside the briefing.
  • done: true lets the current round still run (debaters speak), then exits the loop before the next round. Useful for "give one closing round and stop" semantics.

debateStateSchema​

const debateStateSchema: z.ZodObject<{
moderatorDecisions: z.ZodDefault<z.ZodArray<z.ZodObject<{
briefing: z.ZodNullable<z.ZodString>;
done: z.ZodBoolean;
newAngle: z.ZodNullable<z.ZodString>;
nextSpeakers: z.ZodArray<z.ZodString, "many">;
round: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
round: number;
}, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
round: number;
}>, "many">>;
question: z.ZodDefault<z.ZodString>;
round: z.ZodDefault<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
moderatorDecisions: object[];
question: string;
round: number;
}, {
moderatorDecisions?: object[];
question?: string;
round?: number;
}>;

Outer sequencer state.


debateTranscriptStateSchema​

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

Session-resource state: the append-only debate transcript.


debateVerdictSchema​

const debateVerdictSchema: z.ZodObject<{
reasoning: z.ZodString;
verdict: z.ZodString;
winner: z.ZodNullable<z.ZodString>;
}, "strip", z.ZodTypeAny, {
reasoning: string;
verdict: string;
winner: string | null;
}, {
reasoning: string;
verdict: string;
winner: string | null;
}>;

Verdict the judge produces once after the loop ends.

Functions​

createDebater()​

function createDebater(opts): BlockDefinition<ZodTypeAny, ZodString, any, string>;

Build a default debater generator. Reads prior arguments from the transcript resource and emits { text }. The default prompt is non-conceding (per the sycophancy literature).

Parameters​

opts​

CreateDebaterOptions

Returns​

BlockDefinition<ZodTypeAny, ZodString, any, string>


createDebateTranscript()​

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

Creates a session-scoped writable resource holding the debate transcript. The pattern installs this internally; consumers may call the factory directly when they need the canonical resource shape for external read-access.

Returns​

object & ResourceConfig<JsonObject> & object


createInitTranscript()​

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

Parameters​

opts​
collectionId​

string

name​

string

transcript​

DefinedResource

Returns​

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


createJudge()​

function createJudge(opts): BlockDefinition<ZodTypeAny, ZodObject<{
reasoning: ZodString;
verdict: ZodString;
winner: ZodNullable<ZodString>;
}, "strip", ZodTypeAny, {
reasoning: string;
verdict: string;
winner: string | null;
}, {
reasoning: string;
verdict: string;
winner: string | null;
}>, any, {
reasoning: string;
verdict: string;
winner: string | null;
}>;

Build the default judge generator.

Parameters​

opts​

CreateJudgeOptions

Returns​

BlockDefinition<ZodTypeAny, ZodObject<{ reasoning: ZodString; verdict: ZodString; winner: ZodNullable<ZodString>; }, "strip", ZodTypeAny, { reasoning: string; verdict: string; winner: string | null; }, { reasoning: string; verdict: string; winner: string | null; }>, any, { reasoning: string; verdict: string; winner: string | null; }>


createModerator()​

function createModerator(opts): BlockDefinition<ZodTypeAny, ZodEffects<ZodObject<{
briefing: ZodNullable<ZodString>;
done: ZodBoolean;
newAngle: ZodNullable<ZodString>;
nextSpeakers: ZodArray<ZodString, "many">;
}, "strip", ZodTypeAny, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}>, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}>, any, {
briefing: string | null;
done: boolean;
newAngle: string | null;
nextSpeakers: string[];
}>;

Build the default moderator generator. Returns { nextSpeakers, newAngle, done } per round.

Parameters​

opts​

CreateModeratorOptions

Returns​

BlockDefinition<ZodTypeAny, ZodEffects<ZodObject<{ briefing: ZodNullable<ZodString>; done: ZodBoolean; newAngle: ZodNullable<ZodString>; nextSpeakers: ZodArray<ZodString, "many">; }, "strip", ZodTypeAny, { briefing: string | null; done: boolean; newAngle: string | null; nextSpeakers: string[]; }, { briefing: string | null; done: boolean; newAngle: string | null; nextSpeakers: string[]; }>, { briefing: string | null; done: boolean; newAngle: string | null; nextSpeakers: string[]; }, { briefing: string | null; done: boolean; newAngle: string | null; nextSpeakers: string[]; }>, any, { briefing: string | null; done: boolean; newAngle: string | null; nextSpeakers: string[]; }>


createRecordArgument()​

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

Parameters​

opts​
agentName​

string

collectionId​

string

name​

string

stance​

string

transcript​

DefinedResource

warnedAgents​

Set<string>

Returns​

BlockDefinition<ZodAny, ZodTypeAny, any, void>


createSynthesize()​

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

Build the default debate synthesizer.

Parameters​

opts​

CreateSynthesizeOptions

Returns​

BlockDefinition<ZodTypeAny, ZodTypeAny, unknown, any>


debate()​

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

Build a Debate coordination pattern. Returns a sequencer block that takes { question: string } and returns the synthesizer's output (or DebateRawOutput if synthesizer: false).

Type Parameters​

TOutputSchema​

TOutputSchema extends ZodTypeAny = ZodTypeAny

Parameters​

config​

DebateConfig<TOutputSchema>

Returns​

SequencerDefinition<any, any>


formatTranscriptForJudge()​

function formatTranscriptForJudge(entries, opts): string;

Format the transcript for the judge. Groups entries by round, applies optional per-round shuffling and optional name anonymization.

Exported for tests; consumers building a custom judge can also reuse it to render a transcript identical to the default judge's view.

Parameters​

entries​

object[]

opts​
anonymize​

boolean

random?​

() => number

shuffle​

boolean

Returns​

string

References​

DebateInput​

Re-exports DebateInput


debateInputSchema​

Re-exports debateInputSchema