AS AgentScopeAPI 手册 / API Reference

WorkspaceTaskRepository

public class WorkspaceTaskRepository implements TaskRepository
源码Source 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 #getTask or #listTasks by falling back to workspace records when no local future exists.

  • block=true on 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.RemoteTaskRunSpec tasks use a RemoteSubagentTransport (Agent Protocol by default) and persist TaskRecord#getRemoteBaseUrl() for cross-node resume.

  • Orphan sweeping is throttled via PeriodicGate: use io.agentscope.harness.agent.coordination.StoreBackedPeriodicGate for cross-replica deduplication, or LocalPeriodicGate (the default) for single-process deployments. Prefer a control-plane hosted TaskRepository when 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

方法Method说明Description
public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId)
static
执行 `forTests` 方法。
Test-only factory without background heartbeat or orphan sweeper threads.
public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId, PeriodicGate periodicGate)
static
执行 `forTests` 方法。
Test-only factory with a caller-supplied `PeriodicGate` and no maintenance threads.
public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId, ExecutorService executor)
static
执行 `forTests` 方法。
Test-only factory with a caller-supplied executor and no maintenance threads.
public void setCompletionCallback(TaskCompletionCallback callback)
设置补全回调。
Sets the completion callback.
public BackgroundTask putTask(RuntimeContext rc, String taskId, String subAgentId, String sessionId, TaskRunSpec spec)
执行 `putTask` 方法。
Performs the put task operation.
public BackgroundTask getTask(RuntimeContext rc, String sessionId, String taskId)
获取任务。
Returns the task.
public Collection<BackgroundTask> listTasks(RuntimeContext rc, String sessionId, TaskStatus filter)
列出任务。
Lists the tasks.
public boolean cancelTask(RuntimeContext rc, String sessionId, String taskId)
执行取消任务相关操作。
Performs the cancel task operation.
public List<TaskDelivery> findPendingDeliveries(RuntimeContext rc, String sessionId)
查找 `findPendingDeliveries`。
Finds the pending deliveries.
public void markDelivered(RuntimeContext rc, String sessionId, String taskId)
执行 `markDelivered` 方法。
Stamps `deliveredAt` on the persisted record.
public boolean isDelivered(RuntimeContext rc, String sessionId, String taskId)
判断是否 `isDelivered`。
Returns whether the delivered.
public void shutdown()
关闭资源并释放连接。
Releases resources and connections.

构造器详情Constructor Detail

WorkspaceTaskRepository

public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId)

初始化 WorkspaceTaskRepository 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
parentAgentIdString父级智能体标识(类型 `String`)。The parent agent id.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:134–136

WorkspaceTaskRepository

public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId, PeriodicGate periodicGate)

初始化 WorkspaceTaskRepository 实例。

Creates a repository with an explicit PeriodicGate for orphan-sweep throttling.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
parentAgentIdString父级智能体标识(类型 `String`)。The parent agent id.
periodicGatePeriodicGateperiodic Gate(类型 `PeriodicGate`)。The periodic gate.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:144–159

WorkspaceTaskRepository

public WorkspaceTaskRepository(WorkspaceManager workspaceManager, String parentAgentId, ExecutorService executor)

初始化 WorkspaceTaskRepository 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
parentAgentIdString父级智能体标识(类型 `String`)。The parent agent id.
executorExecutorService执行器(类型 `ExecutorService`)。The executor.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:161–164

方法详情Method Detail

forTests

public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId)
static

执行 forTests 方法。

Test-only factory without background heartbeat or orphan sweeper threads.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
parentAgentIdString父级智能体标识(类型 `String`)。The parent agent id.
返回Returns WorkspaceTaskRepository
返回WorkspaceTaskRepository。Returns workspace task repository.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:172–189

forTests

public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId, PeriodicGate periodicGate)
static

执行 forTests 方法。

