Skip to content

Interface: AgentBuilder<TIn, TOut, THandle> ​

Defined in: builders/agent-builder.ts:28

Fluent builder for the universal LLM actor primitive (P.agent(id)).

Compiles to a passive, deeply frozen AgentNode with canonical roleKey derivation.

Extends ​

Type Parameters ​

Type ParameterDefault typeDescription
TInunknownValidated actor input payload type.
TOutunknownValidated actor output payload type.
THandleunknownRuntime handle type of the active isolation scope.

Methods ​

beforeStop() ​

ts
beforeStop(...checks): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:132

Appends deterministic beforeStop checks verified whenever the agent emits a completion turn.

Failed checks reject the completion turn in-band and return structured diagnostics to the model.

Parameters ​

ParameterTypeDescription
...checksreadonly ( | MaybeBuilder<BuiltInCheckASTNode<THandle>> | readonly MaybeBuilder<BuiltInCheckASTNode<THandle>>[])[]Check AST nodes or builders.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


canRaise() ​

ts
canRaise(...interrupts): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:166

Declares voluntary interrupts the agent may raise via synthetic interrupt tool calls.

Exposes each declared InterruptNode as a callable tool in the agent's toolset.

Parameters ​

ParameterTypeDescription
...interruptsreadonly ( | MaybeBuilder<InterruptNode<unknown>> | readonly MaybeBuilder<InterruptNode<unknown>>[])[]Interrupt definitions.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


capabilities() ​

ts
capabilities(configure): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:174

Configures hierarchical orchestration capabilities (.fork(), .speculate(), .mutatePlan(), .escalate()).

Invokes configure with an AgentCapabilitiesBuilder<TIn, THandle> and stores the compiled node.

Parameters ​

ParameterTypeDescription
configure($cap) => AgentCapabilitiesBuilder<TIn, THandle>Capabilities configurator callback.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


grounding() ​

ts
grounding(...sources): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:108

Appends grounding text or source-backed grounding documents to the agent's context.

Injected into the Turn-0 [ROLE_AND_SCOPE_CONTEXT] user frame in declaration order.

Parameters ​

ParameterTypeDescription
...sourcesreadonly ( | MaybeSource<string> | readonly MaybeSource<string>[])[]Grounding strings or source AST nodes.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


input() ​

ts
input<TNewIn>(schema): AgentBuilder<TNewIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:141

Binds the Zod validation schema for the agent's input payload.

Preserves all previously configured partitions, capabilities, and onInterrupt bindings.

Type Parameters ​

Type ParameterDescription
TNewInValidated actor input payload type.

Parameters ​

ParameterTypeDescription
schemaZodType<TNewIn>Zod schema validating agent input.

Returns ​

AgentBuilder<TNewIn, TOut, THandle>

New immutable agent builder.


instructions() ​

ts
instructions(...sources): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:116

Appends role instruction text or source-backed prompt documents to the agent's context.

Injected into the Turn-0 [ROLE_AND_SCOPE_CONTEXT] user frame after role grounding.

Parameters ​

ParameterTypeDescription
...sourcesreadonly ( | MaybeSource<string> | readonly MaybeSource<string>[])[]Instruction strings or source AST nodes.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


lessons() ​

ts
lessons<TLessonIn>(lessons, options?): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:76

Mounts an empirical LessonsNode on this agent for recalling relevant lessons at session start.

Defaults recordOutcomes to true when options is omitted.

Type Parameters ​

Type ParameterDefault typeDescription
TLessonInunknownQuery input payload type of lessons.

Parameters ​

ParameterTypeDescription
lessonsMaybeBuilder<LessonsNode<TLessonIn>>Lessons AST node or builder.
options?{ recordOutcomes?: boolean; }Outcome attribution toggle (recordOutcomes: true default).
options.recordOutcomes?boolean-

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


model() ​

ts
model(modelOrPool): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:49

Binds the LLM model or model pool powering this agent's turns.

Required before .toAST() can compile a valid AgentNode.

Parameters ​

ParameterTypeDescription
modelOrPool| MaybeBuilder<ModelASTNode> | MaybeBuilder<PoolNode<ModelASTNode>>Model or pool AST node.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


onChildInterrupt() ​

ts
onChildInterrupt<TPayload>(interrupt, configure?): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:185

Registers an upward child-interrupt handler (.onChildInterrupt(interrupt, $intr => ...)).

Intercepts interrupt when raised inside a child fork and suspends the fork back to this parent agent, defaulting to .suspendAndReturnToParent() when configure is omitted.

Type Parameters ​

Type ParameterDescription
TPayloadInterrupt payload type.

Parameters ​

ParameterTypeDescription
interruptMaybeBuilder<InterruptNode<TPayload>>Upward interrupt node or builder.
configure?($intr) => ChildInterruptHandlerBuilder<TPayload>Optional child interrupt configurator callback.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


onInterrupt() ​

ts
onInterrupt<TPayload>(interrupt, configure): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:198

Registers an actor-level default interrupt handler preserved across .withPolicy() and .withTools() clones.

Evaluated when interrupt is raised and no step-level .onInterrupt() override matches.

Type Parameters ​

Type ParameterDescription
TPayloadInterrupt payload type.

Parameters ​

ParameterTypeDescription
interruptMaybeBuilder<InterruptNode<TPayload>>Target interrupt node or builder.
configure($intr) => AstBuilder<InterruptHandlerNode<TIn, TPayload, THandle>>Interrupt edge configurator callback.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


