Step Types
Type definitions for all step variants in Noetic's discriminated union.
Step Union
The Step type is a discriminated union over the kind field:
import type {
Step,
StepBranch,
StepFork,
StepLLM,
StepLoop,
StepProvide,
StepRun,
StepSpawn,
StepTool,
} from '@noetic/core';
type _AssertShape<TMemory, I, O> =
| StepRun<TMemory, I, O>
| StepLLM<TMemory, I, O>
| StepTool<TMemory, I, O>
| StepBranch<TMemory, I, O>
| StepFork<TMemory, I, O>
| StepSpawn<TMemory, I, O>
| StepProvide<TMemory, I, O>
| StepLoop<TMemory, I, O>;
type _AssertSubset<TMemory, I, O> = _AssertShape<TMemory, I, O> extends Step<TMemory, I, O>
? true
: false;The exported Step union additionally includes StepEvery for fixed-interval scheduling.
StepRun
StepRun<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'run' | yes | Discriminant |
id | string | yes | Step identifier |
execute | (input: I, ctx: Context<TMemory>) => Promise<O> | yes | Async function to execute |
retry | RetryPolicy | no | Retry configuration |
StepLLM
StepLLM<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'llm' | yes | Discriminant |
id | string | yes | Step identifier |
model | string | yes | Model identifier |
instructions | string | no | System prompt / instructions for the model |
tools | Tool[] | no | Allowed tool subset (undefined = all, [] = none) |
output | ZodType<O> | no | Structured output schema |
params | ModelParams | no | Sampling parameters |
emit | boolean | ((eventType, data) => boolean) | no | Controls framework event emission for this step. Defaults to true. Pass false to suppress all framework events, or a filter function to allow specific events through. |
StepTool
StepTool<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'tool' | yes | Discriminant |
id | string | yes | Step identifier |
tool | Tool<ZodType<I>, ZodType<O>> | yes | Tool definition |
args | Partial<I> | no | Preset arguments |
StepBranch
StepBranch<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'branch' | yes | Discriminant |
id | string | yes | Step identifier |
route | (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O> | null | yes | Routing function (null skips) |
StepFork
Fork has three mode variants, each a separate interface.
StepForkRace
StepForkRace<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'fork' | yes | Discriminant |
id | string | yes | Step identifier |
mode | 'race' | yes | First completion wins |
paths | (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[] | yes | Path factory |
concurrency | number | no | Max parallel paths |
StepForkAll
StepForkAll<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'fork' | yes | Discriminant |
id | string | yes | Step identifier |
mode | 'all' | yes | Wait for all paths |
paths | (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[] | yes | Path factory |
merge | (results: O[], ctx: Context<TMemory>) => O | yes | Merge function |
concurrency | number | no | Max parallel paths |
StepForkSettle
StepForkSettle<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'fork' | yes | Discriminant |
id | string | yes | Step identifier |
mode | 'settle' | yes | Wait for all, include errors |
paths | (input: I, ctx: Context<TMemory>) => Step<TMemory, I, O>[] | yes | Path factory |
merge | (results: SettleResult<O>[], ctx: Context<TMemory>) => O | yes | Merge function |
concurrency | number | no | Max parallel paths |
StepProvide
StepProvide<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'provide' | yes | Discriminant |
id | string | yes | Step identifier |
child | Step<TMemory, I, O> | yes | Child step to execute with the provided layers |
memory | MemoryConfig | MemoryLayer[] | yes | Memory layers available to all descendant steps |
StepSpawn
StepSpawn<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'spawn' | yes | Discriminant |
id | string | yes | Step identifier |
child | Step<TMemory, I, O> | yes | Child step to execute |
memory | MemoryConfig | MemoryLayer[] | no | Spawn-local memory layers |
timeout | number | no | Timeout in milliseconds |
StepLoop
StepLoop<TMemory, I, O>
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'loop' | yes | Discriminant |
id | string | yes | Step identifier |
steps | ReadonlyArray<Step<TMemory, I, O>> | yes | Loop body steps |
until | Until | yes | Termination predicate |
maxIterations | number | no | Safety limit on iterations |
maxHistorySize | number | no | Max history items to retain |
inbox | Channel<string> | no | Channel for external messages that prevent loop from stopping |
parkTimeout | number | no | Milliseconds to wait on inbox before stopping (0 = non-blocking) |
prepareNext | (output: O, verdict: Verdict, ctx: Context<TMemory>) => I | no | Transform output to next input |
onError | (error: NoeticError, ctx: Context<TMemory>) => 'retry' | 'skip' | 'abort' | no | Error handler |
StepEvery
StepEvery<TMemory, I, O>
A step that runs a body step on a fixed-interval schedule, optionally woken sooner by a wake channel. Runs forever until the executing context is cancelled. The operator output is void — every does not accumulate iteration outputs.
| Field | Type | Required | Description |
|---|---|---|---|
kind | 'every' | yes | Discriminant |
id | string | yes | Step identifier |
step | Step<TMemory, I, O> | yes | Body step executed on each iteration |
ms | number | yes | Park duration between iterations in milliseconds. Must be >= 0. |
wakeOn | Channel<unknown> | no | Channel that wakes the parking interval when any value arrives |
onError | 'continue' | 'fail' | no | Behavior when step throws. Defaults to 'continue' (record the error and keep parking). |
jitter | number | no | Random jitter applied to the park duration in milliseconds. Must be >= 0. Defaults to 0. |
Supporting Types
SettleResult
| Field | Type | Description |
|---|---|---|
stepId | string | Step that produced this result |
status | 'fulfilled' | 'rejected' | Outcome |
value | O | Present if fulfilled |
error | NoeticError | Present if rejected |
RetryPolicy
| Field | Type | Description |
|---|---|---|
maxAttempts | number | Maximum retry attempts |
backoff | 'fixed' | 'linear' | 'exponential' | Backoff strategy |
initialDelay | number | Initial delay in milliseconds |
maxDelay | number | Maximum delay cap (optional) |
ModelParams
| Field | Type | Description |
|---|---|---|
temperature | number | Sampling temperature (optional) |
topP | number | Nucleus sampling (optional) |
maxTokens | number | Max response tokens (optional) |
stopSequences | string[] | Stop sequences (optional) |
Tool
| Field | Type | Description |
|---|---|---|
name | string | Tool name (used by the LLM for selection). |
description | string | Tool description shown to the LLM. |
input | ZodType<I> | Zod schema validating tool input arguments. |
output | ZodType<O> | Zod schema validating tool return value. |
event | ZodType | Optional Zod schema validating streaming events yielded during execution. |
itemSchemas | ItemSchemaExtensions | Optional item schemas for tool-call/result extensions contributed by this tool. |
decorateResultItem | (params) => Item | Decorate the harness-created tool-result item before it is appended/emitted. |
execute | (args: z.infer<I>, toolCtx: ToolExecutionContext) => Promise<z.infer<O>> | AsyncGenerator<unknown, z.infer<O>> | Async function (or generator) that performs the tool's work. |
needsApproval | boolean | Optional. When true, execution pauses for human approval before running. |
memory | ToolMemoryDeclaration | Optional. Declares tool-owned memory the runtime materializes into a MemoryLayer. |
ExecuteStepFn
declare const executeStepShape: <TMemory, I, O>(
step: Step<TMemory, I, O>,
input: I,
ctx: Context<TMemory>,
) => Promise<O>;