Skip to Content

Workflow Extensions

This example demonstrates how workflows can extend other workflows and use arguments for customization. We’ll build a report generation workflow that can be extended by other workflows with customizable content and additional features.

Note: This example uses create_mock tools for demonstration purposes to keep the example simple and focused on core workflow concepts. In real-world use cases, you would replace these mock tools with actual tools that perform the specific processing operations your automation requires (such as API calls, data transformations, file operations, or LLM interactions).

Base Workflow Definition

The base workflow defines a reusable report generation pattern with configurable arguments:

workflows: - name: generate_base_report title: "Base Report Generation Workflow" type: stateMachine parameters: # Argument definitions (JSON schema) for validation type: object properties: topic: type: string minLength: 1 description: "The topic or subject for the report" report_type: type: string enum: ["quarterly", "annual", "project", "analysis"] default: "analysis" description: "Type of report to generate" audience: type: string enum: ["executives", "managers", "technical", "general"] default: "general" description: "Target audience for the report" required: - topic transitions: - name: generate_report from: start to: report_generated call: - tool: create_mock arguments: input: | You are a professional report writer. Create a comprehensive {{ arguments.report_type }} report for a {{ arguments.audience }} audience. The report should be well-structured with clear sections, data analysis, and actionable insights. Generate a detailed report about: {{ arguments.topic }} output: | # Renewable Energy Market Trends - Q4 2024 Executive Report ## Executive Overview The renewable energy sector has demonstrated unprecedented growth in 2024, with solar and wind technologies leading market expansion. Global renewable capacity increased by 15% year-over-year, driven by favorable policy frameworks and declining technology costs. ## Key Market Developments - Solar photovoltaic installations grew by 22% globally - Offshore wind capacity expanded by 18% in key markets - Energy storage deployment increased by 35% - Grid modernization investments reached $180 billion - Cost competitiveness improved with solar LCOE decreasing by 8% - Wind LCOE decreased by 6% while battery storage costs fell by 15% as: REPORT_CONTENT - tool: create_chat_message arguments: role: 'assistant' content: ${ REPORT_CONTENT } - name: complete_report from: report_generated to: end call: - tool: create_chat_message arguments: role: 'assistant' content: 'πŸ“Š Report generation completed!'

Extending Base Workflow

The workflow extends the base workflow, provides arguments, and adds custom transitions:

workflows: - name: generate_full_report title: "Report Generation with Executive Summary" type: stateMachine extends: generate_base_report # Extend the base workflow arguments: # Set arguments for base workflow topic: "renewable energy market trends in 2024" report_type: "quarterly" audience: "executives" transitions: # Override the completion transition to add summary generation - name: complete_report from: report_generated to: summary_generated call: - tool: create_mock arguments: input: | You are an expert at creating executive summaries. Create a concise, high-level summary that captures the key findings, insights, and recommendations from the full report. Focus on actionable information for executive decision-making. Create an executive summary for this report: {{ REPORT_CONTENT }} output: | ## Executive Summary **Growth Overview:** The renewable energy sector achieved exceptional 15% capacity expansion in 2024, with solar and wind technologies driving market leadership through improved cost competitiveness and supportive policy frameworks. **Market Highlights:** Solar installations surged 22% globally while offshore wind expanded 18%. Energy storage deployment accelerated by 35%, supported by $180 billion in grid modernization investments and significant cost reductions across all technologies. as: EXECUTIVE_SUMMARY - tool: create_chat_message arguments: role: 'assistant' content: ${ EXECUTIVE_SUMMARY } # Add final completion transition - name: log_results from: summary_generated to: end call: - tool: create_chat_message arguments: role: 'assistant' content: | πŸ“‹ Complete report with executive summary finished! **Topic**: {{ arguments.topic }} **Full Report:** {{ REPORT_CONTENT.length }} characters **Executive Summary:** {{ EXECUTIVE_SUMMARY.length }} characters

The extended workflow creates an enhanced flow with executive summary:

Before:

After:

Understanding Workflow Extension

Parameters

workflows: - name: generate_base_report type: stateMachine parameters: # JSON Schema for arguments validation type: object properties: topic: type: string minLength: 1 description: "The topic or subject for the report" report_type: type: string enum: ["quarterly", "annual", "project", "analysis"] default: "analysis" audience: type: string enum: ["executives", "managers", "technical", "general"] default: "general" required: - topic transitions: # Workflow logic using arguments

Key Concepts:

  • Parameters Schema: Define validation rules for arguments using JSON Schema
  • Arguments Access: Use {{ arguments.propertyName }} to access provided arguments
  • Validation: Arguments are validated against the parameters schema

Extends and Arguments

workflows: - name: generate_full_report extends: generate_base_report # Inherit base workflow arguments: # Provide validated arguments topic: "renewable energy market trends in 2024" report_type: "quarterly" audience: "executives" transitions: # Override or extend transitions - name: complete_report # Override base transition # Custom implementation with summary generation

Key Concepts:

  • Extension: Workflows extend other workflows
  • Arguments: Provide arguments to be used in extended workflows
  • Transitions: Add or override transitions

Workflow Extension Patterns

Pure Extension (Arguments Only)

In this pattern we use a workflow by defining arguments but do not override or extend their transitions.

workflows: - name: simple_report_workflow extends: generate_base_report arguments: topic: "market analysis for Q3 2024" report_type: "analysis" audience: "managers" # No transitions - uses base workflow as-is

Extension with Override

We can override existing transitions by defining a transition with the same name in the parent workflow.

workflows: - name: technical_report_workflow extends: generate_base_report arguments: topic: "system architecture review" report_type: "project" audience: "technical" transitions: - name: generate_report # Override base implementation from: start to: report_generated call: - tool: technical_report_generator

