SessionAgentManager
public class SessionAgentManager
io/agentscope/harness/coding/session/SessionAgentManager.java:68–924会话智能体管理器,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.harness.coding.session 包。核心成员包括 setAnnounceDispatcher、setSpawnInterceptor、delegate、getConfig、getRunRegistry、getAgentFactories。
Full session management implementation built on top of DefaultAgentManager. Owns *all
* session-related state and concurrency controls:
-
AgentStateStore registry (
sessionsByKey, labels, parent-child) -
Lane management (semaphores for bounded concurrency, per-session locks)
-
SubagentRunRegistryfor run lifecycle tracking -
#registerSession/#registerMainSession— session creation -
#execute— lane-aware, locked agent execution -
Pending completions queue (announce) —
#drainPendingCompletions -
Announce dispatch —
AnnounceDispatcher -
Full
SessionView,HistoryResultviews -
AgentStateStore listing with kind/time filters
Uses DefaultAgentManager only for agent creation (DefaultAgentManager#createAgent) and invocation (DefaultAgentManager#invokeAgent).
Used by SessionsTool and io.agentscope.harness.coding.gateway.HarnessGateway when the full orchestration stack is active.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
AnnounceDispatcher | 接口interface | 定义 Announce 调度器契约的接口。 Callback invoked when a subagent run completes and an announce payload is ready. |
SpawnInterceptor | 接口interface | 定义 Spawn 拦截器契约的接口。 Callback invoked after a subagent session is spawned through this manager. |
构造器摘要Constructor Summary
方法摘要Method Summary
构造器详情Constructor Detail
SessionAgentManager
public SessionAgentManager(DefaultAgentManager delegate, AgentManagerConfig config, SubagentRunRegistry runRegistry, SessionStore sessionStore)
初始化 SessionAgentManager 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
delegate | DefaultAgentManager | 委托(类型 `DefaultAgentManager`)。agent factory/invoker |
config | AgentManagerConfig | 配置对象(类型 `AgentManagerConfig`)。concurrency and announce tuning |
runRegistry | SubagentRunRegistry | 运行注册表(类型 `SubagentRunRegistry`)。run lifecycle tracking |
sessionStore | SessionStore | 会话存储(类型 `SessionStore`)。durable session registry for metadata persistence; may be null |
io/agentscope/harness/coding/session/SessionAgentManager.java:121–135SessionAgentManager
public SessionAgentManager(DefaultAgentManager delegate, AgentManagerConfig config, SubagentRunRegistry runRegistry)
初始化 SessionAgentManager 实例。
Constructor without SessionStore (no metadata persistence).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
delegate | DefaultAgentManager | 委托(类型 `DefaultAgentManager`)。The delegate. |
config | AgentManagerConfig | 配置对象(类型 `AgentManagerConfig`)。The config. |
runRegistry | SubagentRunRegistry | 运行注册表(类型 `SubagentRunRegistry`)。The run registry. |
io/agentscope/harness/coding/session/SessionAgentManager.java:138–143方法详情Method Detail
setAnnounceDispatcher
public void setAnnounceDispatcher(AnnounceDispatcher dispatcher)
设置 setAnnounceDispatcher。
Sets the announce dispatcher.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
dispatcher | AnnounceDispatcher | 调度器(类型 `AnnounceDispatcher`)。The dispatcher. |
io/agentscope/harness/coding/session/SessionAgentManager.java:170–172setSpawnInterceptor
public void setSpawnInterceptor(SpawnInterceptor interceptor)
设置 setSpawnInterceptor。
Sets the spawn interceptor.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
interceptor | SpawnInterceptor | 拦截器(类型 `SpawnInterceptor`)。The interceptor. |
io/agentscope/harness/coding/session/SessionAgentManager.java:174–176delegate
public DefaultAgentManager delegate()
返回委托。
The underlying agent factory/invoker this session manager delegates to.
DefaultAgentManagerio/agentscope/harness/coding/session/SessionAgentManager.java:179–181getConfig
public AgentManagerConfig getConfig()
获取配置。
Returns the config.
AgentManagerConfigio/agentscope/harness/coding/session/SessionAgentManager.java:187–189getRunRegistry
public SubagentRunRegistry getRunRegistry()
获取运行注册表。
Returns the run registry.
SubagentRunRegistryio/agentscope/harness/coding/session/SessionAgentManager.java:191–193getAgentFactories
public Map<String, SubagentFactory> getAgentFactories()
获取 getAgentFactories。
Returns the agent factories.
Map<String, SubagentFactory>io/agentscope/harness/coding/session/SessionAgentManager.java:195–197getSessionStore
public SessionStore getSessionStore()
获取会话存储。
The durable session registry, or null if not configured.
SessionStoreio/agentscope/harness/coding/session/SessionAgentManager.java:200–202resolveSessionKey
public Optional<String> resolveSessionKey(String keyOrLabel)
解析会话键。
Performs the resolve session key operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keyOrLabel | String | 键或标签(类型 `String`)。The key or label. |
Optional<String>io/agentscope/harness/coding/session/SessionAgentManager.java:208–221exists
public boolean exists(String sessionKey)
判断数据是否存在。
Performs the exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
booleanio/agentscope/harness/coding/session/SessionAgentManager.java:223–225getSession
public Optional<SessionEntry> getSession(String sessionKey)
获取会话。
Returns the session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
Optional<SessionEntry>io/agentscope/harness/coding/session/SessionAgentManager.java:227–232allSessions
public Collection<SessionEntry> allSessions()
返回所有会话。
Returns the all sessions.
Collection<SessionEntry>io/agentscope/harness/coding/session/SessionAgentManager.java:234–236listChildren
public List<String> listChildren(String parentSessionKey)
列出子级。
Lists the children.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
parentSessionKey | String | 父级会话键(类型 `String`)。The parent session key. |
List<String>io/agentscope/harness/coding/session/SessionAgentManager.java:238–244registerSession
public SpawnResult registerSession(String agentId, String label, String parentSessionKey, int parentSpawnDepth)
注册会话。
Registers the session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
label | String | 标签(类型 `String`)。The label. |
parentSessionKey | String | 父级会话键(类型 `String`)。The parent session key. |
parentSpawnDepth | int | 父级 Spawn Depth(类型 `int`)。The parent spawn depth. |
SpawnResultio/agentscope/harness/coding/session/SessionAgentManager.java:250–253registerSession
public SpawnResult registerSession(String agentId, String label, String parentSessionKey, int parentSpawnDepth, String userId)
注册会话。
Registers a new subagent session, optionally inheriting the userId from its parent for continued namespace isolation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
label | String | 标签(类型 `String`)。The label. |
parentSessionKey | String | 父级会话键(类型 `String`)。The parent session key. |
parentSpawnDepth | int | 父级 Spawn Depth(类型 `int`)。The parent spawn depth. |
userId | String | 用户标识(类型 `String`)。The user id. |
SpawnResultio/agentscope/harness/coding/session/SessionAgentManager.java:259–353registerMainSession
public SpawnResult registerMainSession(String agentId, String label)
注册主会话。
Registers the main session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
label | String | 标签(类型 `String`)。The label. |
SpawnResultio/agentscope/harness/coding/session/SessionAgentManager.java:359–361registerMainSession
public SpawnResult registerMainSession(String agentId, String label, String gateKey)
注册主会话。
Registers the main session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
label | String | 标签(类型 `String`)。The label. |
gateKey | String | gate 键(类型 `String`)。The gate key. |
SpawnResultio/agentscope/harness/coding/session/SessionAgentManager.java:363–365registerMainSession
public SpawnResult registerMainSession(String agentId, String label, String gateKey, String userId)
注册主会话。
Registers a new MAIN session, optionally recording the gateKey for gateway routing persistence and userId for HarnessAgent namespace isolation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
label | String | 标签(类型 `String`)。The label. |
gateKey | String | gate 键(类型 `String`)。The gate key. |
userId | String | 用户标识(类型 `String`)。The user id. |
SpawnResultio/agentscope/harness/coding/session/SessionAgentManager.java:371–405viewSession
public Optional<SessionView> viewSession(String sessionKey)
设置该参数。
Performs the view session operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
Optional<SessionView>io/agentscope/harness/coding/session/SessionAgentManager.java:407–409registerReviewerSession
public SpawnResult registerReviewerSession(String agentId, String label, String gateKey, String userId)
注册 registerReviewerSession。
Registers a new REVIEWER session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
label | String | 标签(类型 `String`)。The label. |
gateKey | String | gate 键(类型 `String`)。The gate key. |
userId | String | 用户标识(类型 `String`)。The user id. |
SpawnResultio/agentscope/harness/coding/session/SessionAgentManager.java:419–453execute
public SendResult execute(String sessionKeyOrLabel, String prompt, long timeoutMs)
执行执行相关操作。
Performs the execute operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKeyOrLabel | String | 会话键或标签(类型 `String`)。The session key or label. |
prompt | String | 提示词(类型 `String`)。The prompt. |
timeoutMs | long | 超时 Ms(类型 `long`)。The timeout ms. |
SendResultio/agentscope/harness/coding/session/SessionAgentManager.java:459–461execute
public SendResult execute(String sessionKeyOrLabel, String prompt, long timeoutMs, boolean announceToRequesterOnComplete, CommandLane lane)
执行执行相关操作。
Performs the execute operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKeyOrLabel | String | 会话键或标签(类型 `String`)。The session key or label. |
prompt | String | 提示词(类型 `String`)。The prompt. |
timeoutMs | long | 超时 Ms(类型 `long`)。The timeout ms. |
announceToRequesterOnComplete | boolean | announce 到 Requester On Complete(类型 `boolean`)。The announce to requester on complete. |
lane | CommandLane | lane(类型 `CommandLane`)。The lane. |
SendResultio/agentscope/harness/coding/session/SessionAgentManager.java:463–529evictAgent
public void evictAgent(String sessionKey)
设置该参数。
Evicts the cached agent for the given session key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
io/agentscope/harness/coding/session/SessionAgentManager.java:596–600runMaintenance
public int runMaintenance()
运行维护。
Runs session maintenance: prunes stale sessions and caps total entries.
intio/agentscope/harness/coding/session/SessionAgentManager.java:612–649removeSession
public void removeSession(String sessionKey)
移除会话。
Removes a session from all registries (in-memory, store, agent cache).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKey | String | 会话键(类型 `String`)。The session key. |
io/agentscope/harness/coding/session/SessionAgentManager.java:656–677list
public List<SessionView> list(Set<String> kinds, int limit, int activeMinutes)
执行列表相关操作。
Performs the list operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
kinds | Set<String> | kinds(类型 `Set`)。The kinds. |
limit | int | 数量上限(类型 `int`)。The limit. |
activeMinutes | int | active 分钟(类型 `int`)。The active minutes. |
List<SessionView>io/agentscope/harness/coding/session/SessionAgentManager.java:683–702history
public HistoryResult history(String sessionKeyOrLabel, int limit)
执行历史相关操作。
Performs the history operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
sessionKeyOrLabel | String | 会话键或标签(类型 `String`)。The session key or label. |
limit | int | 数量上限(类型 `int`)。The limit. |
HistoryResultio/agentscope/harness/coding/session/SessionAgentManager.java:704–728drainPendingCompletions
public List<PendingCompletion> drainPendingCompletions(String requesterSessionKey, int limit)
执行 drainPendingCompletions 方法。
Performs the drain pending completions operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
requesterSessionKey | String | requester 会话键(类型 `String`)。The requester session key. |
limit | int | 数量上限(类型 `int`)。The limit. |
List<PendingCompletion>io/agentscope/harness/coding/session/SessionAgentManager.java:734–753pendingCompletionCount
public int pendingCompletionCount(String requesterSessionKey)
设置待处理补全数量。
Performs the pending completion count operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
requesterSessionKey | String | requester 会话键(类型 `String`)。The requester session key. |
intio/agentscope/harness/coding/session/SessionAgentManager.java:755–766resolveSessionFilePath
public String resolveSessionFilePath(String agentId, String sessionId)
解析会话文件路径。
Resolves the session file path for a given agent and session.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
Stringio/agentscope/harness/coding/session/SessionAgentManager.java:916–923嵌套类详情Nested Class Detail
AnnounceDispatcher
@FunctionalInterface public interface AnnounceDispatcher定义 Announce 调度器契约的接口。位于 io.agentscope.harness.coding.session 包。核心成员包括 dispatch。
Callback invoked when a subagent run completes and an announce payload is ready.
SpawnInterceptor
@FunctionalInterface public interface SpawnInterceptor定义 Spawn 拦截器契约的接口。位于 io.agentscope.harness.coding.session 包。核心成员包括 onSpawn。
Callback invoked after a subagent session is spawned through this manager.