Skip to content

@ChannelRole & @Channel

The @ChannelRole and @Channel decorators (channels/*.channel.ts) power human-in-the-loop approvals and external questions in AGBoss. A @Tool declares which abstract @ChannelRole gates its execution (@Tool({ channel: RefundApprovalChannel })), while @Application({ providers }) binds the concrete @Channel implementation (such as Slack, PagerDuty, or email) by class inheritance — and tests can swap in AutoApproveChannel or AutoRejectChannel without touching tool code.

Complete @ChannelRole and @Channel example with two-phase app.resume()

Section titled “Complete @ChannelRole and @Channel example with two-phase app.resume()”

What options do @ChannelRole and @Channel accept?

Section titled “What options do @ChannelRole and @Channel accept?”
Decorator Option Type Required Description
@ChannelRole name string Yes Unique kebab-case identifier ending with -channel ("refund-approval-channel").
@ChannelRole description string Yes Describes what this channel role approves or asks.
@ChannelRole answeredBy PauseAnswerer.Channel | PauseAnswerer.ThreadOwner Yes Who is authorized to call app.resume(): the external channel (Channel) or the thread’s original ownerId (ThreadOwner).
@ChannelRole approves DtoClass Yes* Input DTO class of the @Tools this role approves (*mutually exclusive with ask / answer).
@ChannelRole ask & answer DtoClass Yes* Question and answer DTO classes for workflow-level questions (*mutually exclusive with approves).
@ChannelRole replyInterpreter Class No Optional interpreter class that parses free-text user replies into the typed answer DTO.
@Channel name string Yes Unique kebab-case identifier for the concrete channel implementation ("slack-refund-approval-channel").
@Channel description string Yes Describes how this implementation delivers the prompt (e.g., Slack webhook, CLI terminal).
@Channel deps readonly Token[] No Constructor dependencies (ExecutionContext, @Injectable services) injected into the channel.
Section titled “What related entities work with @ChannelRole and @Channel?”
Related Entity Import Path Purpose
ChannelOf<Role> & ChannelAsk<Role> "@agboss/core" Base class extended by @ChannelRole and typed payload passed to send(ask) (ask.pauseId, ask.value.arguments).
ChannelWithdrawal<Role> & PauseResolution "@agboss/core" Payload passed to optional withdraw(withdrawal) when a paused branch is cancelled due to FailFast / quorum Surplus (PauseResolution.Withdrawn) or app.cancel (PauseResolution.Cancelled).
ChannelOutcome (awaitReply(), decided(...)) "@agboss/core" Return value of send(ask): either suspends the branch out-of-process (awaitReply()) or resolves inline (decided({ approved })).
PauseAnswerer (Channel, ThreadOwner) "@agboss/core" Enforces who is allowed to resume the pause (answeredBy vs ownerId).
app.resume({ pauseId, decision }, options) "@agboss/core" Two-phase atomic resume: transitions Pending → Resolved via CAS in PausedExecutionRepository before acquiring the execution-tree lease.
AutoApproveChannel, AutoRejectChannel, TerminalUserChannel "@agboss/core" Built-in channel implementations for automated tests and interactive CLI sessions.
PausedExecutionRepository & SqlitePausedExecutionRepository "@agboss/core" Durable store persisting PendingPause records across restarts and worker pods.