@Workflow
The @Workflow decorator defines a typed state graph (*.workflow.ts) in AGBoss using HarnessDSL (HDSL) — our declarative graph syntax. Every workflow declares its name, version, and flow array of paths built with start(), agent(), router(), action(), workflow(), route(), and caseOf(), enforcing strictly one chained method call per line (@stylistic/newline-per-chained-call) and compile-time Path Scope verification.
Complete @Workflow example with all capabilities
Section titled “Complete @Workflow example with all capabilities”import { StepFailedError, VisitsLimitExceededError, Workflow, action, agent, caseOf, listOf, oneOf, route, start, toAction,} from "@agboss/core";import { Reasoning, ReasoningEffort } from "@agboss/core/models";import { seconds } from "@agboss/core/units";import { AuditArbiter, AuditTrailGuardrail, ComplianceCheckWorkflow, DirectoryMcpServer, DrafterAgent, EditorAgent, LegalAuditAgent, NotifyRecruiterAction, OfferCompaction, OfferFailedWorkflowFinish, OfferFormattingService, OfferPiiPolicy, OfferWorkflowFinish, OfferWorkflowStart, ReviewerAgent, SecurityAuditAgent, SendOfferAction, TriageRouter,} from "../offer.components.js";import { AuditVerdictDto, CandidateInputDto, ChangesRequestedDto, ComplianceReportDto, DraftApprovedDto, OfferDraftDto,} from "../dto/offer-negotiation.dto.js";
@Workflow({ name: "offer-workflow", version: "1.0.0", maxSteps: 18, maxDepth: 3, maxConcurrentExecutions: 8, providers: [OfferFormattingService], mcp: [DirectoryMcpServer], piiPolicies: [OfferPiiPolicy], guardrails: [AuditTrailGuardrail], compaction: OfferCompaction, uncompactedTurns: 8, promptVariables: { companyName: "Acme Corp", }, defaults: { models: { temperature: 0.2, reasoning: Reasoning.on({ effort: ReasoningEffort.Low }), }, router: { model: "typesafe/jev-1.13", }, tools: { maxToolCalls: 6, }, }, flow: [ start(OfferWorkflowStart) .returns(CandidateInputDto) .toRouter(TriageRouter) .chooseOne( route(DrafterAgent) .returns(OfferDraftDto) .toAgent(ReviewerAgent), route(OfferFailedWorkflowFinish), ),
agent(ReviewerAgent) .onError( VisitsLimitExceededError, toAction(NotifyRecruiterAction), ) .returns(oneOf(DraftApprovedDto, ChangesRequestedDto)) .switch( caseOf(DraftApprovedDto) .toWorkflow(ComplianceCheckWorkflow) .returns(ComplianceReportDto) .toParallelAgents(SecurityAuditAgent, LegalAuditAgent) .acceptedBy(AuditArbiter) .joinQuorum({ min: 2, deadline: seconds(15) }) .onJoinError( StepFailedError, toAction(NotifyRecruiterAction), ) .returns(listOf(AuditVerdictDto)) .toAction(SendOfferAction) .toFinish(OfferWorkflowFinish), caseOf(ChangesRequestedDto, { about: OfferDraftDto }) .toAgent(EditorAgent) .returns(OfferDraftDto) .toAgent(ReviewerAgent), ),
action(NotifyRecruiterAction) .toFinish(OfferFailedWorkflowFinish), ],})export class OfferWorkflow {}import { Integer, Text } from "@agboss/core/dto";
export class CandidateInputDto { @Text() role!: string; @Text() region!: string;}
export class OfferDraftDto { @Text() summary!: string; @Integer() baseUsd!: number;}
export class DraftApprovedDto { @Text() signedBy!: string;}
export class ChangesRequestedDto { @Text() critique!: string;}
export class ComplianceReportDto { @Text() status!: string;}
export class AuditVerdictDto { @Text() auditor!: string;}import { expect } from "vitest";import { ExecutionStatus } from "@agboss/core";import { replyWith, routeTo, testWith } from "@agboss/core/testing";import { OfferApplication } from "../src/offer.application.js";import { ComplianceAgent, DrafterAgent, LegalAuditAgent, OfferWorkflowStart, ReviewerAgent, SecurityAuditAgent, TriageRouter,} from "../src/offer.components.js";import { AuditVerdictDto, ComplianceReportDto, DraftApprovedDto, OfferDraftDto,} from "../src/dto/offer-negotiation.dto.js";
const test = testWith(OfferApplication);
test("runs OfferWorkflow through review loop and quorum to approval", async ({ app, mockLlm }) => { mockLlm(TriageRouter).thenReturn(routeTo(DrafterAgent)); mockLlm(DrafterAgent).thenReturn( replyWith(OfferDraftDto, { summary: "Staff TS Engineer", baseUsd: 215_000 }), ); mockLlm(ReviewerAgent).thenReturn( replyWith(DraftApprovedDto, { signedBy: "comp-committee" }), ); mockLlm(ComplianceAgent).thenReturn( replyWith(ComplianceReportDto, { status: "passed" }), ); mockLlm(SecurityAuditAgent).thenReturn( replyWith(AuditVerdictDto, { auditor: "sec-1" }), ); mockLlm(LegalAuditAgent).thenReturn( replyWith(AuditVerdictDto, { auditor: "legal-1" }), ); const res = await app.execute(OfferWorkflowStart, { role: "Staff TS", region: "EU" }); expect(res.status).toBe(ExecutionStatus.Finished);});What options does @Workflow accept?
Section titled “What options does @Workflow accept?”Every @Workflow class name ends with Workflow and its name option ends with -workflow:
| Option | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Unique kebab-case identifier ending with -workflow (e.g., "offer-workflow"). |
version |
string |
Yes | Behavior version of the workflow ("1.0.0"), checked when resuming paused executions across deploys. |
flow |
readonly FlowPath[] |
Yes | List of paths starting with start(), agent(), router(), action(), or workflow(). |
maxSteps |
number |
No | Maximum agent and router visits per execution; defaults to (agents + routers) * 3. |
maxDepth |
number |
No | Maximum nesting depth for child workflows and ThisWorkflow recursive calls (soft stop omitting the recursion tool at depth === maxDepth for model launches; throws DepthLimitExceededError for deterministic launches). |
maxConcurrentExecutions |
number |
No | Maximum concurrent executions across the root workflow and all child/recursive subtrees (10 by default). |
defaults |
WorkflowDefaults |
No | Workflow-level defaults for models, router, guardrail, tools, and flow.maxPathDepth. |
providers |
readonly Provider[] |
No | Workflow-scoped @Injectable services, @A2AAgent clients, or provide(TOKEN, value) bindings. |
mcp |
readonly Class[] |
No | @McpServer classes whose tools are used by agents in this workflow. |
piiPolicies |
readonly Class[] |
No | Additional @PiiPolicy classes applied to all agents and routers in this workflow. |
guardrails |
readonly Class[] |
No | @InputGuardrail and @OutputGuardrail classes applied across all agents and model routers in this workflow. |
excludeGuardrails |
readonly Class[] |
No | Inherited application guardrails exempted for this workflow. |
toolInterceptors |
readonly Class[] |
No | @ToolInterceptor classes applied across all @Tool and @McpTool invocations in this workflow. |
excludeToolInterceptors |
readonly Class[] |
No | Inherited application @ToolInterceptor classes exempted for this workflow. |
compaction |
Class |
No | @Compaction class summarizing conversation turns older than uncompactedTurns. |
uncompactedTurns |
number | TurnLimit |
No | Number of recent finished turns shown in full to agents and model routers in this workflow (5 by default, or TurnLimit.ALL). |
promptVariables |
Readonly<Record<string, string>> |
No | Static {{variable}} substitutions available to every prompt in the workflow. |
What HarnessDSL (HDSL) flow functions and related entities work with @Workflow?
Section titled “What HarnessDSL (HDSL) flow functions and related entities work with @Workflow?”| Builder / Entity | Import Path | Description |
|---|---|---|
start(StartClass) |
"@agboss/core" |
Begins a root path from a @WorkflowStart class. |
agent(AgentClass), router(RouterClass), action(ActionClass), workflow(ChildWorkflow) |
"@agboss/core" |
Begins a shared continuation path from a node reached by multiple upstream paths. |
.returns(Dto, { about? }) |
Flow chain | Declares one output DTO added to Path Scope; { about: TargetDto } binds review verdicts to the artifact they judge. |
.toAgent(A), .toAction(A), .toRouter(R), .toWorkflow(W, { placement? }), .toFinish(F) |
Flow chain | Transitions execution to the next node after verifying its input fields exist in Path Scope; .toWorkflow and route(W, { placement? }) accept placement: ChildPlacement.ParentInstance | ChildPlacement.AnyInstance. |
.chooseOne(route(Target, { placement? })...) |
Flow chain | Branches after .toRouter(R) to exactly one chosen route target. |
.switch(caseOf(Dto, { about? })...) |
Flow chain | Branches deterministically based on which union output variant (oneOf(...)) the preceding node produced. |
.toParallelAgents(...), .toParallelWorkflows(W, { maxItems?, maxConcurrency?, placement? }) |
Flow chain | Fans out across multiple agents, { agent, count } copies, or { agent, each: ListDto } items with { maxItems, maxConcurrency, placement: ChildPlacement.AnyInstance }. |
.join(), .joinQuorum({ min, max?, deadline? }), .joinQuorumGroups(...) |
Flow chain | Joins all parallel branches or resolves early as soon as a quorum verified by .acceptedBy(Arbiter) is reached. |
.onError(ErrorClass, sidePath), .onJoinError(ErrorClass, sidePath) |
Flow chain | Catches step or parallel-join failures (StepFailedError, VisitsLimitExceededError, QuorumNotReachedError) onto a typed recovery path. |
ThisWorkflow |
"@agboss/core" |
Sentinel target passed to .toWorkflow(ThisWorkflow) or .toParallelWorkflows(ThisWorkflow) for bounded self-recursion. |
oneOf(A, B), listOf(Dto), optional(Dto), historyOf(Dto, { limit }) |
"@agboss/core" |
Path Scope input/output shape wrappers used on component input and output declarations. |