Skip to content

@Arbiter & @OnAnswer

The @Arbiter class decorator and @OnAnswer(AgentClass) method decorator (arbiters/*.arbiter.ts) evaluate individual answers arriving from a parallel agent launch (.toParallelAgents(...)) to decide whether each answer counts toward a .joinQuorum() or .joinQuorumGroups() consensus. Unlike a @Router, an @Arbiter never chooses where the graph goes next — it votes true (accept) or false (reject) as each parallel branch finishes so the quorum can resolve immediately and cancel slower branches.

Complete @Arbiter and @OnAnswer examples (DecidedBy.Code and DecidedBy.Model)

Section titled “Complete @Arbiter and @OnAnswer examples (DecidedBy.Code and DecidedBy.Model)”

What options do @Arbiter and @OnAnswer accept?

Section titled “What options do @Arbiter and @OnAnswer accept?”

Every @Arbiter class name ends with Arbiter and its name option ends with -arbiter:

Option / Decorator Applies To Type Required Description
name Both string Yes Unique kebab-case identifier ending with -arbiter (e.g., "valid-score-arbiter").
decidedBy Both DecidedBy.Code | DecidedBy.Model Yes Whether TypeScript @OnAnswer methods (Code) or a decision/chat model (Model) judges each arriving answer.
deps DecidedBy.Code readonly Token[] No Constructor dependencies (ExecutionContext, @Injectable services) for a code arbiter.
@OnAnswer(AgentClass) DecidedBy.Code MethodDecorator Yes Decorates one method per launched @Agent ((answer: OutputDto) => boolean | Promise<boolean>); missing an agent fails compilation with [arbiter.unhandled-agent].
model DecidedBy.Model string Yes Decision model ("typesafe/jev-1.13") or chat model used to judge each arriving answer.
prompt DecidedBy.Model string Yes General instructions explaining how the model arbiter evaluates answers.
criteria DecidedBy.Model readonly [ArbiterCriterion, ...] Yes Array of { agent: AgentClass, prompt: string } entries covering every agent in the parallel launch.
Related Entity Import Path Purpose
.acceptedBy(Arbiter) & .acceptedBy(anyOf(A, B)) "@agboss/core" Chains arbiter gates after .toParallelAgents(...); multiple .acceptedBy() calls form a logical AND, while anyOf(A, B) forms a logical OR.
.joinQuorum({ min, max?, deadline? }) Flow chain Collects accepted answers as soon as max (default min) answers pass all arbiters, cancelling remaining branches (BranchVerdict.Surplus).
.joinQuorumGroups(group(A, B).priority(1)..., { deadline? }) "@agboss/core" Enforces prioritized group quorum rules where each group(...) declares its own .returns(...) and continuation path.
QuorumNotReachedError "@agboss/core" Thrown when fewer than min answers are accepted or the deadline expires; catchable via .onJoinError(QuorumNotReachedError, sidePath).
testArbiter(ArbiterClass, options?) "@agboss/core/testing" Isolated unit runner that tests an arbiter’s verdict for any agent and answer payload.