π§© Basic Concepts
This section establishes the technical foundation to building automations with Loopstack you understanding how AI workflows are executed.
Overview
Loopstack automations are build using two essential contepts:
Blocks- NestJS services that represent the building blocks of every automation.YAML Configs- Configuration files to define block specific behaviour.
Block Types
There are different Block types, each with specific functionality
Workspaces- Organizational containers that group related automations and dataWorkflows- State machines that define business processes, call tools and create documentsTools- Functional units that perform specific tasksDocuments- Structured data objects that store and display information
Workspaces
Workspaces contain pipelines, which in turn contain workflows. They serve as the top-level organizational unit in Loopstack.
Purpose: Provide organizational structure for your automations.
- Create logical groupings of related automations
- Control access and permissions at a high level
TypeScript
@Injectable()
@BlockConfig({
config: {
title: 'Examples Workspace'
},
})
export class ExampleWorkspace extends WorkspaceBase {
@Workflow() chatWorkflow: ChatWorkflow;
@Workflow() meetingNotes: MeetingNotesWorkflow;
}Workflows
Workflows are automation entities that can be executed. They use tools to perform custom operations. Workflows control the flow of a business process and manage its state.
Purpose: Define specific business processes as state machines with transitions between states.
- Model processes with states (places) and transitions
- Execute tools to perform actions
- Handle errors and decision points
- Manage the flow of data through the process
- Maintain a custom state
- Define Arguments the workflow can be executed with
TypeScript
@Injectable()
// Include an yaml configuration file
@BlockConfig({
configFile: __dirname + '/prompt.workflow.yaml',
})
// Define arguments
@WithArguments(z.object({
language: z.string().default("python")
})
// Define the workflow state
@WithState(z.object({
code: z.string().optional()
})
export class PromptWorkflow extends WorkflowBase {
// Inject tools and documents used in the workflow
@Tool() aiGenerateText: AiGenerateText;
@Tool() createDocument: CreateDocument;
@Document(): fileDocument: FileDocument;
}Execution Process:
- Workflow always starts in
startstate - Finds transition with matching
fromstate - Executes specified tools with provided arguments
- Exports results to variables if specified
- Moves to
tostate - Repeats until reaching terminal
endstate
Tools
Tools are called by workflow transitions of from other tools. They execute custom business logic, create or modify documents or interact with outside systems.
Purpose: Perform specific actions or operations within workflows.
- Execute defined operations (API calls, data processing, etc.)
- Accept input arguments
- Create documents displayed in the Loopstack Studio
- Call other tools
TypeScript
@Injectable()
@BlockConfig({
config: {
description: 'Calculate the sum of two values.',
},
})
@WithArguments(z.object({
a: z.number(),
b: z.number()
}))
export class MathSumTool extends ToolBase {
async execute(args: { a: number; b: number; }): Promise<ToolCallResult> {
const sum = args.a + args.b;
return {
data: sum
};
}
}Documents
Documents are created and used by workflows and tools. They can store data persistently and provide configuration for interactive forms for user input in the Loopstack Studio.
Purpose: Store, display, and collect data throughout the automation process.
- Define data schemas for validation
- Provide UI components for user interaction
- Store information between workflow steps
- Serve as inputs and outputs for tools
TypeScript
@Injectable()
@BlockConfig({
configFile: __dirname + '/file-analysis-result.document.yaml',
})
@WithArguments(z.object({
recommendations: z.array(
z.object({
description: z.string(),
example: z.string(),
}),
),
}))
export class FileAnalysisResult extends DocumentBase {}How Components Work Together
Letβs examine how these components interact in a typical automation:
- A workspace provides organizational structure
- The workflows gets executed by a user or internal process
- Each workflow consists of transitions between states
- Transitions call tools to perform actions
- Tools create or modify documents to store and display data
Example Flow
State Persistence
Workflow state is automatically persisted, enabling:
- Execution resume after interruptions
- Human in the loop interaction
- Audit trails of workflow progress
- Historical execution analysis
All other Blocks are not persistent and will be re-executed on every automation run.