npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@loopstack/run-sub-workflow-example

v0.20.8

Published

Execute child workflows from within a parent workflow for hierarchical workflow composition

Readme

@loopstack/run-sub-workflow-example

A module for the Loopstack AI automation framework.

This module provides an example demonstrating how to execute child workflows from within a parent workflow for hierarchical workflow composition.

Overview

The Run Sub Workflow Example shows how to build workflows that spawn and manage child workflows asynchronously. It demonstrates a parent workflow that starts a sub-workflow, tracks its completion status through a callback mechanism, and receives result data from the child workflow.

By using this example as a reference, you'll learn how to:

  • Use ExecuteWorkflowAsync to start child workflows asynchronously
  • Set up callback transitions to handle sub-workflow completion
  • Define workflow results using @Output and getResult()
  • Access child workflow results via runtime.transition.payload in the callback
  • Hide sub-workflows from direct execution using visible: false
  • Display real-time status updates using the LinkDocument
  • Compose complex workflows from smaller, reusable workflow components

This example is essential for developers building workflows that need to orchestrate multiple workflow executions or break down complex processes into manageable sub-workflows.

Installation

See SETUP.md for installation and setup instructions.

How It Works

Key Concepts

1. Parent Workflow Structure

The parent workflow uses ExecuteWorkflowAsync to start a child workflow and sets up a callback transition:

@Injectable()
@Workflow({
  configFile: __dirname + '/run-sub-workflow-example-parent.workflow.yaml',
})
export class RunSubWorkflowExampleParentWorkflow {
  @InjectTool() private createChatMessage: CreateChatMessage;
  @InjectTool() private executeWorkflowAsync: ExecuteWorkflowAsync;
  @InjectTool() private createDocument: CreateDocument;

  @InjectDocument() private linkDocument: LinkDocument;
}

2. Executing a Sub-Workflow Asynchronously

Use executeWorkflowAsync to spawn a child workflow with a callback:

- tool: executeWorkflowAsync
  id: job
  args:
    workflow: runSubWorkflowExampleSubWorkflow
    args: {}
    callback:
      transition: sub_workflow_callback

The callback.transition specifies which transition will be triggered when the sub-workflow completes.

3. Displaying Status with LinkDocument

Use LinkDocument to display a link to the sub workflow and status updates:

- tool: createDocument
  args:
    document: linkDocument
    id: subWorkflow_link
    update:
      content:
        icon: 'Clock'
        label: 'Executing Sub-Workflow...'
        href: '/pipelines/{{ metadata.tools.run_workflow.job.data.task.payload.id }}'

4. Defining Workflow Results

Sub-workflows can return structured results using @Output and getResult():

@Injectable()
@Workflow({
  configFile: __dirname + '/run-sub-workflow-example-sub.workflow.yaml',
})
export class RunSubWorkflowExampleSubWorkflow {
  @InjectTool() private createChatMessage: CreateChatMessage;

  @Output({
    schema: z.object({
      message: z.string(),
    }),
  })
  getResult(): any {
    return {
      message: 'Hi mom!',
    };
  }
}

The @Output decorator on getResult() defines the schema for the workflow's output, and the method returns the actual data when the workflow completes.

5. Handling the Callback and Accessing Results

Define a callback transition that fires when the sub-workflow completes. Access the child workflow's result via runtime.transition.payload:

- id: sub_workflow_callback
  from: sub_workflow_started
  to: end
  trigger: manual
  call:
    - tool: createDocument
      args:
        document: linkDocument
        id: subWorkflow_link
        update:
          content:
            icon: 'CircleCheck'
            label: 'Sub-Workflow completed'
            href: '/pipelines/{{ metadata.tools.run_workflow.job.data.task.payload.id }}'

    - tool: createChatMessage
      args:
        role: 'assistant'
        content: |
          A message from the child workflow:

          {{ runtime.transition.payload.message }}

The trigger: manual ensures this transition only fires when called by the callback, not automatically. The runtime.transition.payload contains the result returned by the child workflow's getResult() method, decorated with @Output.

6. Hiding Sub-Workflows from Direct Execution

Sub-workflows that should only be executed by a parent workflow can be hidden from the Loopstack Studio UI using the visible: false option:

@Workflow({ options: { visible: false } }) runSubWorkflowExampleSubWorkflow: RunSubWorkflowExampleSubWorkflow;

When visible: false is set, the workflow will not appear in the Loopstack Studio for direct execution. It can only be triggered programmatically by another workflow using executeWorkflowAsync. This is useful for helper workflows that are not meant to be run standalone.

Dependencies

This workflow uses the following Loopstack modules:

  • @loopstack/core - Core framework functionality including ExecuteWorkflowAsync
  • @loopstack/core - Provides CreateDocument tool and LinkDocument
  • @loopstack/create-chat-message-tool - Provides CreateChatMessage tool

About

Author: Jakob Klippel

License: Apache-2.0

Additional Resources