Skip to content

Interface: SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate> ​

Defined in: builders/speculate-capability-builder.ts:26

Fluent sub-builder for a parallel speculative tournament capability ($cap.speculate(toolName, $s => ...)).

Configures $B \ge 2$ isolated tournament branches, optional cross-branch verification, sole-survivor verification, arbiter judgment, and conditional post-arbitration refinement.

Extends ​

Type Parameters ​

Type ParameterDefault typeDescription
TParentInunknownParent actor input payload type.
TRequnknownValidated speculation tool request payload type.
TChildInunknownBranch worker input payload type.
TChildOutunknownBranch worker output payload type.
THandleunknownRuntime handle type of the active BranchableScope.
TCrossReportunknownCross-verifier report payload type.
TVerdictunknownArbiter agent structured verdict payload type.
TCandidateunknownCandidate union element type inferred from the arbiter's input schema.

Methods ​

arbiter() ​

Call Signature ​

ts
arbiter<TArbiterIn, TNewVerdict>(arbiterActor, options?): SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TNewVerdict, ExtractSpeculationCandidate<TArbiterIn>>;

Defined in: builders/speculate-capability-builder.ts:182

Binds the read-only arbiter agent (with an optional decision projector) when the arbiter output already extends SpeculateArbiterDecision.

Infers TCandidate from TArbiterIn so .refineWinnerWhen(...) receives typed candidates, and defaults resolveDecision to the identity projection (verdict) => verdict when omitted.

Type Parameters ​
Type ParameterDefault typeDescription
TArbiterInunknownArbiter input payload type (used to infer TCandidate).
TNewVerdict extends SpeculateArbiterDecisionSpeculateArbiterDecisionArbiter structured verdict output type extending SpeculateArbiterDecision.
Parameters ​
ParameterTypeDescription
arbiterActorMaybeBuilder<AgentNode<TArbiterIn, TNewVerdict, THandle>>Read-only arbiter agent.
options?{ resolveDecision?: (verdict) => SpeculateArbiterDecision; }Optional pure decision projector.
options.resolveDecision?(verdict) => SpeculateArbiterDecision-
Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TNewVerdict, ExtractSpeculationCandidate<TArbiterIn>>

New immutable speculate builder.

Call Signature ​

ts
arbiter<TNewVerdict, TArbiterIn>(arbiterActor, options): SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TNewVerdict, ExtractSpeculationCandidate<TArbiterIn>>;

Defined in: builders/speculate-capability-builder.ts:212

Binds the read-only arbiter agent and decision projector for judging candidate branches.

Infers TCandidate from TArbiterIn so .refineWinnerWhen(...) receives typed candidates.

Type Parameters ​
Type ParameterDefault typeDescription
TNewVerdict-Arbiter structured verdict output type.
TArbiterInunknownArbiter input payload type (used to infer TCandidate).
Parameters ​
ParameterTypeDescription
arbiterActorMaybeBuilder<AgentNode<TArbiterIn, TNewVerdict, THandle>>Read-only arbiter agent.
options{ resolveDecision: (verdict) => SpeculateArbiterDecision; }Pure decision projector.
options.resolveDecision(verdict) => SpeculateArbiterDecision-
Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TNewVerdict, ExtractSpeculationCandidate<TArbiterIn>>

New immutable speculate builder.


branches() ​

ts
branches(branchCount, mapBranches): SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>;

Defined in: builders/speculate-capability-builder.ts:100

Configures the number of parallel speculative branches ($B \ge 2$) and the branch input mapper.

Throws immediately at builder call time if branchCount < 2 or is not an integer.

Parameters ​

ParameterTypeDescription
branchCountnumberNumber of parallel branches ($B \ge 2$).
mapBranches(parentInput, req) => readonly TChildIn[]Synchronous mapper producing $B$ branch inputs.

Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>

New immutable speculate builder.


crossVerifyWith() ​

ts
crossVerifyWith<TNewCrossReport>(crossVerifier): SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TNewCrossReport, TVerdict, TCandidate>;

Defined in: builders/speculate-capability-builder.ts:125

Binds an optional cross-verifier AST node executed across surviving candidate branches before arbitration.

Narrows TCrossReport to the report type produced by crossVerifier.

Type Parameters ​

Type ParameterDescription
TNewCrossReportCross-verifier report payload type.

Parameters ​

