Interface TaskClient
Not for user extension or instantiation, returned by the SDK component client.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAssign a task to an owner.CompletionStage<akka.Done> assignAsync(String assignee) Async variant ofassign(java.lang.String).default <R> voidcomplete(TaskDefinition<R> taskDefinition, R result) Complete a task with a typed result.<R> CompletionStage<akka.Done> completeAsync(TaskDefinition<R> taskDefinition, R result) Async variant ofcomplete(akka.javasdk.agent.task.TaskDefinition<R>, R).default <R> StringCreate a task entity.<R> CompletionStage<String> createAsync(Task<R> task) Async variant ofcreate(akka.javasdk.agent.task.Task<R>).default voidFail a task with a reason.CompletionStage<akka.Done> Async variant offail(java.lang.String).default <R> TaskSnapshot<R> get(TaskDefinition<R> taskDefinition) Get a point-in-time snapshot of the task's current state.<R> CompletionStage<TaskSnapshot<R>> getAsync(TaskDefinition<R> taskDefinition) Async variant ofget(akka.javasdk.agent.task.TaskDefinition<R>).akka.stream.javadsl.Source<TaskNotification, akka.NotUsed> Subscribe to notifications published by the task entity.default <R> Rresult(TaskDefinition<R> taskDefinition) Blocks until the task reaches a terminal state and returns the typed result.<R> CompletionStage<R> resultAsync(TaskDefinition<R> taskDefinition) Async variant ofresult(akka.javasdk.agent.task.TaskDefinition<R>).
-
Method Details
-
create
Create a task entity. The task definition provides the type, description, and instructions. Returns the task ID (the same ID this client was created with).- Type Parameters:
R- the result type of the task- Parameters:
task- the task to create, with instructions and any attachments- Returns:
- the task ID
-
createAsync
Async variant ofcreate(akka.javasdk.agent.task.Task<R>).- Type Parameters:
R- the result type of the task- Parameters:
task- the task to create, with instructions and any attachments- Returns:
- a CompletionStage with the task ID
-
assign
Assign a task to an owner. A task must be assigned before it can be completed or failed. For agent-processed tasks, assignment is handled by the runtime. For tasks completed by humans or other processes, the application assigns the task via this method.- Parameters:
assignee- identifier of the owner (e.g., a user ID, team name, or process identifier)
-
assignAsync
Async variant ofassign(java.lang.String).- Parameters:
assignee- identifier of the owner (e.g., a user ID, team name, or process identifier)- Returns:
- a CompletionStage that completes when the task has been assigned
-
complete
Complete a task with a typed result. The task must be assigned first (viaassign(java.lang.String)or by the agent runtime). For tasks not yet in progress, completion is allowed directly from the assigned state — no separate start step is needed.- Type Parameters:
R- the result type of the task- Parameters:
taskDefinition- the task definition, used for result type validationresult- the task result
-
completeAsync
Async variant ofcomplete(akka.javasdk.agent.task.TaskDefinition<R>, R).- Type Parameters:
R- the result type of the task- Parameters:
taskDefinition- the task definition, used for result type validationresult- the task result- Returns:
- a CompletionStage that completes when the task has been completed
-
fail
Fail a task with a reason. The task must be assigned first (viaassign(java.lang.String)or by the agent runtime).- Parameters:
reason- the failure reason
-
failAsync
Async variant offail(java.lang.String).- Parameters:
reason- the failure reason- Returns:
- a CompletionStage that completes when the task has been failed
-
get
Get a point-in-time snapshot of the task's current state.The supplied
TaskDefinitionis validated against the task entity: if its name or result type does not match the definition the task was created with,TaskException.TypeMismatchis thrown. This guards against accidentally reading a task with the wrong definition (for example, callingforTask(taskId).get(OtherTasks.SOMETHING_ELSE)on an id that was created with a different task) and ensures the returned result can be safely deserialized asR.- Type Parameters:
R- the result type of the task- Parameters:
taskDefinition- the task definition, used for typed result deserialization- Returns:
- the task snapshot containing status and typed result
- Throws:
TaskException.TypeMismatch- if the task's name or result type does not matchtaskDefinition
-
getAsync
Async variant ofget(akka.javasdk.agent.task.TaskDefinition<R>).The returned CompletionStage fails with
TaskException.TypeMismatchif the task's name or result type does not matchtaskDefinition.- Type Parameters:
R- the result type of the task- Parameters:
taskDefinition- the task definition, used for typed result deserialization- Returns:
- a CompletionStage with the task snapshot containing status and typed result
-
result
Blocks until the task reaches a terminal state and returns the typed result.As with
get(akka.javasdk.agent.task.TaskDefinition<R>), the suppliedTaskDefinitionis validated against the task entity.- Type Parameters:
R- the result type of the task- Parameters:
taskDefinition- the task definition, used for typed result deserialization- Returns:
- the typed task result
- Throws:
TaskException.Failed- if the task failedTaskException.Cancelled- if the task was cancelledTaskException.TypeMismatch- if the task's name or result type does not matchtaskDefinition
-
resultAsync
Async variant ofresult(akka.javasdk.agent.task.TaskDefinition<R>).The returned CompletionStage fails with
TaskException.Failedif the task failed,TaskException.Cancelledif it was cancelled, orTaskException.TypeMismatchif the task's name or result type does not matchtaskDefinition.- Type Parameters:
R- the result type of the task- Parameters:
taskDefinition- the task definition, used for typed result deserialization- Returns:
- a CompletionStage with the typed task result
-
notificationStream
akka.stream.javadsl.Source<TaskNotification,akka.NotUsed> notificationStream()Subscribe to notifications published by the task entity. SeeTaskNotificationfor the event catalog.- Returns:
- a source of task notification events
-