API Reference
Context Types
Type definitions for Context, ItemLog, Item variants, and content parts in Noetic.
The execution context threaded through every step.
interface Context<TState = unknown> {
readonly id: string;
readonly stepCount: number;
readonly tokens: TokenUsage;
readonly elapsed: number;
readonly cost: number;
state: TState;
readonly parent: Context | null;
readonly depth: number;
readonly span: Span;
readonly threadId: string;
readonly resourceId?: string;
readonly itemLog: ItemLog;
readonly lastStepMeta: StepMeta | null;
recv<T>(channel: Channel<T>, opts?: { timeout?: number }): Promise<T>;
send<T>(channel: Channel<T>, value: T): void;
tryRecv<T>(channel: Channel<T>): T | null;
checkpoint(): Promise<void>;
complete<T>(value: T): void;
readonly completed: boolean;
readonly completionValue: unknown;
readonly aborted: boolean;
readonly abortReason?: string;
abort(reason?: string): void;
}
| Field | Type | Description |
|---|
id | string | Unique execution identifier |
stepCount | number | Number of steps executed so far |
tokens | TokenUsage | Accumulated token usage |
elapsed | number | Elapsed time in milliseconds |
cost | number | Accumulated cost in USD |
state | TState | Mutable user state |
parent | Context | null | Parent context (for spawned agents) |
depth | number | Nesting depth (0 for root) |
span | Span | Observability span |
threadId | string | Thread identifier for memory scoping |
resourceId | string | Resource identifier for memory scoping (optional) |
itemLog | ItemLog | Conversation history |
lastStepMeta | StepMeta | null | Metadata from the last executed step |
completed | boolean | Whether complete() has been called |
completionValue | unknown | Value passed to complete() |
aborted | boolean | Whether abort() has been called |
abortReason | string | Reason passed to abort() (optional) |
| Method | Signature | Description |
|---|
recv | <T>(channel, opts?) => Promise<T> | Receive from a channel (blocking) |
send | <T>(channel, value) => void | Send to a channel |
tryRecv | <T>(channel) => T | null | Non-blocking receive |
checkpoint | () => Promise<void> | Persist current state |
complete | <T>(value) => void | Signal completion with a value |
abort | (reason?) => void | Signal abort |
An append-only log of conversation items.
interface ItemLog {
readonly items: ReadonlyArray<Item>;
append(item: Item): void;
}
| Field | Type | Description |
|---|
items | ReadonlyArray<Item> | All items in the log |
append | (item: Item) => void | Append a new item |
The Item type is a discriminated union over the type field:
type Item =
| MessageItem
| FunctionCallItem
| FunctionCallOutputItem
| ReasoningItem
| ExtensionItem;
All items share this base:
| Field | Type | Description |
|---|
id | string | Unique item identifier |
status | 'in_progress' | 'completed' | 'incomplete' | 'failed' | Item status |
| Field | Type | Description |
|---|
type | 'message' | Discriminant |
role | 'user' | 'assistant' | 'system' | 'developer' | Message author |
content | ContentPart[] | Message content parts |
| Field | Type | Description |
|---|
type | 'function_call' | Discriminant |
call_id | string | Unique call identifier |
name | string | Function name |
arguments | string | JSON-encoded arguments |
| Field | Type | Description |
|---|
type | 'function_call_output' | Discriminant |
call_id | string | Matching call identifier |
output | string | JSON-encoded output |
| Field | Type | Description |
|---|
type | 'reasoning' | Discriminant |
content | ContentPart[] | Reasoning content |
summary | ContentPart[] | Summary of reasoning (optional) |
encrypted_content | string | Encrypted reasoning content (optional) |
| Field | Type | Description |
|---|
type | `x-${string}` | Custom type prefixed with x- |
data | Record<string, unknown> | Arbitrary data |
type ContentPart =
| { type: 'output_text'; text: string }
| { type: 'input_text'; text: string }
| { type: 'refusal'; refusal: string };
| Variant | Fields | Description |
|---|
output_text | text: string | Text generated by the model |
input_text | text: string | Text from the user or system |
refusal | refusal: string | Model refusal message |
| Field | Type | Description |
|---|
input | number | Input tokens consumed |
output | number | Output tokens generated |
total | number | Total tokens |
| Field | Type | Description |
|---|
toolCalls | FunctionCallItem[] | Tool calls made in this step (optional) |
usage | { inputTokens, outputTokens, cachedTokens? } | Token usage (optional) |
cost | number | Step cost in USD (optional) |
responseItems | ReadonlyArray<Item> | Items produced by this step (optional) |