Skip to main content
Base class for creating custom (user-defined) nodes. Subclasses must implement the process method. A unique node type is automatically registered once per subclass. Example:
import { CustomNode, ProcessContext } from '@inworld/runtime/graph';

// Define a custom node that processes the input text
class CustomTextNode extends CustomNode {
  async process(
    context: ProcessContext,
    input: string,
  ): Promise<{ processedText: string }> {
    return {
      processedText: input.toUpperCase(),
    };
  }
}

// Create an instance of the custom node
const customTextNode = new CustomTextNode();

Constructor

new CustomNode<InputType = any, OutputType = any>(
    props?: CustomNodeProps
): CustomNode<InputType, OutputType>
Creates a new CustomNode.

Type Parameters

InputType
default:"any"
The type of the inputs to the node, should be any or one of the following CustomNodeInputTypes:
OutputType
default:"any"
The type of the outputs from the node, should be any or one of the following CustomNodeOutputTypes:

Parameters

props (CustomNodeProps) = {} Custom node options including optional executionConfig. Subclasses can pass an executionConfig object to surface additional execution-time properties. Execution config would be available to the process function in the ProcessContext.

Returns

CustomNode<InputType, OutputType> Overrides AbstractNode.constructor

Methods

process

Abstract
process(
    context: ProcessContext,
    ...inputs: InputType[]
): OutputType | Promise<OutputType>
The execution function of the custom node. Must be implemented by subclasses.

Parameters

context (ProcessContext) The execution context. ...inputs (InputType[]) The inputs to the node.

Returns

OutputType | Promise<OutputType> - The output of the node.