Interface TaskRepository

All Known Implementing Classes:
WorkspaceTaskRepository

public interface TaskRepository
Repository for managing background subagent tasks, scoped by session.

All operations are scoped to a sessionId so that tasks from different parent sessions are isolated from one another. Implementations may ignore sessionId (in-memory stores) or use it to partition durable storage (workspace-backed stores).

Every method accepts a RuntimeContext: implementations that persist task state through a per-user namespaced filesystem must propagate rc so that writes from concurrent users land in their respective namespaces.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Callback invoked when a background task reaches a terminal state (COMPLETED or FAILED).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    RuntimeContext flag for callers that retain execution ownership and collect results themselves.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    cancelTask(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
    Cancel a running task by session and task ID.
    findPendingDeliveries(io.agentscope.core.agent.RuntimeContext rc, String sessionId)
    Returns terminal-state tasks for the given session whose completions have not yet been pushed back to the parent agent.
    getTask(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
    Retrieve a background task by session and task ID, or null if not found.
    default boolean
    isDelivered(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
    Whether the given task has already been delivered to the parent agent.
    listTasks(io.agentscope.core.agent.RuntimeContext rc, String sessionId, TaskStatus filter)
    List all tracked tasks for the given session, optionally filtered by status.
    default void
    markDelivered(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
    Stamps the given task as delivered so it does not get pushed again.
    putTask(io.agentscope.core.agent.RuntimeContext rc, String taskId, String subAgentId, String sessionId, TaskRunSpec spec)
    Submit a new background task according to TaskRunSpec.
    default void
    Registers a callback invoked when any task reaches a terminal state (COMPLETED or FAILED).
    default void
    Shuts down background executors owned by this repository.
  • Field Details

    • SUPPRESS_COMPLETION_CALLBACK

      static final String SUPPRESS_COMPLETION_CALLBACK
      RuntimeContext flag for callers that retain execution ownership and collect results themselves.
      See Also:
  • Method Details

    • getTask

      BackgroundTask getTask(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
      Retrieve a background task by session and task ID, or null if not found.
      Parameters:
      rc - the current call's runtime context; may be RuntimeContext.empty()
      sessionId - the parent session scope
      taskId - unique task identifier
    • putTask

      BackgroundTask putTask(io.agentscope.core.agent.RuntimeContext rc, String taskId, String subAgentId, String sessionId, TaskRunSpec spec)
      Submit a new background task according to TaskRunSpec.

      Implementations should capture rc so that the background execution thread can persist task state under the originating user's namespace.

      Parameters:
      rc - the current call's runtime context; may be RuntimeContext.empty()
      taskId - unique identifier for the task
      subAgentId - the subagent type executing this task
      sessionId - the parent session scope
      spec - local supplier execution or remote HTTP task protocol
      Returns:
      the created background task
    • listTasks

      Collection<BackgroundTask> listTasks(io.agentscope.core.agent.RuntimeContext rc, String sessionId, TaskStatus filter)
      List all tracked tasks for the given session, optionally filtered by status.
      Parameters:
      rc - the current call's runtime context; may be RuntimeContext.empty()
      sessionId - the parent session scope
      filter - if non-null, only return tasks with this status; null returns all tasks
    • cancelTask

      boolean cancelTask(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
      Cancel a running task by session and task ID.
      Parameters:
      rc - the current call's runtime context; may be RuntimeContext.empty()
      Returns:
      true if the task was found and cancellation was attempted
    • findPendingDeliveries

      default List<TaskDelivery> findPendingDeliveries(io.agentscope.core.agent.RuntimeContext rc, String sessionId)
      Returns terminal-state tasks for the given session whose completions have not yet been pushed back to the parent agent.

      Implementations should order the result deterministically (typically by completion time ascending) so the parent agent sees deliveries in the order they actually happened.

      Default returns an empty list — in-memory repositories do not currently support push.

    • markDelivered

      default void markDelivered(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
      Stamps the given task as delivered so it does not get pushed again. Idempotent: calling twice has no effect after the first call.

      Default is a no-op.

    • isDelivered

      default boolean isDelivered(io.agentscope.core.agent.RuntimeContext rc, String sessionId, String taskId)
      Whether the given task has already been delivered to the parent agent. Used by SubagentsMiddleware.buildTaskSummary(io.agentscope.harness.agent.subagent.task.TaskRepository, io.agentscope.core.agent.RuntimeContext) to omit already-delivered terminal tasks from the SYSTEM-prompt summary.

      Default returns false.

    • setCompletionCallback

      default void setCompletionCallback(TaskRepository.TaskCompletionCallback callback)
      Registers a callback invoked when any task reaches a terminal state (COMPLETED or FAILED). Used by SubagentsMiddleware to push results to the session inbox and enqueue a wakeup signal. The result argument is null for failed tasks.

      Callers retaining execution ownership can set SUPPRESS_COMPLETION_CALLBACK in their RuntimeContext to suppress inbox/wakeup callbacks while preserving durable results. Implementations supporting this callback should honor the flag.

      Default is a no-op. Implementations that support push delivery should override.

    • shutdown

      default void shutdown()
      Shuts down background executors owned by this repository. Default is a no-op.