Skip to Content
DocumentationBuilding with LoopstackοΈβš™οΈ WorkflowsCreating Workflows

Creating Workflows

Workflows are the core building blocks of automation in Loopstack. They define a sequence of states and transitions that execute tools to accomplish specific tasks, from simple data processing to complex multi-step business processes.

Creating a Workflow

A workflow is created by extending the Workflow base class and decorating it with @BlockConfig. While you can define simple configurations inline, workflows typically use a separate YAML file to define their state machine logic.

Basic Workflow Definition

import { z } from 'zod'; import { Workflow } from '@loopstack/core'; import { BlockConfig, Input } from '@loopstack/shared'; import { AiGenerateText } from '@loopstack/llm'; import { Expose } from 'class-transformer'; @BlockConfig({ imports: [AiGenerateText], properties: z.object({ subject: z.string().default("coffee"), }), configFile: __dirname + '/chat.workflow.yaml', }) export class ChatWorkflow extends Workflow { @Input() @Expose() lastMessage: any; }

Key Components

@BlockConfig Decorator

  • Marks a class as a Loopstack block
  • Links the NestJS service to its YAML configuration via configFile
  • Specifies dependencies (tools) through imports

@Expose() Decorator

  • Makes properties accessible in YAML templates
  • Enables property access via template variables like ${ myData }

@Input() Decorator

  • Allows setting properties from within workflow execution
  • Enables the assign feature in YAML transitions to store results

YAML Config

  • transitions Define the flow of states and the tools executed at each step
  • calls Specifies tool calls triggered in a transition
  • assing Assigns the result to a workflow property and makes it available for later use

Registering the Workflow

Add your workflow as a module provider and import it in your workspace to make it available for execution.

@Module({ imports: [LoopCoreModule, CoreToolsModule], providers: [ InvoiceProcessingWorkflow, // ... other providers ], }) @ModuleFactory(MyModuleFactoryService) export class MyModule {}

Using Your Workflow

Once registered in a workspace, your workflow can be manually executed:

  1. Navigate to your workspace in the Loopstack Studio
  2. Click Run to create a new execution
  3. Select the workflow from the available workflows
Last updated on