Test-only factory with a caller-supplied PeriodicGate and no maintenance threads.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
parentAgentIdString父级智能体标识(类型 `String`)。The parent agent id.
periodicGatePeriodicGateperiodic Gate(类型 `PeriodicGate`)。The periodic gate.
返回Returns WorkspaceTaskRepository
返回WorkspaceTaskRepository。Returns workspace task repository.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:194–205

forTests

public static WorkspaceTaskRepository forTests(WorkspaceManager workspaceManager, String parentAgentId, ExecutorService executor)
static

执行 forTests 方法。

Test-only factory with a caller-supplied executor and no maintenance threads.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
parentAgentIdString父级智能体标识(类型 `String`)。The parent agent id.
executorExecutorService执行器(类型 `ExecutorService`)。The executor.
返回Returns WorkspaceTaskRepository
返回WorkspaceTaskRepository。Returns workspace task repository.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:208–212

setCompletionCallback

public void setCompletionCallback(TaskCompletionCallback callback)

设置补全回调。

Sets the completion callback.

参数Parameters
名称Name类型Type说明Description
callbackTaskCompletionCallback回调函数(类型 `TaskCompletionCallback`)。The callback.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:256–259

putTask

public BackgroundTask putTask(RuntimeContext rc, String taskId, String subAgentId, String sessionId, TaskRunSpec spec)

执行 putTask 方法。

Performs the put task operation.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
taskIdString任务标识(类型 `String`)。The task id.
subAgentIdString子智能体标识(类型 `String`)。The sub agent id.
sessionIdString会话标识(类型 `String`)。The session id.
specTaskRunSpec规格(类型 `TaskRunSpec`)。The spec.
返回Returns BackgroundTask
返回BackgroundTask。Returns background task.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:269–351

getTask

public BackgroundTask getTask(RuntimeContext rc, String sessionId, String taskId)

获取任务。

Returns the task.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
sessionIdString会话标识(类型 `String`)。The session id.
taskIdString任务标识(类型 `String`)。The task id.
返回Returns BackgroundTask
返回BackgroundTask。Returns background task.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:514–526

listTasks

public Collection<BackgroundTask> listTasks(RuntimeContext rc, String sessionId, TaskStatus filter)

列出任务。

Lists the tasks.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
sessionIdString会话标识(类型 `String`)。The session id.
filterTaskStatus过滤条件(类型 `TaskStatus`)。The filter.
返回Returns Collection<BackgroundTask>
返回集合。Returns collection.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:528–553

cancelTask

public boolean cancelTask(RuntimeContext rc, String sessionId, String taskId)

执行取消任务相关操作。

Performs the cancel task operation.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
sessionIdString会话标识(类型 `String`)。The session id.
taskIdString任务标识(类型 `String`)。The task id.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:555–590

findPendingDeliveries

public List<TaskDelivery> findPendingDeliveries(RuntimeContext rc, String sessionId)

查找 findPendingDeliveries。

Finds the pending deliveries.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
sessionIdString会话标识(类型 `String`)。The session id.
返回Returns List<TaskDelivery>
返回列出。Returns list.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:594–621

markDelivered

public void markDelivered(RuntimeContext rc, String sessionId, String taskId)

执行 markDelivered 方法。

Stamps deliveredAt on the persisted record.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
sessionIdString会话标识(类型 `String`)。The session id.
taskIdString任务标识(类型 `String`)。The task id.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:630–640

isDelivered

public boolean isDelivered(RuntimeContext rc, String sessionId, String taskId)

判断是否 isDelivered。

Returns whether the delivered.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
sessionIdString会话标识(类型 `String`)。The session id.
taskIdString任务标识(类型 `String`)。The task id.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:642–649

shutdown

public void shutdown()

关闭资源并释放连接。

Releases resources and connections.

源码Source io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java:651–675

继承成员Inherited Members

继承自Members inherited from TaskRepository
基于官方固定版本源码静态生成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.