Skip to content

@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”

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.
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.