AS AgentScopeAPI 手册 / API Reference

HarnessGateway

public final class HarnessGateway implements Gateway
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:70–462

Harness 网关,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.coding.gateway 包,实现 Gateway。核心成员包括 create、sessionAgentManager、channelManager、bindMainAgent、registerAgent、run。

Gateway-style gateway: routes inbound turns by MsgContext, and dispatches subagent completion announces as new HarnessAgent runs on the root requester (OpenClaw gateway analogue).

AgentStateStore management is delegated to SessionAgentManager. The gateway wires itself as the SessionAgentManager.AnnounceDispatcher and SessionAgentManager.SpawnInterceptor on creation, so subagent spawns and announces flow through the correct channel gates.

AgentStateStore routing

On the first #run call for a given MsgContext#canonicalKey(), a MAIN session is registered in the SessionAgentManager. Subsequent calls for the same key reuse that session. Multiple harness agents may be registered with #registerAgent for agentId-based routing.

Per-session turn serialization

Each MsgContext#canonicalKey() has a fair lock (SessionTurnGate) so at most one HarnessAgent.call runs at a time for that key.

方法摘要Method Summary

方法Method说明Description
public static HarnessGateway create(SessionAgentManager sessionAgentManager, ChannelManager channelManager)
static
创建并返回实例。
Creates a gateway wired to the given `SessionAgentManager` and `ChannelManager`.
public static HarnessGateway create(SessionAgentManager sessionAgentManager)
static
创建并返回实例。
Creates a gateway without a channel manager (no outbound delivery support).
public SessionAgentManager sessionAgentManager()
返回会话智能体管理器。
The session agent manager used by this gateway.
public ChannelManager channelManager()
返回渠道管理器。
The channel manager for outbound delivery, or null if not configured.
public void bindMainAgent(HarnessAgent agent)
设置该参数。
Binds the primary harness agent.
public void registerAgent(String agentId, HarnessAgent agent)
注册智能体。
Registers the agent.
public Mono<Msg> run(MsgContext context, List<Msg> messages)
执行运行相关操作。
Direct or channel-originated turn.
public Mono<Msg> run(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress)
执行运行相关操作。
Inbound turn with outbound address tracking.

方法详情Method Detail

create

public static HarnessGateway create(SessionAgentManager sessionAgentManager, ChannelManager channelManager)
static

创建并返回实例。

Creates a gateway wired to the given SessionAgentManager and ChannelManager.

参数Parameters
名称Name类型Type说明Description
sessionAgentManagerSessionAgentManager会话智能体管理器(类型 `SessionAgentManager`)。session and agent lifecycle manager
channelManagerChannelManager渠道管理器(类型 `ChannelManager`)。channel registry for outbound delivery; may be null if outbound delivery is not needed
返回Returns HarnessGateway
返回HarnessGateway。Returns harness gateway.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:128–136

create

public static HarnessGateway create(SessionAgentManager sessionAgentManager)
static

创建并返回实例。

Creates a gateway without a channel manager (no outbound delivery support).

参数Parameters
名称Name类型Type说明Description
sessionAgentManagerSessionAgentManager会话智能体管理器(类型 `SessionAgentManager`)。The session agent manager.
返回Returns HarnessGateway
返回HarnessGateway。Returns harness gateway.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:139–141

sessionAgentManager

public SessionAgentManager sessionAgentManager()

返回会话智能体管理器。

The session agent manager used by this gateway.

返回Returns SessionAgentManager
返回SessionAgentManager。Returns session agent manager.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:144–146

channelManager

public ChannelManager channelManager()

返回渠道管理器。

The channel manager for outbound delivery, or null if not configured.

返回Returns ChannelManager
返回ChannelManager。Returns channel manager.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:149–151

bindMainAgent

public void bindMainAgent(HarnessAgent agent)

设置该参数。

Binds the primary harness agent.

参数Parameters
名称Name类型Type说明Description
agentHarnessAgent智能体(类型 `HarnessAgent`)。The agent.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:195–202

registerAgent

public void registerAgent(String agentId, HarnessAgent agent)

注册智能体。

Registers the agent.

参数Parameters
名称Name类型Type说明Description
agentIdString智能体标识(类型 `String`)。The agent id.
agentHarnessAgent智能体(类型 `HarnessAgent`)。The agent.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:204–209

run

public Mono<Msg> run(MsgContext context, List<Msg> messages)

执行运行相关操作。

Direct or channel-originated turn.

参数Parameters
名称Name类型Type说明Description
contextMsgContext上下文(类型 `MsgContext`)。The context.
messagesList<Msg>消息列表(类型 `List`)。The messages.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:216–219

run

public Mono<Msg> run(MsgContext context, List<Msg> messages, OutboundAddress outboundAddress)

执行运行相关操作。

Inbound turn with outbound address tracking.

参数Parameters
名称Name类型Type说明Description
contextMsgContext上下文(类型 `MsgContext`)。The context.
messagesList<Msg>消息列表(类型 `List`)。The messages.
outboundAddressOutboundAddress出站 Address(类型 `OutboundAddress`)。The outbound address.
返回Returns Mono<Msg>
返回Mono。Returns mono.
源码Source io/agentscope/harness/coding/gateway/HarnessGateway.java:226–260

继承成员Inherited Members

基于官方固定版本源码静态生成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.