Class BackgroundTask
java.lang.Object
io.agentscope.harness.agent.subagent.task.BackgroundTask
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 executingcreatedAt— when the task was createdlastCheckedAt— when the task status was last polled
-
Constructor Summary
ConstructorsConstructorDescriptionBackgroundTask(String taskId, String agentId, CompletableFuture<String> future) -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) Cancels the task.getError()Non-blocking result peek; returns null if not yet completed or if an error occurred.Returns a human-readable status string.Returns the structuredTaskStatusfor this task, reflecting the underlying future state and any explicit cancellation.booleanvoidbooleanwaitForCompletion(long timeoutMs) Blocks until the task completes or the timeout elapses.whenComplete(BiConsumer<String, Throwable> action) Observe the backing future; workspace local tasks persist their result before resolving it.
-
Constructor Details
-
BackgroundTask
-
-
Method Details
-
whenComplete
Observe the backing future; workspace local tasks persist their result before resolving it. -
getTaskId
-
getAgentId
-
getCreatedAt
-
getLastCheckedAt
-
updateLastCheckedAt
public void updateLastCheckedAt() -
isCompleted
public boolean isCompleted() -
getTaskStatus
Returns the structuredTaskStatusfor this task, reflecting the underlying future state and any explicit cancellation. -
getStatus
Returns a human-readable status string. -
getResult
Non-blocking result peek; returns null if not yet completed or if an error occurred. -
getError
-
waitForCompletion
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 thatgetTaskStatus()returnsTaskStatus.CANCELLEDeven if the future cannot be interrupted.
-