Skip to main content

createInputNode

workflow.createInputNode() Create a normal input node. It is usually placed in the first step of workflow and is used to trim, verify, convert, or complete the input constructed by executor.

Signature

workflow.createInputNode<Input>(
options?: InputNodeOptions<Input, Input>,
): BaseNode<Input, Input>

workflow.createInputNode<Input, Output>(
options: InputNodeOptions<Input, Output> & {
parse: InputParser<Input, Output>;
},
): BaseNode<Input, Output>

Parameter

ParameterTypeDescription
optionsInputNodeOptions<Input, Output>node name, parsing function, history, and meta information. Creates a default input node when not passed.

InputNodeOptions

FieldTypeDescription
namestringNode name, default "input".
parse(input, context) => OutputInput parsing function; return input as it is if it is not passed.
historyLimitnumberThe number of nodes retained in the execution history. The default value is 50.
metadataWorkflowNodeMetadataInputThe node displays meta information.

parse Input

NameDescription
inputThe input to parse, from the workflow run or upstream node.
contextruntime injected NodeContext, can read metadata, KV, conversation, provider, abortSignal, etc.

Return value

ReturnTypeDescription
Node ObjectBaseNode<Input, Output>Execute via workflow.runNode(inputNode, input, context).
Node outputOutputparse returns the value as input to the downstream node.

Analysis process

PhaseInputResult
executorargs/API/formInput
createInputNode nodeInput, NodeContextOutput
Downstream nodeOutputContinue processing or enter the LLM/output node

Example

const inputNode = workflow.createInputNode<Input, ParsedInput>({
name: "parse-input",
parse(input) {
return {
message: input.message.trim(),
count: Number(input.count ?? 1),
};
},
});

Common Usage

SceneMethod
Cleanup StringIn parse trim().
Convert typeConvert the string constructed by executor to number/boolean/object.
Input verificationworkflow.WorkflowError is thrown when the verification fails, and the type is usually input_validation.
Direct pass-throughDo not pass parse, node output is equal to input.