
Security News
Packagist Urges Immediate Composer Update After GitHub Actions Token Leak
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.
@loopstack/dynamic-routing-example-workflow
Advanced tools
A workflow demonstrating how to create dynamic routing an a workflow
A module for the Loopstack AI automation framework.
This module provides an example workflow demonstrating how to implement conditional routing based on runtime values using guards and transition priorities.
The Dynamic Routing Example Workflow shows how to create branching logic in workflows using @Guard decorators and @Transition priorities. It demonstrates how to route execution through different paths based on input values.
By using this workflow as a reference, you'll learn how to:
z.object() for typed input arguments@Guard('methodName') to conditionally gate transitionspriority optionThis example is useful for developers building workflows that require decision trees, validation flows, or any logic that branches based on data.
See SETUP.md for installation and setup instructions.
The workflow extends BaseWorkflow<TArgs> with a typed argument object. The schema is defined in the @Workflow decorator using Zod:
@Workflow({
uiConfig: __dirname + '/dynamic-routing-example.ui.yaml',
schema: z
.object({
value: z.number().default(150),
})
.strict(),
})
export class DynamicRoutingExampleWorkflow extends BaseWorkflow<{ value: number }> {
value!: number;
}
The @Initial transition receives the validated input as a method argument. Store it as an instance property for use in guards and later transitions:
@Initial({ to: 'prepared' })
async createMockData(args: { value: number }) {
this.value = args.value;
await this.repository.save(MessageDocument, {
role: 'assistant',
content: `Analysing value = ${this.value}`,
});
}
A guard is a method that returns a boolean. It determines whether a transition should be taken. Reference it by name in the @Guard decorator:
@Transition({ from: 'prepared', to: 'placeA', priority: 10 })
@Guard('isAbove100')
routeToPlaceA() {}
isAbove100() {
return this.value > 100;
}
When the workflow reaches the prepared state, it evaluates guards on all transitions from that state. If isAbove100() returns true, the workflow moves to placeA.
When multiple transitions share the same from state, priority controls evaluation order (higher priority is evaluated first). The first transition whose guard passes (or that has no guard) is taken:
// Evaluated first (priority: 10) -- taken if value > 100
@Transition({ from: 'prepared', to: 'placeA', priority: 10 })
@Guard('isAbove100')
routeToPlaceA() {}
// Evaluated second (no priority = default) -- fallback route
@Transition({ from: 'prepared', to: 'placeB' })
routeToPlaceB() {}
A transition without a @Guard always matches, acting as a fallback.
Chain conditional transitions to create decision trees. After reaching placeA, a second level of guards routes further:
@Transition({ from: 'placeA', to: 'placeC', priority: 10 })
@Guard('isAbove200')
routeToPlaceC() {}
isAbove200() {
return this.value > 200;
}
@Transition({ from: 'placeA', to: 'placeD' })
routeToPlaceD() {}
The workflow routes through different states based on the input value:
import { z } from 'zod';
import { BaseWorkflow, Final, Guard, Initial, Transition, Workflow } from '@loopstack/common';
import { MessageDocument } from '@loopstack/common';
@Workflow({
uiConfig: __dirname + '/dynamic-routing-example.ui.yaml',
schema: z
.object({
value: z.number().default(150),
})
.strict(),
})
export class DynamicRoutingExampleWorkflow extends BaseWorkflow<{ value: number }> {
value!: number;
@Initial({ to: 'prepared' })
async createMockData(args: { value: number }) {
this.value = args.value;
await this.repository.save(MessageDocument, {
role: 'assistant',
content: `Analysing value = ${this.value}`,
});
}
@Transition({ from: 'prepared', to: 'placeA', priority: 10 })
@Guard('isAbove100')
routeToPlaceA() {}
isAbove100() {
return this.value > 100;
}
@Transition({ from: 'prepared', to: 'placeB' })
routeToPlaceB() {}
@Transition({ from: 'placeA', to: 'placeC', priority: 10 })
@Guard('isAbove200')
routeToPlaceC() {}
isAbove200() {
return this.value > 200;
}
@Transition({ from: 'placeA', to: 'placeD' })
routeToPlaceD() {}
@Final({ from: 'placeB' })
async showMessagePlaceB() {
await this.repository.save(MessageDocument, {
role: 'assistant',
content: 'Value is less or equal 100',
});
}
@Final({ from: 'placeC' })
async showMessagePlaceC() {
await this.repository.save(MessageDocument, {
role: 'assistant',
content: 'Value is greater than 200',
});
}
@Final({ from: 'placeD' })
async showMessagePlaceD() {
await this.repository.save(MessageDocument, {
role: 'assistant',
content: 'Value is less or equal 200, but greater than 100',
});
}
}
This workflow uses the following Loopstack modules:
@loopstack/common - Base classes, decorators, and guards@loopstack/common - Provides MessageDocument for chat messagesAuthor: Jakob Klippel
License: MIT
FAQs
A workflow demonstrating how to create dynamic routing an a workflow
We found that @loopstack/dynamic-routing-example-workflow demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.

Research
GemStuffer abuses RubyGems as an exfiltration channel, packaging scraped UK council portal data into junk gems published from new accounts.

Company News
Socket was named to the Rising in Cyber 2026 list, recognizing 30 private cybersecurity startups selected by CISOs and security executives.