Skip to main content
Sub-steps allow you to break down complex steps into smaller, trackable operations within a parent step. They provide fine-grained visibility into complex operations while maintaining the overall step context.

When to Use Sub-steps

  • Complex operations - Multiple distinct actions within one step
  • Parallel execution - Running multiple operations concurrently
  • Debugging visibility - Need to see intermediate progress
  • Performance analysis - Identify bottlenecks within steps

Sub-step Properties

  • Parent step - Associated with a main step
  • Unique name - Within the parent step context
  • Independent status - Can succeed or fail independently
  • Timestamps - Track execution timing
  • Context data - Specific to the sub-step operation

Sub-step vs Step

FeatureStepSub-step
ScopeThread-levelWithin a step
ValidationContract rulesNo validation
NotificationsCan trigger eventsNo events

Using Sub-steps

await thread.step('payment_processing')
  .subStep('validate_payment', { cardType: 'visa' })
  .subStep('check_fraud', { fraudScore: 0.15 })
  .subStep('process_transaction', { txnId: 'TXN-456' })
  .addContext({ amount: 150.00 })
  .success();

Parameters

ParameterTypeDefaultDescription
namestringrequiredSub-step name
dataobject{}Sub-step data
statusstring'success''success' or 'failed'

Best Practices

  • Logical grouping - Sub-steps should be related to parent step
  • Don’t overuse - Not every operation needs a sub-step
  • Clear naming - Describe the specific sub-operation
  • Consistent patterns - Use similar sub-step structures across steps

Next Steps