HarnessGateway
public final class HarnessGateway implements Gateway, WakeupDispatcher.WakeupTarget
io/agentscope/harness/agent/gateway/HarnessGateway.java:62–847Harness 网关,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.gateway 包,实现 Gateway、WakeupDispatcher.WakeupTarget。核心成员包括 create、messageBus、channelManager、setRuntimeContextResolver、getRuntimeContextResolver、bindMainAgent。
Default Gateway implementation. Routes inbound turns by MsgContext#canonicalKey(),
serializes concurrent turns per session via SessionTurnGate, and dispatches to the
appropriate registered HarnessAgent.
This implementation provides:
-
Multi-agent registry with fallback to a main agent
-
Stable session mapping: same
MsgContext#canonicalKey()always resolves to the same session id, giving each logical conversation its own memory -
Per-session fair mutual exclusion preventing concurrent turns from racing
-
Outbound address tracking for proactive delivery (e.g. subagent announces)
方法摘要Method Summary
方法详情Method Detail
create
public static HarnessGateway create(ChannelManager channelManager)
创建并返回实例。
Creates a gateway with a channel manager for outbound delivery.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channelManager | ChannelManager | 渠道管理器(类型 `ChannelManager`)。The channel manager. |
HarnessGatewayio/agentscope/harness/agent/gateway/HarnessGateway.java:120–122create
public static HarnessGateway create(ChannelManager channelManager, MessageBus messageBus)
创建网关使用渠道管理器和消息总线。
Creates a gateway with a channel manager and message bus.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channelManager | ChannelManager | 渠道管理器(类型 `ChannelManager`)。The channel manager. |
messageBus | MessageBus | 消息总线(类型 `MessageBus`)。The message bus. |
HarnessGatewayio/agentscope/harness/agent/gateway/HarnessGateway.java:125–128create
public static HarnessGateway create()
创建并返回实例。
Creates a gateway without outbound delivery support.
HarnessGatewayio/agentscope/harness/agent/gateway/HarnessGateway.java:131–133messageBus
public MessageBus messageBus()
返回消息总线。
Returns the message bus, or null if not configured.
MessageBusio/agentscope/harness/agent/gateway/HarnessGateway.java:136–138channelManager
public ChannelManager channelManager()
返回渠道管理器。
The channel manager for outbound delivery, or null if not configured.
ChannelManagerio/agentscope/harness/agent/gateway/HarnessGateway.java:141–143setRuntimeContextResolver
public void setRuntimeContextResolver(ChannelRuntimeContextResolver runtimeContextResolver)
设置运行时上下文解析器。
Sets an optional ChannelRuntimeContextResolver used when building the per-turn RuntimeContext.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
runtimeContextResolver | ChannelRuntimeContextResolver | 运行时上下文解析器(类型 `ChannelRuntimeContextResolver`)。The runtime context resolver. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:149–151getRuntimeContextResolver
public ChannelRuntimeContextResolver getRuntimeContextResolver()
获取运行时上下文解析器。
Returns the configured ChannelRuntimeContextResolver, or null.
ChannelRuntimeContextResolverio/agentscope/harness/agent/gateway/HarnessGateway.java:154–156bindMainAgent
public void bindMainAgent(HarnessAgent agent)
设置该参数。
Performs the bind main agent operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | HarnessAgent | 智能体(类型 `HarnessAgent`)。The agent. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:158–165registerAgent
public void registerAgent(String agentId, HarnessAgent agent)
注册智能体。
Registers the agent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
agent | HarnessAgent | 智能体(类型 `HarnessAgent`)。The agent. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:167–172findAgent
public HarnessAgent findAgent(String agentId)
查找智能体。
Returns the agent registered under agentId, or null if not found.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
HarnessAgentio/agentscope/harness/agent/gateway/HarnessGateway.java:178–181run
public Mono<Msg> run(MsgContext context, List<Msg> messages)
执行运行相关操作。
Performs the run operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:183–186run
public Mono<Msg> run(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress)
执行运行相关操作。
Performs the run operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
outboundAddress | OutboundAddress | 出站 Address(类型 `OutboundAddress`)。The outbound address. |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:188–191run
public Mono<Msg> run(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress, RuntimeContext callerContext)
执行运行相关操作。
Performs the run operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
outboundAddress | OutboundAddress | 出站 Address(类型 `OutboundAddress`)。The outbound address. |
callerContext | RuntimeContext | caller 上下文(类型 `RuntimeContext`)。The caller context. |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:193–200run
public Mono<Msg> run(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress, RuntimeContext callerContext, InboundMessage inboundMessage)
执行运行相关操作。
Performs the run operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
outboundAddress | OutboundAddress | 出站 Address(类型 `OutboundAddress`)。The outbound address. |
callerContext | RuntimeContext | caller 上下文(类型 `RuntimeContext`)。The caller context. |
inboundMessage | InboundMessage | 入站消息(类型 `InboundMessage`)。The inbound message. |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:202–231runStream
public Flux<AgentEvent> runStream(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress)
运行流。
Runs the stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
outboundAddress | OutboundAddress | 出站 Address(类型 `OutboundAddress`)。The outbound address. |
Flux<AgentEvent>io/agentscope/harness/agent/gateway/HarnessGateway.java:233–237runStream
public Flux<AgentEvent> runStream(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress, RuntimeContext callerContext)
运行流。
Runs the stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
outboundAddress | OutboundAddress | 出站 Address(类型 `OutboundAddress`)。The outbound address. |
callerContext | RuntimeContext | caller 上下文(类型 `RuntimeContext`)。The caller context. |
Flux<AgentEvent>io/agentscope/harness/agent/gateway/HarnessGateway.java:239–246runStream
public Flux<AgentEvent> runStream(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress, RuntimeContext callerContext, InboundMessage inboundMessage)
运行流。
Runs the stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | MsgContext | 上下文(类型 `MsgContext`)。The context. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
outboundAddress | OutboundAddress | 出站 Address(类型 `OutboundAddress`)。The outbound address. |
callerContext | RuntimeContext | caller 上下文(类型 `RuntimeContext`)。The caller context. |
inboundMessage | InboundMessage | 入站消息(类型 `InboundMessage`)。The inbound message. |
Flux<AgentEvent>io/agentscope/harness/agent/gateway/HarnessGateway.java:248–277deliverToSession
public boolean deliverToSession(String sessionId, List<Msg> messages)
执行 deliverToSession 方法。
Delivers proactive outbound messages through the channel manager using the session's last recorded outbound address.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
booleanio/agentscope/harness/agent/gateway/HarnessGateway.java:335–346exposeSubagent
public String exposeSubagent(String agentId, String sessionId, Agent agent, OutboundAddress replyTo)
执行 exposeSubagent 方法。
Exposes a spawned subagent as a user-addressable entry point.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。the subagent type identifier |
sessionId | String | 会话标识(类型 `String`)。the session id assigned to the subagent |
agent | Agent | 智能体实例。the agent instance |
replyTo | OutboundAddress | 回复到(类型 `OutboundAddress`)。the outbound address for delivering replies; may be null |
Stringio/agentscope/harness/agent/gateway/HarnessGateway.java:369–389revokeSubagent
public void revokeSubagent(String subagentId)
设置该参数。
Revokes a previously exposed subagent, removing it from the live cache and the registry.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
subagentId | String | 子智能体标识(类型 `String`)。The subagent id. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:392–401setSubagentRegistry
public void setSubagentRegistry(SubagentRegistry registry)
设置子智能体注册表。
Installs the durable SubagentRegistry.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
registry | SubagentRegistry | 注册表(类型 `SubagentRegistry`)。The registry. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:407–411setSubagentMaterializer
public void setSubagentMaterializer(SubagentMaterializer materializer)
设置子智能体物化器。
Installs the SubagentMaterializer used to rebuild subagents that are not present in the local live cache (cross-node / post-restart recovery).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
materializer | SubagentMaterializer | 物化器(类型 `SubagentMaterializer`)。The materializer. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:417–419setBaseStore
public void setBaseStore(BaseStore store)
设置基类存储。
Installs the BaseStore used to persist session routing metadata across nodes.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
store | BaseStore | 存储实例(类型 `BaseStore`)。The store. |
io/agentscope/harness/agent/gateway/HarnessGateway.java:425–427setSessionTurnGate
public void setSessionTurnGate(SessionTurnGate gate)
设置 setSessionTurnGate。
Installs the SessionTurnGate used to serialize concurrent turns per session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
gate | SessionTurnGate | gate(类型 `SessionTurnGate`)。turn gate implementation; ignored when `null` |
io/agentscope/harness/agent/gateway/HarnessGateway.java:435–439runSubagent
public Mono<Msg> runSubagent(String subagentId, List<Msg> messages)
运行子智能体。
Runs the subagent.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
subagentId | String | 子智能体标识(类型 `String`)。The subagent id. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:484–503runSubagentStream
public Flux<AgentEvent> runSubagentStream(String subagentId, List<Msg> messages)
运行子智能体流。
Runs the subagent stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
subagentId | String | 子智能体标识(类型 `String`)。The subagent id. |
messages | List<Msg> | 消息列表(类型 `List`)。The messages. |
Flux<AgentEvent>io/agentscope/harness/agent/gateway/HarnessGateway.java:539–550registerExternalSession
public void registerExternalSession(String sessionId, String gateKey)
注册外部会话。
Adopts a control-plane-allocated session id so #runWakeup(String, String) can resolve it.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。external session id assigned by the control plane |
gateKey | String | gate 键(类型 `String`)。stable gate key (e.g. `team:{teamName}:{role}`) |
io/agentscope/harness/agent/gateway/HarnessGateway.java:588–597isSessionRunning
public boolean isSessionRunning(String sessionId)
判断是否会话运行中。
Returns true when the given session is currently inside a gated turn (a run is in progress).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
booleanio/agentscope/harness/agent/gateway/HarnessGateway.java:604–607runWakeup
public Mono<Msg> runWakeup(String sessionId)
运行 runWakeup。
{@inheritDoc} Delegates to #runWakeup(String, String) with a null user id.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionId | String | 会话标识(类型 `String`)。The session id. |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:618–622runWakeup
public Mono<Msg> runWakeup(String userId, String sessionId)
运行 runWakeup。
Triggers a wakeup-driven run for an idle session, propagating the owning user id when present.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。the owning user id carried by the wakeup entry; may be `null` or blank |
sessionId | String | 会话标识(类型 `String`)。the session to wake up |
Mono<Msg>io/agentscope/harness/agent/gateway/HarnessGateway.java:640–674