Class BackgroundTask

java.lang.Object
io.agentscope.harness.agent.subagent.task.BackgroundTask

public class BackgroundTask extends Object
Wraps a CompletableFuture to track background subagent task execution with status, result, error, and lifecycle metadata. Thread-safe by delegation to the underlying future.

Lifecycle metadata:

  • agentId — which subagent type is executing
  • createdAt — when the task was created
  • lastCheckedAt — when the task status was last polled
  • Constructor Details

  • Method Details

    • whenComplete

      public BackgroundTask whenComplete(BiConsumer<String,Throwable> action)
      Observe the backing future; workspace local tasks persist their result before resolving it.
    • getTaskId

      public String getTaskId()
    • getAgentId

      public String getAgentId()
    • getCreatedAt

      public Instant getCreatedAt()
    • getLastCheckedAt

      public Instant getLastCheckedAt()
    • updateLastCheckedAt

      public void updateLastCheckedAt()
    • isCompleted

      public boolean isCompleted()
    • getTaskStatus

      public TaskStatus getTaskStatus()
      Returns the structured TaskStatus for this task, reflecting the underlying future state and any explicit cancellation.
    • getStatus

      public String getStatus()
      Returns a human-readable status string.
    • getResult

      public String getResult()
      Non-blocking result peek; returns null if not yet completed or if an error occurred.
    • getError

      public Exception getError()
    • waitForCompletion

      public boolean waitForCompletion(long timeoutMs) throws InterruptedException
      Blocks until the task completes or the timeout elapses.
      Returns:
      true if completed within timeout, false if timed out
      Throws:
      InterruptedException
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Cancels the task. Sets the internal cancelled flag so that getTaskStatus() returns TaskStatus.CANCELLED even if the future cannot be interrupted.