Class SubworkflowExecutor
java.lang.Object
ai.nervemind.app.executor.SubworkflowExecutor
- All Implemented Interfaces:
NodeExecutor
Executor for the "subworkflow" node type - executes another workflow as a
nested operation.
Enables modular workflow composition by invoking other workflows as subroutines. Supports input/output mapping to pass data between parent and child workflows, with optional async execution for fire-and-forget scenarios.
Node Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| workflowId | Long/String | - | ID or name of workflow to execute |
| workflowName | String | - | Name of workflow (alternative to ID) |
| inputMapping | Map | {} | Map subworkflow inputs to expressions |
| outputMapping | Map | {} | Map parent outputs to subworkflow paths |
| waitForCompletion | Boolean | true | Wait for subworkflow to complete |
| timeout | Long | 300000 | Max execution time (5 min default) |
Input Mapping
Maps parent workflow data to subworkflow inputs:
"inputMapping": {
"userId": "$.user.id", // JSONPath-like reference
"config": "configData", // Direct field reference
"static": "hardcoded" // Static value
}
Output Mapping
Maps subworkflow outputs back to parent workflow:
"outputMapping": {
"result": "$.processedData",
"status": "status"
}
Output Data
| Key | Type | Description |
|---|---|---|
| executionId | Long | ID of the subworkflow execution |
| status | String | Execution status (SUCCESS, FAILED, etc.) |
| success | Boolean | Whether subworkflow succeeded |
| output | Map | Mapped output from subworkflow |
| rawOutput | Map | Complete subworkflow output |
| error | String | Error message (if failed) |
Recursion Protection
The executor prevents infinite recursion by checking if the subworkflow being invoked is the same as the currently executing workflow.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSubworkflowExecutor(WorkflowService workflowService, org.springframework.context.ApplicationContext applicationContext) Creates a new subworkflow executor. -
Method Summary
Modifier and TypeMethodDescriptionexecute(ai.nervemind.common.domain.Node node, Map<String, Object> input, ExecutionService.ExecutionContext context) Executes the business logic for this node type.Unique identifier for the node type this executor handles.
-
Constructor Details
-
SubworkflowExecutor
public SubworkflowExecutor(WorkflowService workflowService, org.springframework.context.ApplicationContext applicationContext) Creates a new subworkflow executor.- Parameters:
workflowService- the workflow service for workflow accessapplicationContext- the Spring application context
-
-
Method Details
-
getNodeType
Description copied from interface:NodeExecutorUnique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.- Specified by:
getNodeTypein interfaceNodeExecutor- Returns:
- The unique type string (e.g., "httpRequest", "llmChat").
-
execute
public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String, Object> input, ExecutionService.ExecutionContext context) Description copied from interface:NodeExecutorExecutes the business logic for this node type.- Specified by:
executein interfaceNodeExecutor- Parameters:
node- The node definition containing parameters and configuration. UseNode.parameters()to access user settings.input- Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.context- Verification context providing access to workflow-scoped services, logger, and execution metadata.- Returns:
- A Map containing the results of this node's execution.
Keys in this map become available variables for downstream nodes.
Note: Returningnullis treated as an empty map.
-