API Reference

Runtime Types

Type definitions for the Runtime interface, AgentConfig, and related runtime types in Noetic.

Runtime

The core execution engine interface.

interface Runtime {
  execute<I, O>(step: Step<I, O>, input: I, ctx: Context): Promise<O>;
  detachedSpawn<I, O>(step: Step<I, O>, input: I, parentCtx: Context): DetachedHandle<O>;
  createContext(opts?: CreateContextOpts): Context;
  send<T>(channel: Channel<T>, value: T, ctx: Context): void;
  recv<T>(channel: Channel<T>, ctx: Context, opts?: { timeout?: number }): Promise<T>;
  tryRecv<T>(channel: Channel<T>, ctx: Context): T | null;
  getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
  initLayers(layers: MemoryLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
  recallLayers(layers: MemoryLayer[], input: string, ctx: Context): Promise<RecallLayerOutput[]>;
  storeLayers(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<void>;
  disposeLayers(layers: MemoryLayer[], ctx: Context): Promise<void>;
  assembleView(agent: AgentConfig, input: string, ctx: Context): Promise<Item[]>;
  checkpoint(ctx: Context): Promise<void>;
  restore(executionId: string): Promise<Context | null>;
  cancel(ctx: Context, reason?: string): Promise<void>;
  createSpan(name: string, parent: Span | null): Span;
}

Runtime Methods

MethodDescription
execute(step, input, ctx)Execute a step with the given input and context
detachedSpawn(step, input, parentCtx)Launch a step concurrently, returning a DetachedHandle
createContext(opts?)Create a new execution context
send(channel, value, ctx)Send a value to a channel
recv(channel, ctx, opts?)Receive from a channel (blocking)
tryRecv(channel, ctx)Non-blocking receive
getChannelHandle(channel, executionId)Get external channel handle
initLayers(layers, ctx, storage)Initialize memory layers
recallLayers(layers, input, ctx)Run recall on all layers
storeLayers(layers, response, ctx)Run store on all layers
disposeLayers(layers, ctx)Dispose all layers
assembleView(agent, input, ctx)Merge all layer outputs into prompt items
checkpoint(ctx)Persist current execution state
restore(executionId)Restore a previously checkpointed context
cancel(ctx, reason?)Cancel an execution
createSpan(name, parent)Create an observability span

AgentConfig

Declarative configuration for an agent.

interface AgentConfig {
  name: string;
  description: string;
  model: string;
  instructions: string | (() => string | Promise<string>);
  tools?: Tool[];
  outputSchema?: ZodType;
  memory?: MemoryLayer[];
  storage?: StorageAdapter;
  projection?: ProjectionPolicy;
  hooks?: AgentHooks;
}
FieldTypeRequiredDescription
namestringyesAgent name
descriptionstringyesAgent description
modelstringyesDefault model identifier
instructionsstring | (() => string | Promise<string>)yesSystem instructions (static or dynamic)
toolsTool[]noAvailable tools
outputSchemaZodTypenoStructured output schema
memoryMemoryLayer[]noMemory layers to attach
storageStorageAdapternoStorage backend for memory persistence
projectionProjectionPolicynoToken budget and overflow policy
hooksAgentHooksnoBefore/after step hooks

AgentHooks

interface AgentHooks {
  beforeStep?: (step: Step, ctx: Context) => Promise<void>;
  afterStep?: (step: Step, result: unknown, ctx: Context) => Promise<void>;
}
HookParametersDescription
beforeStep(step, ctx)Called before each step executes
afterStep(step, result, ctx)Called after each step completes

DetachedHandle

A handle returned by runtime.detachedSpawn() to track a concurrently running child step.

interface DetachedHandle<O> {
  readonly id: string;
  readonly status: DetachedStatus;
  readonly result: O | undefined;
  readonly error: string | undefined;
  await(timeout?: number): Promise<O>;
}
PropertyTypeDescription
idstringUnique handle identifier (child context ID)
statusDetachedStatusCurrent execution status
resultO | undefinedChild output (set when completed)
errorstring | undefinedError message (set when failed)
await(timeout?)Promise<O>Wait for completion, optionally with timeout in ms

DetachedStatus

const DetachedStatus = {
  Running: 'running',
  Completed: 'completed',
  Failed: 'failed',
} as const;
type DetachedStatus = (typeof DetachedStatus)[keyof typeof DetachedStatus];
ValueDescription
'running'Child step is still executing
'completed'Child step finished successfully
'failed'Child step threw an error

RecallLayerOutput

The output from a single memory layer's recall hook.

interface RecallLayerOutput {
  layerId: string;
  items: Item[];
  tokenCount: number;
}
FieldTypeDescription
layerIdstringWhich layer produced this output
itemsItem[]Items to inject into the prompt
tokenCountnumberToken cost of the items

LLMResponse

The response from an LLM call.

interface LLMResponse {
  items: Item[];
  usage: {
    inputTokens: number;
    outputTokens: number;
    cachedTokens?: number;
  };
  cost?: number;
}
FieldTypeDescription
itemsItem[]Response items (messages, function calls, etc.)
usage.inputTokensnumberInput tokens consumed
usage.outputTokensnumberOutput tokens generated
usage.cachedTokensnumberCached tokens used (optional)
costnumberCost in USD (optional)

On this page