AS AgentScopeAPI 手册 / API Reference

Channel

public interface Channel
源码Source 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-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.

  • #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.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:62

config

public ChannelConfig config()

返回路由配置用于此渠道。

Returns the routing configuration for this channel.

返回Returns ChannelConfig
返回ChannelConfig。Returns channel config.
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:65

init

default public void init(Gateway gateway)
default

初始化 Channel 实例。

Called by the gateway bootstrap before #start() to supply the auto-wired Gateway.

参数Parameters
名称Name类型Type说明Description
gatewayGateway网关(类型 `Gateway`)。The gateway.
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:72

start

default public void start()
default

执行启动相关操作。

Connects to the external event source and starts dispatching inbound messages.

源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:78

stop

default public void stop()
default

执行停止相关操作。

Disconnects from the external event source and releases resources.

源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:84

dispatch

public Mono<Msg> dispatch(InboundMessage message)

设置该参数。

Dispatches a fully constructed InboundMessage through routing and returns the agent reply.

参数Parameters
名称Name类型Type说明Description
messageInboundMessage消息(类型 `InboundMessage`)。The message.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:97

dispatchStream

default public Flux<AgentEvent> dispatchStream(InboundMessage message)
default

设置该参数。

Streaming variant of #dispatch(InboundMessage).

参数Parameters
名称Name类型Type说明Description
messageInboundMessage消息(类型 `InboundMessage`)。The message.
返回Returns Flux<AgentEvent>
返回Flux。Returns flux.
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:105–107

deliver

default public void deliver(OutboundAddress address, List<Msg> messages)
default

执行 deliver 方法。

Delivers proactive outbound messages (e.g.

参数Parameters
名称Name类型Type说明Description
addressOutboundAddressaddress(类型 `OutboundAddress`)。the delivery target (peer, thread, account context)
messagesList<Msg>消息列表(类型 `List`)。the messages to deliver
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:120

deliverWithReceipt

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.

参数Parameters
名称Name类型Type说明Description
addressOutboundAddressaddress(类型 `OutboundAddress`)。The address.
messageMsg消息(类型 `Msg`)。The message.
deliveryIdStringdelivery 标识(类型 `String`)。The delivery id.
返回Returns Mono<String>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:125–128

applyRoutingConfig

default public boolean applyRoutingConfig(ChannelConfig newConfig)
default

应用路由配置。

Applies a new routing ChannelConfig (bindings, dmScope, defaultAgentId) without tearing down the channel's transport.

参数Parameters
名称Name类型Type说明Description
newConfigChannelConfig新建配置(类型 `ChannelConfig`)。the new routing configuration to install (channelId must match `#channelId()`)
返回Returns boolean
返回布尔值,表示判断结果。`true` if the config was applied live; `false` if the channel requires a restart to pick up the new config
源码Source io/agentscope/harness/agent/gateway/channel/Channel.java:144–146
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.