output() ​

ts
output<TNewOut>(schema): AgentBuilder<TIn, TNewOut, THandle>;

Defined in: builders/agent-builder.ts:158

Binds the Zod validation schema for the agent's structured output payload.

Validated automatically during the beforeStop completion gate.

Type Parameters ​

Type ParameterDescription
TNewOutValidated actor output payload type.

Parameters ​

ParameterTypeDescription
schemaZodType<TNewOut>Zod schema validating agent output.

Returns ​

AgentBuilder<TIn, TNewOut, THandle>

New immutable agent builder.


partitions() ​

ts
partitions(extractor): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:149

Binds an optional synchronous extractor mapping TIn to ResolutionContext.activePartitions.

Determines which topology contracts and partition-scoped rules are injected at Turn 0.

Parameters ​

ParameterTypeDescription
extractor(input) => readonly string[]Partition ID extractor callback.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


policy() ​

ts
policy(policy): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:92

Binds the capability and sandbox PolicyNode governing tool execution and quantitative limits.

Evaluates pre-flight and post-flight guard clauses on every tool invocation.

Parameters ​

ParameterTypeDescription
policyMaybeBuilder<PolicyNode<THandle>>Policy AST node or builder.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


prefixGroup() ​

ts
prefixGroup(group): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:41

Binds a shared PrefixGroupNode for byte-identical wire system prompts.

Pins shared grounding, instructions, and global rules into Slot 1 of the wire prompt.

Parameters ​

ParameterTypeDescription
groupMaybeBuilder<PrefixGroupNode>Shared prefix group AST node or builder.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


rules() ​

ts
rules(rules): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:66

Mounts a global and scoped RulesNode registry on this agent.

Evaluates scoped rules pre-flight on active partitions and post-call on tool effects.

Parameters ​

ParameterTypeDescription
rulesMaybeBuilder<RulesNode>Rules AST node or builder.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


skills() ​

ts
skills(...items): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:84

Mounts one or more inline SkillNode definitions or source-backed skill bundles.

Populates the Turn-0 skill catalog and unlocks the native activateSkill tool.

Parameters ​

ParameterTypeDescription
...itemsreadonly ( | MaybeBuilder<SkillNode<THandle>> | MaybeBuilder<SourceASTNode<readonly SkillNode<THandle>[]>> | readonly MaybeBuilder<SkillNode<THandle>>[])[]Skills or skill bundle sources.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


timeoutMinutes() ​

ts
timeoutMinutes(minutes): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:124

Sets the wall-clock timeout in minutes for the agent step.

Enforces an upper bound on the agent's total execution duration.

Parameters ​

ParameterTypeDescription
minutesnumberPositive wall-clock timeout in minutes.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


toAST() ​

ts
toAST(): AgentNode;

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 ​

AgentNode

Deeply frozen passive AST node.

Inherited from ​

AstBuilder.toAST


tools() ​

ts
tools(...items): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:100

Mounts always-unlocked ToolASTNode entries directly on this base agent.

Base tools are included in the base agent's id role without appending +tools:... to roleKey.

Parameters ​

ParameterTypeDescription
...itemsreadonly ( | MaybeBuilder<BuiltInToolASTNode<THandle>> | readonly MaybeBuilder<BuiltInToolASTNode<THandle>>[])[]Tools or tool arrays.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


topology() ​

ts
topology<TPart>(topology): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:58

Binds a relational TopologyNode whose live partition contracts are injected into the Turn-0 context frame.

Enables automatic partition contract injection and epoch tracking for active partitions.

Type Parameters ​

Type ParameterDefault typeDescription
TPart extends stringstringLiteral partition identifier union of topology.

Parameters ​

ParameterTypeDescription
topologyMaybeBuilder<TopologyNode<TPart>>Relational topology AST node or builder.

Returns ​

AgentBuilder<TIn, TOut, THandle>

New immutable agent builder.


withPolicy() ​

ts
withPolicy(newPolicy): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:206

Clones this agent with newPolicy while preserving roleKey, .prefixGroup(), .partitions(), and .onInterrupt() handlers.

Produces a new immutable AgentBuilder without mutating the source agent definition.

Parameters ​

ParameterTypeDescription
newPolicyMaybeBuilder<PolicyNode<THandle>>Replacement policy node or builder.

Returns ​

AgentBuilder<TIn, TOut, THandle>

Cloned immutable agent builder.


withTools() ​

ts
withTools(...extraTools): AgentBuilder<TIn, TOut, THandle>;

Defined in: builders/agent-builder.ts:214

Clones this agent with additional tools and derives the canonical order-independent roleKey ("${id}+tools:${sortedNames}").

Preserves all existing configuration while appending extraTools to the cloned agent.

Parameters ​

ParameterTypeDescription
...extraToolsreadonly ( | MaybeBuilder<BuiltInToolASTNode<THandle>> | readonly MaybeBuilder<BuiltInToolASTNode<THandle>>[])[]Additional tools to mount.

Returns ​

AgentBuilder<TIn, TOut, THandle>

Cloned immutable agent builder with updated roleKey.

Properties ​

PropertyModifierTypeDescriptionDefined in
idreadonlystringUnique identifier of the base agent definition.builders/agent-builder.ts:31
roleKeyreadonlystringCanonical role key (id or "${id}+tools:${sortedExtraToolNames.join(',')}").builders/agent-builder.ts:33

Released under the MIT License.