WorkspaceTaskRepository
public class WorkspaceTaskRepository implements TaskRepository
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:79–979工作区任务仓库,负责持久化与读取数据。位于 io.agentscope.harness.agent.subagent.task 包,实现 TaskRepository。核心成员包括 forTests、setCompletionCallback、putTask、getTask、listTasks、cancelTask。
Workspace-backed TaskRepository that uses WorkspaceManager as the authoritative
truth source for task state, while maintaining in-memory BackgroundTask handles as a
local performance overlay for tasks running on the current node.
Storage layout: agents/<parentAgentId>/tasks/<sessionId>.json — a JSON map of
taskId → TaskRecord, consistent with how sessions are stored. In distributed deployments
using RemoteFilesystemSpec, this path is automatically routed to shared storage, making
task state visible to any node. In sandbox mode the injected filesystem is a per-call proxy with
no live sandbox between calls, so task records are persisted on the host workspace instead of
inside the sandbox — see the task-record routing in WorkspaceManager.
The in-memory localTasks map is keyed by "<sessionId>:<taskId>" to preserve
session isolation when multiple sessions coexist in the same process.
Distributed semantics:
-
Task execution is sticky to the originating node (the node that called
#putTask). -
Any node can read task status via
#getTaskor#listTasksby falling back to workspace records when no local future exists. -
block=trueon a non-originating node degrades gracefully to reading the latest persisted terminal state without hanging. -
Cancellation sets a
TaskRecord#isCancelRequested()flag in workspace storage; the originating node checks this flag before invoking the subagent for best-effort cancel. -
Remote
TaskRunSpec.RemoteTaskRunSpectasks use aRemoteSubagentTransport(Agent Protocol by default) and persistTaskRecord#getRemoteBaseUrl()for cross-node resume. -
Orphan sweeping is throttled via
PeriodicGate: useio.agentscope.harness.agent.coordination.StoreBackedPeriodicGatefor cross-replica deduplication, orLocalPeriodicGate(the default) for single-process deployments. Prefer a control-plane hostedTaskRepositorywhen available — that path runs a leader-only sweep and does not use this workspace repository at all.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId) | 初始化 `WorkspaceTaskRepository` 实例。 Creates a new instance. |
public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId, PeriodicGate periodicGate) | 初始化 `WorkspaceTaskRepository` 实例。 Creates a repository with an explicit `PeriodicGate` for orphan-sweep throttling. |
public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId, ExecutorService executor) | 初始化 `WorkspaceTaskRepository` 实例。 Creates a new instance. |
方法摘要Method Summary
构造器详情Constructor Detail
WorkspaceTaskRepository
public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId)
初始化 WorkspaceTaskRepository 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
parentAgentId | String | 父级智能体标识(类型 `String`)。The parent agent id. |
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:134–136WorkspaceTaskRepository
public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId, PeriodicGate periodicGate)
初始化 WorkspaceTaskRepository 实例。
Creates a repository with an explicit PeriodicGate for orphan-sweep throttling.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
parentAgentId | String | 父级智能体标识(类型 `String`)。The parent agent id. |
periodicGate | PeriodicGate | periodic Gate(类型 `PeriodicGate`)。The periodic gate. |
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:144–159WorkspaceTaskRepository
public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId, ExecutorService executor)
初始化 WorkspaceTaskRepository 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
parentAgentId | String | 父级智能体标识(类型 `String`)。The parent agent id. |
executor | ExecutorService | 执行器(类型 `ExecutorService`)。The executor. |
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:161–164方法详情Method Detail
forTests
public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId)
执行 forTests 方法。
Test-only factory without background heartbeat or orphan sweeper threads.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
parentAgentId | String | 父级智能体标识(类型 `String`)。The parent agent id. |
WorkspaceTaskRepositoryio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:172–189forTests
public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId, PeriodicGate periodicGate)
执行 forTests 方法。
Test-only factory with a caller-supplied PeriodicGate and no maintenance threads.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
parentAgentId | String | 父级智能体标识(类型 `String`)。The parent agent id. |
periodicGate | PeriodicGate | periodic Gate(类型 `PeriodicGate`)。The periodic gate. |
WorkspaceTaskRepositoryio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:194–205forTests
public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId, ExecutorService executor)
执行 forTests 方法。
Test-only factory with a caller-supplied executor and no maintenance threads.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
parentAgentId | String | 父级智能体标识(类型 `String`)。The parent agent id. |
executor | ExecutorService | 执行器(类型 `ExecutorService`)。The executor. |
WorkspaceTaskRepositoryio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:208–212setCompletionCallback
public void setCompletionCallback(TaskCompletionCallback callback)
设置补全回调。
Sets the completion callback.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
callback | TaskCompletionCallback | 回调函数(类型 `TaskCompletionCallback`)。The callback. |
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:256–259putTask
public BackgroundTask putTask(RuntimeContext rc, String taskId, String subAgentId, String sessionId, TaskRunSpec spec)
执行 putTask 方法。
Performs the put task operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
taskId | String | 任务标识(类型 `String`)。The task id. |
subAgentId | String | 子智能体标识(类型 `String`)。The sub agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
spec | TaskRunSpec | 规格(类型 `TaskRunSpec`)。The spec. |
BackgroundTaskio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:269–351getTask
public BackgroundTask getTask(RuntimeContext rc, String sessionId, String taskId)
获取任务。
Returns the task.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
taskId | String | 任务标识(类型 `String`)。The task id. |
BackgroundTaskio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:514–526listTasks
public Collection<BackgroundTask> listTasks(RuntimeContext rc, String sessionId, TaskStatus filter)
列出任务。
Lists the tasks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
filter | TaskStatus | 过滤条件(类型 `TaskStatus`)。The filter. |
Collection<BackgroundTask>io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:528–553cancelTask
public boolean cancelTask(RuntimeContext rc, String sessionId, String taskId)
执行取消任务相关操作。
Performs the cancel task operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
taskId | String | 任务标识(类型 `String`)。The task id. |
booleanio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:555–590findPendingDeliveries
public List<TaskDelivery> findPendingDeliveries(RuntimeContext rc, String sessionId)
查找 findPendingDeliveries。
Finds the pending deliveries.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
List<TaskDelivery>io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:594–621markDelivered
public void markDelivered(RuntimeContext rc, String sessionId, String taskId)
执行 markDelivered 方法。
Stamps deliveredAt on the persisted record.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
taskId | String | 任务标识(类型 `String`)。The task id. |
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:630–640isDelivered
public boolean isDelivered(RuntimeContext rc, String sessionId, String taskId)
判断是否 isDelivered。
Returns whether the delivered.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
taskId | String | 任务标识(类型 `String`)。The task id. |
booleanio/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:642–649shutdown
public void shutdown()
关闭资源并释放连接。
Releases resources and connections.
io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:651–675