Purpose
The Sub Use Case node calls another use case (workflow) as a step within the current workflow. This enables composition, reusability, and modularity. Build complex workflows by combining smaller, focused workflows. Sub Use Case nodes are the key to building maintainable AI systems. Instead of duplicating logic across workflows, create reusable workflows that can be called from anywhere.How it works
When execution reaches a Sub Use Case node, it triggers a child workflow execution.Parent workflow reaches Sub Use Case node
The parent workflow arrives at the Sub Use Case node with data in its variable store.
Child workflow starts
A new Temporal workflow execution starts for the child use case. This is a completely independent execution with its own variable store.
Child workflow executes
The child workflow runs through all its activities: agents, tools, conditions, human tasks, etc. The parent workflow waits.
Sub Use Case executions are fully independent. Each has its own execution history, logs, and variable store. This isolation makes workflows easier to test, debug, and maintain.
Configuration
Configure a Sub Use Case node to call the right workflow with the right data.Select target use case
Choose which use case to execute from your project. The target use case can be any workflow you’ve created in MagOneAI Studio. Available use cases:- Workflows in the current project
- Workflows shared from other projects (if you have access)
- Template workflows from the MagOneAI library
- “Send Notification” — Reusable workflow for sending emails/Slack/SMS
- “Document Verification” — Standard KYC document verification
- “Risk Assessment” — Company-wide risk scoring logic
- “Compliance Check” — Standard compliance validation
Input mapping
Map data from the parent workflow to the child workflow’s expected inputs. Example: Calling a notification workflow- Trigger inputs:
{{trigger.input.*}} - Previous activity outputs:
{{activity_name.output.*}} - Static values: Hard-coded strings, numbers, booleans
Output mapping
Map the child workflow’s output back to the parent workflow’s variable store. Example output mapping:Timeout and retry settings
Configure how to handle child workflow failures: Timeout:- Set a maximum execution time for the child workflow
- If exceeded, the child workflow is cancelled and the parent can handle the timeout
- Number of retry attempts if the child workflow fails
- Backoff strategy between retries
- Which error types trigger retries
When to use sub use cases
Sub Use Case nodes are powerful, but they add complexity. Use them strategically.Use sub use cases for:
Reusability
A workflow component is used by multiple parent workflows.Example: A “Send Notification” workflow called by 20 different workflows. Change notification logic once, all workflows benefit.
Modularity
Break complex workflows into smaller, focused pieces that are easier to understand and maintain.Example: A “Customer Onboarding” workflow calls sub-workflows for “Document Verification”, “Risk Assessment”, and “Account Creation”.
Separation of concerns
Different teams own different pieces of the workflow.Example: The compliance team owns the “Compliance Check” workflow, the finance team owns “Credit Assessment”, and the main workflow orchestrates them.
Independent testing
Test complex workflow components independently before integrating.Example: Test the “Document Verification” workflow thoroughly in isolation, then integrate it into larger workflows with confidence.
Versioning and rollback
Update sub-workflows independently without changing parent workflows.Example: Deploy a new version of “Risk Assessment” workflow. Parent workflows automatically use the new version.
Don’t use sub use cases for:
Simple sequences
If it’s just a few nodes in sequence, keep them in the same workflow. Sub Use Cases add overhead.
One-time logic
If the logic is only used in one place and won’t be reused, don’t extract it to a sub-workflow.
Tight coupling
If the “sub” workflow is deeply coupled to the parent’s data structures, it’s not truly reusable. Keep it in the parent.
Examples
Let’s look at practical examples of Sub Use Case nodes.Example 1: Reusable notification workflow
Scenario: Multiple workflows need to send notifications via email, Slack, or SMS. Create one notification workflow, use it everywhere. Sub Use Case: “Send Notification”- One place to update notification logic
- Consistent notification handling across all workflows
- Easy to add new notification channels (Teams, WhatsApp, etc.)
- Centralized logging and monitoring
Example 2: Document verification pipeline
Scenario: Multiple workflows need to verify documents. Standardize the verification process. Sub Use Case: “Document Verification”- Consistent verification across all document types
- Easy to update verification logic globally
- Independent testing of verification workflow
- Reusable across onboarding, KYC updates, re-verification, etc.
Example 3: Risk assessment module
Scenario: Multiple workflows need risk assessment. Standardize risk scoring. Sub Use Case: “Risk Assessment”- Consistent risk assessment methodology
- Single source of truth for risk logic
- Easy to update risk models globally
- Centralized compliance and audit trail
Example 4: Modular customer onboarding
Scenario: Customer onboarding is complex. Break it into focused sub-workflows. Main Workflow: Customer Onboarding- Developed by the responsible team
- Tested in isolation
- Versioned and deployed
- Monitored and optimized
- Clear separation of concerns
- Teams work independently
- Easy to test and debug
- Flexible to update individual components
Best practices
Design for reusability
Design for reusability
When creating a workflow that might become a sub-workflow, design it to be reusable:
- Clear, well-defined inputs
- Predictable outputs
- No hidden dependencies on external state
- Comprehensive error handling
Use semantic versioning
Use semantic versioning
Version your sub-workflows (v1.0, v1.1, v2.0). Parent workflows can specify which version to use, enabling gradual rollout of changes.
Document inputs and outputs
Document inputs and outputs
Clearly document what inputs the sub-workflow expects and what outputs it produces. This is the “contract” between parent and child.
Handle errors gracefully
Handle errors gracefully
Sub-workflows should return structured error information, not just fail. Parent workflows can then decide how to handle specific errors.
Keep sub-workflows focused
Keep sub-workflows focused
Each sub-workflow should do one thing well. Don’t create mega sub-workflows that try to do everything.
Monitor sub-workflow performance
Monitor sub-workflow performance
Track execution times, success rates, and costs for sub-workflows. Optimize frequently-used sub-workflows aggressively.
Test independently
Test independently
Write tests for sub-workflows before integrating them into parent workflows. This catches issues early.
Advanced patterns
Conditional sub-workflow selection
Choose which sub-workflow to call based on data:Retry with fallback sub-workflow
Try a primary sub-workflow, fall back to an alternative on failure:Chained sub-workflows
Call sub-workflows in sequence, each building on the previous:Dynamic sub-workflow invocation
Use ForEach to call a sub-workflow for each item in a collection:Performance considerations
Execution overhead
Each Sub Use Case node adds overhead:- Temporal workflow creation
- Input/output serialization
- Separate execution history