@OnAnswer
The @OnAnswer(AgentClass) method decorator ("@agboss/core") marks the per-agent evaluation method inside a DecidedBy.Code @Arbiter class. During a .joinQuorum() or .joinQuorumGroups() step, AGBoss invokes the matching @OnAnswer(AgentClass) method as each parallel branch finishes so your arbiter can return true (count toward quorum) or false (reject the branch answer) in real time.
Complete @OnAnswer example
Section titled “Complete @OnAnswer example”import { Agent, Arbiter, DecidedBy, ExecutionContext, Injectable, OnAnswer,} from "@agboss/core";import { Integer, Text } from "@agboss/core/dto";
export class PricingQuoteDto { @Text({ prompt: "Pricing tier name" }) tierName!: string;
@Integer({ min: 0, max: 100, prompt: "Gross margin percentage (0-100)" }) marginPercent!: number;}
@Agent({ name: "enterprise-pricing-agent", description: "Generates enterprise tier quote", model: "moonshotai/kimi-k2.6", prompt: "Propose an enterprise pricing quote.", output: PricingQuoteDto,})export class EnterprisePricingAgent {}
@Agent({ name: "self-serve-pricing-agent", description: "Generates self-serve tier quote", model: "moonshotai/kimi-k2.6", prompt: "Propose a self-serve pricing quote.", output: PricingQuoteDto,})export class SelfServePricingAgent {}
@Injectable()export class MarginPolicyService { minMarginForTenant(_tenantId: string): number { return 30; }}
@Arbiter({ name: "margin-threshold-arbiter", decidedBy: DecidedBy.Code, deps: [ExecutionContext, MarginPolicyService],})export class MarginThresholdArbiter { constructor( private readonly ctx: ExecutionContext, private readonly policy: MarginPolicyService, ) {}
@OnAnswer(EnterprisePricingAgent) fromEnterprisePricing(answer: PricingQuoteDto): boolean { const minMargin = this.policy.minMarginForTenant(this.ctx.tenant.tenantId); return answer.marginPercent >= minMargin; }
@OnAnswer(SelfServePricingAgent) fromSelfServePricing(answer: PricingQuoteDto): boolean { return answer.marginPercent >= 20; }}import { expect, it } from "vitest";import { testArbiter } from "@agboss/core/testing";import { EnterprisePricingAgent, MarginThresholdArbiter,} from "../src/margin-threshold.js";
it("accepts quotes meeting the margin threshold via @OnAnswer", async () => { const runArbiter = testArbiter(MarginThresholdArbiter); const { output } = await runArbiter(EnterprisePricingAgent, { tierName: "Enterprise", marginPercent: 42, }); expect(output).toBe(true);});How @OnAnswer(AgentClass) works inside @Arbiter
Section titled “How @OnAnswer(AgentClass) works inside @Arbiter”| Signature Part | Type | Description |
|---|---|---|
@OnAnswer(AgentClass) |
Method decorator | Binds the method on a DecidedBy.Code @Arbiter to a specific @Agent class launched by .toParallelAgents(...). Every agent in the launch must have a corresponding @OnAnswer method ([arbiter.unhandled-agent]). |
answer parameter |
ArbiterAnswerOf<typeof AgentClass> |
The plain validated output DTO produced by that @Agent branch. TypeScript rejects mismatched DTO types at compile time. |
| Return value | boolean | Promise<boolean> |
Returns true if the branch’s answer counts toward the quorum, or false to reject it. |