Skip to content

@anvia/channel-agent ​

@anvia/channel-agent connects one Channel adapter to one Anvia agent executor, owning everything between a platform event and a delivered reply: filtering, conversation serialization, prompt preparation, streaming edits, long-message splitting, and paused interactions.

Complete Install and setup first if you have not built an agent yet; start with Your first agent.

Create the service ​

createChannelAgent() returns a ChannelAgentService that you start yourself:

ts
import { createChannelAgent } from '@anvia/channel-agent'

const service = createChannelAgent({
  channel,
  agent,
  streaming: {
    placeholder: 'Thinking…',
    editIntervalMs: 750,
  },
  onError(error, context) {
    console.error(context.stage, error)
  },
})

await service.start()

The service starts the adapter, serializes runs inside one conversation and thread, streams text through message edits, splits long final output, and stops the adapter when service.stop() is called. Do not also call channel.start(); the service owns the adapter lifecycle.

Use serveChannelAgent() when a small executable wants an already-started service:

ts
import { serveChannelAgent } from '@anvia/channel-agent'

const service = await serveChannelAgent({ channel, agent })

Both functions return a ChannelAgentService, and both must be stopped.

Configuration options ​

OptionPurpose
channelThe adapter whose lifecycle the service owns
agentExecutor with generate(), stream(), and optional resume(); an Anvia Agent satisfies it
shouldHandleMessage filter; defaults to direct messages and mentions
createPromptPrompt builder; defaults to channelMessagePrompt() under the multimodal policy
createSessionMemory scope factory; defaults to sender-isolated sessions
renderOutcomeFinal response renderer; returns a string or ChannelMessage
streamingenabled, placeholder, editIntervalMs
acknowledgeAcceptance/completion reactions: a reaction string, full options, or false
commandsSlash-command handling: true, per-name options, or false (default)
multimodalAttachment limits, or false to reject file input
interactionsStore, rendering, parsing, timeout, and cancel behavior, or false to disable
errorMessageFailure reply shown to users, or false to send nothing
emptyResponseMessageReply when an outcome carries no visible text
onErrorError observer receiving (error, { stage, event })

Continue with ​

Built for Anvia.