Extension with Additional Transitions

We can add new transitions (new name)

workflows: - name: reviewed_report_workflow extends: generate_base_report arguments: topic: "compliance audit findings" report_type: "annual" audience: "executives" transitions: - name: requestReview # Add new transition from: end to: underReview call: - tool: review_request_tool

Key Concepts:

  • Flexible Extension: Multiple ways to extend base workflows
  • Arguments Inheritance: Extensions use a merged arguments schema (when working with nested workflows)
  • Selective Customization: Override only what needs to be different

Multiple Workflow Extensions

Different workflows can extend the same base workflow for various report types:

# base workflow workflows: - name: base_workflow parameters: ... # Define base_workflow parameters transitions: ... # extending workflow 1 - name: extending_workflow_1 extends: base_workflow arguments: # Set arguments for base_workflow ... # extending workflow 2 - name: extending_workflow_2 extends: base_workflow arguments: # Set arguments for base_workflow ...

Multi-Level Workflow Extension

Workflows can create inheritance chains where a workflow extends another workflow that extends yet another workflow. The system merges schemas, transitions, and other properties across the entire inheritance hierarchy before execution.

# Base workflow workflows: - name: base_workflow type: stateMachine parameters: ... # Define base_workflow parameters transitions: ... # workflow extending base_workflow - name: extending_workflow extends: base_workflow parameters: ... # Define own properties to be merged with base_workflow properties transitions: ... # Override or extend base transitions # workflow extending extending_workflow - name: final_workflow extends: base_workflow parameters: ... # Define own properties to be merged with extending_workflow properties arguments: ... # Set arguments for all workflows transitions: ... # Override or extend base transitions

During execution, Loopstack merges the inheritance chain into a single workflow. The outer workflow needs to define the arguments for all inherited workflows.

Running This Example

This example is already available in Loopstack Studio:

  1. Navigate to the Studio interface
  2. Switch to the examples workspace
  3. Select β€œExample 4: Workflow Extensions” from the available automations
  4. Observe how the base workflow’s generate_report transition executes first
  5. See the overridden complete_report transition that generates an executive summary
  6. Notice the additional log_results transition with detailed metrics

Configuration Location: You can also view the complete configuration file at src/config/examples/basic/workflow-extension-example.yaml

Complete Example:

include: - core/tools/create-mock.yaml - core/tools/create-chat-message.yaml - core/tools/create-document.yaml - core/tools/switch-target.yaml pipelines: - name: human_in_the_loop_example title: "Example 7: Human-in-the-Loop Workflow" type: root workspace: examples sequence: - workflow: blog_post_review workflows: - name: blog_post_review type: stateMachine transitions: - name: create_draft # Step 1: Generate initial content draft from: start to: draft_created call: - tool: create_mock arguments: input: 'blog post about renewable energy' output: | # The Future of Renewable Energy Renewable energy sources are becoming increasingly important as we work toward a sustainable future. Solar and wind power have seen dramatic cost reductions, making them competitive with traditional fossil fuels. Key benefits include: - Reduced carbon emissions - Energy independence - Long-term cost savings The transition to renewable energy represents one of the most significant opportunities of our time. as: DRAFT_CONTENT - tool: create_chat_message arguments: role: 'assistant' content: 'Draft content has been generated and is ready for your review.' - name: show_approval_form # Step 2: Present draft to user for approval from: draft_created to: waiting_for_approval call: - tool: create_document arguments: document: approval_form content: draft_content: ${ DRAFT_CONTENT } approved: false feedback: "" - name: process_approval # Step 3: Handle user's approval decision from: waiting_for_approval to: - approved - needs_revision when: manual # Wait for user interaction call: - tool: create_mock arguments: input: ${ transition.payload } output: ${ transition.payload.approved } as: USER_DECISION - tool: switch_target arguments: target: "{{#if (eq USER_DECISION true)}}approved{{else}}needs_revision{{/if}}" # Approval path - name: finalize_content # Handle approved content from: approved to: end call: - tool: create_mock arguments: input: ${ DRAFT_CONTENT } output: 'Content published successfully to blog.example.com' as: PUBLISH_RESULT - tool: create_chat_message arguments: role: 'assistant' content: | βœ… Content approved and published! {{ PUBLISH_RESULT }} # Revision path - name: handle_revision # Handle revision requests from: needs_revision to: draft_created # Return to draft creation for revision call: - tool: create_chat_message arguments: role: 'assistant' content: 'πŸ“ Revision requested. Generating updated draft with your feedback...' - tool: create_mock arguments: input: ${ DRAFT_CONTENT } output: | # The Future of Renewable Energy (Revised) Renewable energy sources are rapidly transforming our global energy landscape. Solar and wind power have experienced unprecedented cost reductions, making them not just environmentally responsible but economically superior to traditional fossil fuels. Key benefits include: - Significant reduction in carbon emissions - Enhanced energy independence and security - Substantial long-term cost savings - Job creation in emerging green industries The transition to renewable energy represents the most transformative opportunity of our generation, offering both environmental and economic advantages. as: DRAFT_CONTENT documents: - name: approval_form schema: type: object properties: draft_content: type: string approved: type: boolean feedback: type: string required: - draft_content - approved ui: properties: draft_content: widget: textarea-expand title: "Draft Content" readonly: true approved: widget: switch title: "Approve" feedback: widget: textarea title: "Feedback (optional)" placeholder: "Provide feedback for revisions..." order: - draft_content - feedback - approved buttons: - transition: process_approval label: "Submit Decision" enabledWhen: - waiting_for_approval
Last updated on