AS AgentScopeAPI 手册 / API Reference

MsgContext

public record MsgContext( String channel, String group, String room, String threadId, String threadTs, Map<String, String> extra, String userId)
源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

承载消息上下文数据的记录类型。位于 io.agentscope.harness.agent.gateway 包。核心成员包括 channel、group、room、threadId、threadTs、extra。

Routing context for inbound turns (direct API, channel adapter, group/room/thread). Used by the gateway to map stable conversation keys to session ids.

The #userId field carries the message sender's identity for multi-tenant namespace isolation in io.agentscope.harness.agent.HarnessAgent. It is derived from io.agentscope.harness.agent.gateway.channel.InboundMessage#senderId() and does not participate in #canonicalKey() computation — the same user's conversations always map to the same session key regardless of how userId is set.

记录组件摘要Record Component Summary

组件Component类型Type说明Description
channelString
执行渠道相关操作。
logical channel name (e.g. slack, discord, web)
groupString
执行组相关操作。
optional group / team / workspace id
roomString
执行 `room` 方法。
optional room / channel id
threadIdString
执行会话线程标识相关操作。
optional thread / topic id
threadTsString
执行会话线程 Ts相关操作。
optional provider-specific thread timestamp or message anchor
extraMap<String, String>
执行 `extra` 方法。
additional key/value pairs for adapters
userIdString
执行用户标识相关操作。
optional authenticated user identity for HarnessAgent namespace isolation

构造器摘要Constructor Summary

构造器Constructor说明Description
public MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String, String> extra, String userId)
初始化 `MsgContext` 实例。
Creates a new instance.
public MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String, String> extra)
初始化 `MsgContext` 实例。
Convenience constructor without `userId` (backwards-compatible for callsites that do not carry user identity).

方法摘要Method Summary

方法Method说明Description
public static MsgContext defaultContext()
static
返回默认上下文。
Default single-conversation context (no channel metadata, no userId).
public MsgContext withUserId(String userId)
执行使用用户标识相关操作。
Returns a copy of this context with the given `userId` set.
public String canonicalKey()
返回规范键。
Stable key for session routing: same logical conversation maps to the same gateway session id.

记录组件详情Record Component Detail

channel

String channel

执行渠道相关操作。

logical channel name (e.g. slack, discord, web)

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

group

String group

执行组相关操作。

optional group / team / workspace id

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

room

String room

执行 room 方法。

optional room / channel id

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

threadId

String threadId

执行会话线程标识相关操作。

optional thread / topic id

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

threadTs

String threadTs

执行会话线程 Ts相关操作。

optional provider-specific thread timestamp or message anchor

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

extra

Map<String, String> extra

执行 extra 方法。

additional key/value pairs for adapters

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

userId

String userId

执行用户标识相关操作。

optional authenticated user identity for HarnessAgent namespace isolation

源码Source io/agentscope/harness/agent/gateway/MsgContext.java:39–104

构造器详情Constructor Detail

MsgContext

public MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String, String> extra, String userId)

初始化 MsgContext 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
channelString渠道(类型 `String`)。The channel.
groupString组(类型 `String`)。The group.
roomStringroom(类型 `String`)。The room.
threadIdString会话线程标识(类型 `String`)。The thread id.
threadTsString会话线程 Ts(类型 `String`)。The thread ts.
extraMap<String, String>extra(类型 `Map`)。The extra.
userIdString用户标识(类型 `String`)。The user id.
源码Source io/agentscope/harness/agent/gateway/MsgContext.java:48–50

MsgContext

public MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String, String> extra)

初始化 MsgContext 实例。

Convenience constructor without userId (backwards-compatible for callsites that do not carry user identity).

参数Parameters
名称Name类型Type说明Description
channelString渠道(类型 `String`)。The channel.
groupString组(类型 `String`)。The group.
roomStringroom(类型 `String`)。The room.
threadIdString会话线程标识(类型 `String`)。The thread id.
threadTsString会话线程 Ts(类型 `String`)。The thread ts.
extraMap<String, String>extra(类型 `Map`)。The extra.
源码Source io/agentscope/harness/agent/gateway/MsgContext.java:56–64

方法详情Method Detail

defaultContext

public static MsgContext defaultContext()
static

返回默认上下文。

Default single-conversation context (no channel metadata, no userId).

返回Returns MsgContext
返回MsgContext。Returns msg context.
源码Source io/agentscope/harness/agent/gateway/MsgContext.java:67–69

withUserId

public MsgContext withUserId(String userId)

执行使用用户标识相关操作。

Returns a copy of this context with the given userId set.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
返回Returns MsgContext
返回MsgContext。Returns msg context.
源码Source io/agentscope/harness/agent/gateway/MsgContext.java:72–74

canonicalKey

public String canonicalKey()

返回规范键。

Stable key for session routing: same logical conversation maps to the same gateway session id.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/harness/agent/gateway/MsgContext.java:77–103
基于官方固定版本源码静态生成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.