Interface Channel
- All Known Implementing Classes:
ChatUiChannel
public interface Channel
Channel adapter — ingests inbound messages from one messaging platform (or a programmatic
caller), routes them through
ChannelRouter to resolve the target agent and session, and
delegates execution to Gateway.
Lifecycle
init(Gateway)— called by the gateway bootstrap to inject the auto-wiredGatewaybefore start-up. Implementations should store the gateway and perform any pre-connection setup. The default is a no-op for channels that receive the gateway at construction time.start()— connects to the external event source (webhook endpoint, long-poll, websocket, etc.) and begins dispatching inbound messages. Programmatic channels may implement this as a no-op.stop()— disconnects and releases resources.
Message dispatch
Implementations callGateway.run(io.agentscope.harness.agent.gateway.MsgContext, java.util.List<io.agentscope.core.message.Msg>) with the MsgContext produced by ChannelRouter.resolveRoute(io.agentscope.harness.agent.gateway.channel.ChannelConfig, io.agentscope.harness.agent.gateway.channel.InboundMessage),
the resolved OutboundAddress, and any caller RuntimeContext carried on InboundMessage.runtimeContext().
The returned Msg reply is delivered back to the originating platform by the channel
adapter.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanapplyRoutingConfig(ChannelConfig newConfig) Applies a new routingChannelConfig(bindings, dmScope, defaultAgentId) without tearing down the channel's transport.Logical identifier for this channel (e.g.config()Returns the routing configuration for this channel.default voiddeliver(OutboundAddress address, List<io.agentscope.core.message.Msg> messages) Delivers proactive outbound messages (e.g. subagent completion announces) to this channel's transport.default reactor.core.publisher.Mono<String>deliverWithReceipt(OutboundAddress address, io.agentscope.core.message.Msg message, String deliveryId) Delivers one durable notification and returns the provider message ID, not a local ack.reactor.core.publisher.Mono<io.agentscope.core.message.Msg>dispatch(InboundMessage message) Dispatches a fully constructedInboundMessagethrough routing and returns the agent reply.default reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>dispatchStream(InboundMessage message) Streaming variant ofdispatch(InboundMessage).default voiddefault voidstart()Connects to the external event source and starts dispatching inbound messages.default voidstop()Disconnects from the external event source and releases resources.
-
Method Details
-
channelId
String channelId()Logical identifier for this channel (e.g."chatui","slack","discord"). Must matchChannelConfig.channelId(). -
config
ChannelConfig config()Returns the routing configuration for this channel. -
init
-
start
default void start()Connects to the external event source and starts dispatching inbound messages. Programmatic channels may make this a no-op. -
stop
default void stop()Disconnects from the external event source and releases resources. Programmatic channels may make this a no-op. -
dispatch
Dispatches a fully constructedInboundMessagethrough routing and returns the agent reply. The channel implementation is responsible for:- Calling
ChannelRouter.resolveRoute(io.agentscope.harness.agent.gateway.channel.ChannelConfig, io.agentscope.harness.agent.gateway.channel.InboundMessage)to obtain aRouteResult(which includes theOutboundAddressfor reply routing) - Passing the
RouteResult.context(), messages, andRouteResult.outboundAddress()toGateway.run(io.agentscope.harness.agent.gateway.MsgContext, java.util.List<io.agentscope.core.message.Msg>)
- Calling
-
dispatchStream
default reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> dispatchStream(InboundMessage message) Streaming variant ofdispatch(InboundMessage). Returns fine-grainedAgentEvents instead of a single reply.The default delegates to
Gateway.runStream(io.agentscope.harness.agent.gateway.MsgContext, java.util.List<io.agentscope.core.message.Msg>)with the resolved route. -
deliver
Delivers proactive outbound messages (e.g. subagent completion announces) to this channel's transport. Called by the gateway when an agent produces a reply that needs to be pushed to the originating channel/peer rather than returned synchronously.The default implementation is a no-op, suitable for pull-based channels that do not support proactive push.
- Parameters:
address- the delivery target (peer, thread, account context)messages- the messages to deliver
-
deliverWithReceipt
default reactor.core.publisher.Mono<String> deliverWithReceipt(OutboundAddress address, io.agentscope.core.message.Msg message, String deliveryId) Delivers one durable notification and returns the provider message ID, not a local ack. Unsupported transports fail explicitly so callers can keep the notification pending. -
applyRoutingConfig
Applies a new routingChannelConfig(bindings, dmScope, defaultAgentId) without tearing down the channel's transport. Implementations that hold theirconfig()in a mutable / volatile reference can override this to support hot reload of bindings.The default implementation returns
falseto signal that this channel does not support live config swap. Returningtruemeans the swap was applied and subsequent inbound messages will route under the new config.- Parameters:
newConfig- the new routing configuration to install (channelId must matchchannelId())- Returns:
trueif the config was applied live;falseif the channel requires a restart to pick up the new config
-