ChannelRouter
public final class ChannelRouter
io/agentscope/harness/agent/gateway/channel/ChannelRouter.java:62–222渠道路由器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.gateway.channel 包。核心成员包括 resolveRoute、ChannelRouter。
Resolves the target agentId and stable MsgContext for an InboundMessage
by evaluating ChannelBinding rules in deterministic priority order.
Binding evaluation tiers (highest to lowest priority)
-
explicit —
InboundMessage#preferredAgentId()short-circuit when the caller has already nominated a specific agent. Bindings are still consulted to determinesessionScopeand outbound addressing. -
peer — exact
Peer#key()match (e.g."direct:u_42") -
peer.parent — exact match on the thread-parent peer's key
-
guild + roles — guild id matches AND sender holds at least one of the binding's roles
-
guild — guild id matches (no role constraint)
-
team — team id matches
-
account — account id matches
-
channel — channel id matches
-
default —
ChannelConfig#defaultAgentId()orglobalDefaultAgentId
Within each tier the first binding in ChannelConfig#bindings() list order that
matches wins.
Session key construction (MsgContext)
After resolving agentId, the router builds a MsgContext whose MsgContext#canonicalKey() produces a stable session key:
-
DM +
DmScope#MAIN—channelfield only; all DMs share one session -
DM + other scopes — room = peerId (optionally group = accountId)
-
Thread — room = parentPeer id, threadId = peer id
-
Non-DM channel/group — room = peer id, group = guild
The resolved agentId is always included in MsgContext#extra() under key "agentId" so that the gateway can pick the correct agent from its registry.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ChannelRouter(String globalDefaultAgentId) | 初始化 `ChannelRouter` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public RouteResult resolveRoute(ChannelConfig config, InboundMessage msg) | 解析路由。 Evaluates bindings in priority order and returns a `RouteResult` ready for gateway
execution. |
构造器详情Constructor Detail
ChannelRouter
public ChannelRouter(String globalDefaultAgentId)
初始化 ChannelRouter 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
globalDefaultAgentId | String | global 默认智能体标识(类型 `String`)。fallback agent id when no binding and no channel-level default match; typically the id of the agent registered via `io.agentscope.harness.agent.gateway.Gateway#bindMainAgent` |
io/agentscope/harness/agent/gateway/channel/ChannelRouter.java:71–73方法详情Method Detail
resolveRoute
public RouteResult resolveRoute(ChannelConfig config, InboundMessage msg)
解析路由。
Evaluates bindings in priority order and returns a RouteResult ready for gateway execution.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
config | ChannelConfig | 配置对象(类型 `ChannelConfig`)。channel-level routing config (bindings + dmScope + channel default agent) |
msg | InboundMessage | 消息(类型 `InboundMessage`)。normalized inbound message |
RouteResultio/agentscope/harness/agent/gateway/channel/ChannelRouter.java:82–118