Skip to main content

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.
1

Parent workflow reaches Sub Use Case node

The parent workflow arrives at the Sub Use Case node with data in its variable store.
2

Input mapping

Data from the parent workflow is mapped to the child workflow’s input parameters.
3

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.
4

Child workflow executes

The child workflow runs through all its activities: agents, tools, conditions, human tasks, etc. The parent workflow waits.
5

Child workflow completes

When the child workflow finishes, its final output is captured.
6

Output mapping

The child workflow’s output is mapped back to the parent workflow’s variable store.
7

Parent workflow continues

The parent workflow resumes execution with access to the child workflow’s results.
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 child use case must be in the same project as the parent workflow and must be active. Configuration:
Example target use cases:
  • “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
Example: Calling a document verification workflow
Variable references: You can reference any data from the parent workflow’s variable store:
  • Trigger inputs: {{input.*}}
  • Previous activity outputs: {{activity_name.*}}
  • 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:
Accessing nested outputs: If the child workflow returns structured data:

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
Retry policy:
  • Number of retry attempts if the child workflow fails
  • Backoff strategy between retries
  • Which error types trigger retries
Example configuration:

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.
Rule of thumb: If you find yourself copying workflow segments between workflows, extract them to a Sub Use Case. If a workflow is getting too complex to understand at a glance, break it into smaller Sub Use Cases.

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”
Parent workflows call it:
Benefits:
  • 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”
Parent workflow: Customer Onboarding
Benefits:
  • 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”
Multiple parent workflows use it: Workflow 1: New Customer Onboarding
Workflow 2: Large Transaction Processing
Workflow 3: Credit Application
Benefits:
  • 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
Each sub-workflow is independently:
  • Developed by the responsible team
  • Tested in isolation
  • Versioned and deployed
  • Monitored and optimized
Benefits:
  • Clear separation of concerns
  • Teams work independently
  • Easy to test and debug
  • Flexible to update individual components

Best practices

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
Version your sub-workflows (v1.0, v1.1, v2.0). Parent workflows can specify which version to use, enabling gradual rollout of changes.
Clearly document what inputs the sub-workflow expects and what outputs it produces. This is the “contract” between parent and child.
Sub-workflows should return structured error information, not just fail. Parent workflows can then decide how to handle specific errors.
Each sub-workflow should do one thing well. Don’t create mega sub-workflows that try to do everything.
Track execution times, success rates, and costs for sub-workflows. Optimize frequently-used sub-workflows aggressively.
Write tests for sub-workflows before integrating them into parent workflows. This catches issues early.
Sub Use Case nodes create parent-child workflow relationships. Be careful not to create circular dependencies (Workflow A calls B, B calls A). MagOneAI will detect and prevent this, but design workflows to avoid it.

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
Impact: ~100-200ms overhead per sub-workflow invocation Mitigation: Use sub-workflows for substantial work (multi-step processes), not single activities.

Nested depth limits

Avoid deeply nested sub-workflows (workflow calls workflow calls workflow calls…). Recommended: Max 3 levels of nesting Absolute maximum: 5 levels Deep nesting makes workflows hard to debug and may hit Temporal limits.

Parallel sub-workflow execution

When using Parallel nodes to call multiple sub-workflows, each executes independently:
This is efficient for independent operations.

Next steps

Workflow overview

Understand how workflows compose into larger systems

Parallel execution

Call multiple sub-workflows simultaneously

Condition node

Conditionally call different sub-workflows

Memory system

Pass data between parent and child workflows