Direct Execution (Ephemeral Workflows)
Direct execution (@since v0.8.0) allows you to execute a series of steps without first saving them as a Pipeline or Flow in the database. This is ideal for one-off tasks, programmatic triggers, or AI-generated workflows.
How It Works
When a direct execution workflow is triggered via the /execute REST endpoint, the system:
- Validates the Payload: Ensures the
workflowobject contains a validstepsarray with supported step types and handlers. - Dynamic Config Generation: The
Execute::build_configs_from_workflow()method transforms the JSON request into internalflow_configandpipeline_configformats. - Direct Execution Mode: Sets
flow_id = 'direct'andpipeline_id = 'direct'within these configurations. The string'direct'explicitly indicates direct execution mode, bypassing normal flow/pipeline lookup. - Job Initialization: Creates a standard Job record. Even though the workflow is ephemeral, the Job and its Logs are still persisted for monitoring and debugging.
- Snapshotting: The dynamically generated configurations are stored in the Job’s
engine_datasnapshot. This ensures the workflow definition remains consistent even if it doesn’t exist in thewp_datamachine_flowstable. - Standard Execution: The job enters the standard execution cycle:
datamachine_run_flow_now→datamachine_execute_step→datamachine_schedule_next_step.
Use Cases
- AI Chatbot Execution: When the Data Machine chat agent suggests a sequence of actions, it can trigger them immediately as a direct execution workflow.
- External Triggers: Programmatically trigger a specific sequence of steps from an external script without cluttering the WordPress database with temporary pipelines.
- Testing: Quickly test a new combination of handlers and prompts without going through the Pipeline Builder UI.
- CLI Tools: Use the
wp datamachine agentWP-CLI command to run the chat agent directly for debugging and validation.
Limitations
- No Persistence: You cannot "edit" a direct execution workflow once it has started.
- No Automatic Retries: If a direct execution workflow fails, it must be re-submitted via the API.
- Direct Mode: Because
flow_idis'direct', certain features that rely on flow-specific settings (like flow-level overrides) must be included directly in thehandler_configwithin the request.
Example Payload
See the Execute Endpoint Documentation for detailed payload examples.