ParameterTypeDescription
crossVerifierMaybeBuilder<CrossVerifierASTNode<THandle, Record<string, unknown>, TNewCrossReport>>Cross-verifier node or builder.

Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TNewCrossReport, TVerdict, TCandidate>

New immutable speculate builder.


refineWinnerWhen() ​

ts
refineWinnerWhen(
   predicate, 
   refinementExecutable, 
   mapInput
): SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>;

Defined in: builders/speculate-capability-builder.ts:228

Configures an optional post-arbitration refinement pass executed on the winning branch while losing branches remain readable.

Runs refinementExecutable on the winning branch's isolated scope before merging into the parent scope.

Parameters ​

ParameterTypeDescription
predicate(verdict) => booleanPredicate testing whether refinement should run.
refinementExecutableMaybeBuilder< | AgentNode<TChildIn, TChildOut, THandle> | LoopNode<TChildIn, TChildOut, THandle, string>>Refinement agent or loop.
mapInput(parentInput, verdict, candidates) => TChildInRefinement input mapper.

Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>

New immutable speculate builder.


requestSchema() ​

ts
requestSchema<TNewReq>(schema): SpeculateCapabilityBuilder<TParentIn, TNewReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>;

Defined in: builders/speculate-capability-builder.ts:49

Binds the Zod validation schema for the parent agent's speculation tool call arguments.

Resets any previously bound mapBranches callback when the request schema changes.

Type Parameters ​

Type ParameterDescription
TNewReqValidated speculation request payload type.

Parameters ​

ParameterTypeDescription
schemaZodType<TNewReq>Zod schema for the speculation request.

Returns ​

SpeculateCapabilityBuilder<TParentIn, TNewReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>

New immutable speculate builder.


toAST() ​

ts
toAST(): SpeculateCapabilityNode;

Defined in: ast/ast-builder.ts:20

Compiles the current builder configuration into a deeply frozen passive AST node.

Validates required builder invariants at compilation time and returns an immutable plain-object AST representation containing zero execution methods.

Returns ​

SpeculateCapabilityNode

Deeply frozen passive AST node.

Inherited from ​

AstBuilder.toAST


verifyWinnerWith() ​

ts
verifyWinnerWith<TEvalIn, TEvalOut, TReceipt>(evaluator, options): SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>;

Defined in: builders/speculate-capability-builder.ts:143

Configures an optional sole-survivor evaluator invoked when 1 branch completes uncontested.

Short-circuits the arbiter when the sole completed branch is accepted by options.acceptWhen.

Type Parameters ​

Type ParameterDefault typeDescription
TEvalIn-Evaluator input payload type.
TEvalOut-Evaluator output payload type.
TReceiptTCandidate extends object ? R : unknownInspected scope receipt type.

Parameters ​

ParameterTypeDescription
evaluatorMaybeBuilder<AgentNode<TEvalIn, TEvalOut, THandle>>Read-only evaluator agent.
options{ acceptWhen: (evalOut) => boolean; mapInput: (branchInput, branchOutput, scopeReceipt) => TEvalIn; }Input mapper and acceptance predicate.
options.acceptWhen(evalOut) => boolean-
options.mapInput(branchInput, branchOutput, scopeReceipt) => TEvalIn-

Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TChildIn, TChildOut, THandle, TCrossReport, TVerdict, TCandidate>

New immutable speculate builder.


worker() ​

ts
worker<TNewChildIn, TNewChildOut>(workerExecutable): SpeculateCapabilityBuilder<TParentIn, TReq, TNewChildIn, TNewChildOut, THandle, TCrossReport, TVerdict, TCandidate>;

Defined in: builders/speculate-capability-builder.ts:74

Binds the worker agent or loop executed in parallel across all tournament branches.

Resets dependent branch mapper, sole-survivor verifier, and winner refinement configs when changed.

Type Parameters ​

Type ParameterDescription
TNewChildInBranch worker input payload type.
TNewChildOutBranch worker output payload type.

Parameters ​

ParameterTypeDescription
workerExecutableMaybeBuilder< | AgentNode<TNewChildIn, TNewChildOut, THandle> | LoopNode<TNewChildIn, TNewChildOut, THandle, string>>Worker agent or loop.

Returns ​

SpeculateCapabilityBuilder<TParentIn, TReq, TNewChildIn, TNewChildOut, THandle, TCrossReport, TVerdict, TCandidate>

New immutable speculate builder.

Released under the MIT License.