Class SubworkflowExecutor

java.lang.Object
ai.nervemind.app.executor.SubworkflowExecutor
All Implemented Interfaces:
NodeExecutor

@Component public class SubworkflowExecutor extends Object implements 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

Subworkflow node configuration 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

Output keys added by this executor
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 Details

    • SubworkflowExecutor

      public SubworkflowExecutor(WorkflowService workflowService, org.springframework.context.ApplicationContext applicationContext)
      Creates a new subworkflow executor.
      Parameters:
      workflowService - the workflow service for workflow access
      applicationContext - the Spring application context
  • Method Details

    • getNodeType

      public String getNodeType()
      Description copied from interface: NodeExecutor
      Unique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.
      Specified by:
      getNodeType in interface NodeExecutor
      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: NodeExecutor
      Executes the business logic for this node type.
      Specified by:
      execute in interface NodeExecutor
      Parameters:
      node - The node definition containing parameters and configuration. Use Node.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: Returning null is treated as an empty map.