AS AgentScopeAPI 手册 / API Reference

SendOptions

public record SendOptions( String userId, String sessionId, String agentId, RuntimeContext runtimeContext)
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:69–122

承载发送选项数据的记录类型。位于 io.agentscope.harness.agent.gateway.channel.chatui 包。核心成员包括 userId、sessionId、agentId、runtimeContext、of、withAgentId。

Routing identity for ChatUiChannel requests. Replaces the need to understand io.agentscope.harness.agent.gateway.channel.DmScope by letting the caller express routing intent through simple business identifiers.

  • userId — identifies the user. Maps to io.agentscope.harness.agent.gateway.MsgContext#userId() for HarnessAgent namespace isolation, and is used as the default session key when sessionId is null.

  • sessionId — optional explicit conversation identifier. When provided, different sessions for the same user are kept separate. When null, one session per user is the default.

  • agentId — optional target agent override for multi-agent setups. When null, the channel's default agent is used.

  • runtimeContext — optional per-call RuntimeContext merged into the agent turn (attributes, typed values, force-sync flags, …). Gateway-owned identity fields still win on conflict.

Usage

`// One session per user (most common)
chat.send(SendOptions.userId("user-1"), "hello");

// Same user, different sessions
chat.send(SendOptions.of("user-1", "session-a"), "hello");
chat.send(SendOptions.of("user-1", "session-b"), "hello");

// Target a specific agent in multi-agent setups
chat.send(SendOptions.userId("user-1").withAgentId("support"), "help me");

// Pass application context into the agent turn
chat.send(
SendOptions.userId("user-1")
.withAttribute("tenant", "acme")
.withRuntimeContext(
RuntimeContext.builder()
.put(AgentSpawnTool.CTX_FORCE_SYNC, true)
.build()),
"hello");
`

记录组件摘要Record Component Summary

组件Component类型Type说明Description
userIdString
用户身份(必填)。
the user identity (required)
sessionIdString
执行会话标识相关操作。
optional conversation identifier; null means one session per user
agentIdString
执行智能体标识相关操作。
optional target agent override; null for default routing
runtimeContextRuntimeContext
执行运行时上下文相关操作。
optional caller-supplied runtime context; null when none

构造器摘要Constructor Summary

构造器Constructor说明Description
public SendOptions(String userId, String sessionId, String agentId, RuntimeContext runtimeContext)
初始化 `SendOptions` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public static SendOptions userId(String userId)
static
设置用户标识。
One session per user — the most common case.
public static SendOptions of(String userId, String sessionId)
static
创建并返回实例。
Explicit user + session — multiple conversations for the same user.
public SendOptions withAgentId(String agentId)
执行使用智能体标识相关操作。
Returns a copy with the given agent id override.
public SendOptions withRuntimeContext(RuntimeContext runtimeContext)
执行使用运行时上下文相关操作。
Returns a copy that carries the given `RuntimeContext` into the agent turn.
public SendOptions withAttribute(String key, Object value)
执行使用属性相关操作。
Returns a copy with a string attribute merged into the carried `RuntimeContext`.
public T SendOptions withAttribute(Class<T> type, T value)
执行使用属性相关操作。
Returns a copy with a typed attribute merged into the carried `RuntimeContext`.

记录组件详情Record Component Detail

userId

String userId

用户身份(必填)。

the user identity (required)

源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:69–122

sessionId

String sessionId

执行会话标识相关操作。

optional conversation identifier; null means one session per user

源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:69–122

agentId

String agentId

执行智能体标识相关操作。

optional target agent override; null for default routing

源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:69–122

runtimeContext

RuntimeContext runtimeContext

执行运行时上下文相关操作。

optional caller-supplied runtime context; null when none

源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:69–122

构造器详情Constructor Detail

SendOptions

public SendOptions(String userId, String sessionId, String agentId, RuntimeContext runtimeContext)

初始化 SendOptions 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
agentIdString智能体标识(类型 `String`)。The agent id.
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。The runtime context.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:72–74

方法详情Method Detail

userId

public static SendOptions userId(String userId)
static

设置用户标识。

One session per user — the most common case.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
返回Returns SendOptions
返回SendOptions。Returns send options.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:77–79

of

public static SendOptions of(String userId, String sessionId)
static

创建并返回实例。

Explicit user + session — multiple conversations for the same user.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
返回Returns SendOptions
返回SendOptions。Returns send options.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:82–85

withAgentId

public SendOptions withAgentId(String agentId)

执行使用智能体标识相关操作。

Returns a copy with the given agent id override.

参数Parameters
名称Name类型Type说明Description
agentIdString智能体标识(类型 `String`)。The agent id.
返回Returns SendOptions
返回SendOptions。Returns send options.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:88–90

withRuntimeContext

public SendOptions withRuntimeContext(RuntimeContext runtimeContext)

执行使用运行时上下文相关操作。

Returns a copy that carries the given RuntimeContext into the agent turn.

参数Parameters
名称Name类型Type说明Description
runtimeContextRuntimeContext运行时上下文(类型 `RuntimeContext`)。The runtime context.
返回Returns SendOptions
返回SendOptions。Returns send options.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:96–98

withAttribute

public SendOptions withAttribute(String key, Object value)

执行使用属性相关操作。

Returns a copy with a string attribute merged into the carried RuntimeContext.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key.
valueObject值(类型 `Object`)。The value.
返回Returns SendOptions
返回SendOptions。Returns send options.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:104–107

withAttribute

public T SendOptions withAttribute(Class<T> type, T value)

执行使用属性相关操作。

Returns a copy with a typed attribute merged into the carried RuntimeContext.

参数Parameters
名称Name类型Type说明Description
typeClass<T>类型(类型 `Class`)。The type.
valueT值(类型 `T`)。The value.
返回Returns SendOptions
返回SendOptions。Returns send options.
源码Source io/agentscope/harness/agent/gateway/channel/chatui/SendOptions.java:113–116
基于官方固定版本源码静态生成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.