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

  1. init(Gateway) — called by the gateway bootstrap to inject the auto-wired Gateway before 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.
  2. 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.
  3. stop() — disconnects and releases resources.

Message dispatch

Implementations call Gateway.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 Type
    Method
    Description
    default boolean
    Applies a new routing ChannelConfig (bindings, dmScope, defaultAgentId) without tearing down the channel's transport.
    Logical identifier for this channel (e.g.
    Returns the routing configuration for this channel.
    default void
    deliver(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>
    Dispatches a fully constructed InboundMessage through routing and returns the agent reply.
    default reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>
    Streaming variant of dispatch(InboundMessage).
    default void
    init(Gateway gateway)
    Called by the gateway bootstrap before start() to supply the auto-wired Gateway.
    default void
    Connects to the external event source and starts dispatching inbound messages.
    default void
    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 match ChannelConfig.channelId().
    • config

      ChannelConfig config()
      Returns the routing configuration for this channel.
    • init

      default void init(Gateway gateway)
      Called by the gateway bootstrap before start() to supply the auto-wired Gateway. Implementations that need a gateway but do not receive it at construction time should override this method. The default is a no-op.
    • 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

      reactor.core.publisher.Mono<io.agentscope.core.message.Msg> dispatch(InboundMessage message)
    • dispatchStream

      default reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> dispatchStream(InboundMessage message)
      Streaming variant of dispatch(InboundMessage). Returns fine-grained AgentEvents 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

      default void deliver(OutboundAddress address, List<io.agentscope.core.message.Msg> messages)
      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

      default boolean applyRoutingConfig(ChannelConfig newConfig)
      Applies a new routing ChannelConfig (bindings, dmScope, defaultAgentId) without tearing down the channel's transport. Implementations that hold their config() in a mutable / volatile reference can override this to support hot reload of bindings.

      The default implementation returns false to signal that this channel does not support live config swap. Returning true means the swap was applied and subsequent inbound messages will route under the new config.

      Parameters:
      newConfig - the new routing configuration to install (channelId must match channelId())
      Returns:
      true if the config was applied live; false if the channel requires a restart to pick up the new config