Channel
public interface Channel
io/agentscope/harness/agent/gateway/channel/Channel.java:56–147定义渠道契约的接口。位于 io.agentscope.harness.agent.gateway.channel 包。核心成员包括 channelId、config、init、start、stop、dispatch。
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 call Gateway#run with the io.agentscope.harness.agent.gateway.MsgContext produced by ChannelRouter#resolveRoute,
the resolved OutboundAddress, and any caller io.agentscope.core.agent.RuntimeContext carried on InboundMessage#runtimeContext().
The returned Msg reply is delivered back to the originating platform by the channel
adapter.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String channelId() | 返回渠道标识。 Logical identifier for this channel (e.g. |
public ChannelConfig config() | 返回路由配置用于此渠道。 Returns the routing configuration for this channel. |
default public void init(Gateway gateway)default | 初始化 `Channel` 实例。 Called by the gateway bootstrap before `#start()` to supply the auto-wired
`Gateway`. |
default public void start()default | 执行启动相关操作。 Connects to the external event source and starts dispatching inbound messages. |
default public void stop()default | 执行停止相关操作。 Disconnects from the external event source and releases resources. |
public Mono<Msg> dispatch(InboundMessage message) | 设置该参数。 Dispatches a fully constructed `InboundMessage` through routing and returns the agent
reply. |
default public Flux<AgentEvent> dispatchStream(InboundMessage message)default | 设置该参数。 Streaming variant of `#dispatch(InboundMessage)`. |
default public void deliver(OutboundAddress address, List<Msg> messages)default | 执行 `deliver` 方法。 Delivers proactive outbound messages (e.g. |
default public Mono<String> deliverWithReceipt(OutboundAddress address, Msg message, String deliveryId)default | 执行 `deliverWithReceipt` 方法。 Delivers one durable notification and returns the provider message ID, not a local ack. |
default public boolean applyRoutingConfig(ChannelConfig newConfig)default | 应用路由配置。 Applies a new routing `ChannelConfig` (bindings, dmScope, defaultAgentId) without
tearing down the channel's transport. |
方法详情Method Detail
channelId
public String channelId()
返回渠道标识。
Logical identifier for this channel (e.g.
Stringio/agentscope/harness/agent/gateway/channel/Channel.java:62config
public ChannelConfig config()
返回路由配置用于此渠道。
Returns the routing configuration for this channel.
ChannelConfigio/agentscope/harness/agent/gateway/channel/Channel.java:65init
default public void init(Gateway gateway)
初始化 Channel 实例。
Called by the gateway bootstrap before #start() to supply the auto-wired Gateway.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
gateway | Gateway | 网关(类型 `Gateway`)。The gateway. |
io/agentscope/harness/agent/gateway/channel/Channel.java:72start
default public void start()
执行启动相关操作。
Connects to the external event source and starts dispatching inbound messages.
io/agentscope/harness/agent/gateway/channel/Channel.java:78stop
default public void stop()
执行停止相关操作。
Disconnects from the external event source and releases resources.
io/agentscope/harness/agent/gateway/channel/Channel.java:84dispatch
public Mono<Msg> dispatch(InboundMessage message)
设置该参数。
Dispatches a fully constructed InboundMessage through routing and returns the agent reply.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
message | InboundMessage | 消息(类型 `InboundMessage`)。The message. |
Mono<Msg>io/agentscope/harness/agent/gateway/channel/Channel.java:97dispatchStream
default public Flux<AgentEvent> dispatchStream(InboundMessage message)
设置该参数。
Streaming variant of #dispatch(InboundMessage).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
message | InboundMessage | 消息(类型 `InboundMessage`)。The message. |
Flux<AgentEvent>io/agentscope/harness/agent/gateway/channel/Channel.java:105–107deliver
default public void deliver(OutboundAddress address, List<Msg> messages)
执行 deliver 方法。
Delivers proactive outbound messages (e.g.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
address | OutboundAddress | address(类型 `OutboundAddress`)。the delivery target (peer, thread, account context) |
messages | List<Msg> | 消息列表(类型 `List`)。the messages to deliver |
io/agentscope/harness/agent/gateway/channel/Channel.java:120deliverWithReceipt
default public Mono<String> deliverWithReceipt(OutboundAddress address, Msg message, String deliveryId)
执行 deliverWithReceipt 方法。
Delivers one durable notification and returns the provider message ID, not a local ack.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
address | OutboundAddress | address(类型 `OutboundAddress`)。The address. |
message | Msg | 消息(类型 `Msg`)。The message. |
deliveryId | String | delivery 标识(类型 `String`)。The delivery id. |
Mono<String>io/agentscope/harness/agent/gateway/channel/Channel.java:125–128applyRoutingConfig
default public boolean applyRoutingConfig(ChannelConfig newConfig)
应用路由配置。
Applies a new routing ChannelConfig (bindings, dmScope, defaultAgentId) without tearing down the channel's transport.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
newConfig | ChannelConfig | 新建配置(类型 `ChannelConfig`)。the new routing configuration to install (channelId must match `#channelId()`) |
booleanio/agentscope/harness/agent/gateway/channel/Channel.java:144–146