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
TypeScript
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
assignfeature in YAML transitions to store results
YAML Config
transitionsDefine the flow of states and the tools executed at each stepcallsSpecifies tool calls triggered in a transitionassingAssigns 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.
my-module.ts
@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:
- Navigate to your workspace in the Loopstack Studio
- Click Run to create a new execution
- Select the workflow from the available workflows
Last updated on