Package akka.javasdk.agent.task
Class Task<R>
Object
akka.javasdk.agent.task.Task<R>
- Type Parameters:
R- The result type produced when the task completes.
- All Implemented Interfaces:
TaskDefinition<R>
A typed task definition — describes a kind of work and the expected result type.
Use name(String) to create a definition, then resultConformsTo(Class) to set
the result type. Task definitions are immutable and typically declared as static final
constants. The default result type is String.
Per-request methods like instructions(String), attach(MessageContent...),
and dependsOn(String...) return a new instance, leaving the original definition
unchanged. This allows a single definition to be reused across many requests.
-
Method Summary
Modifier and TypeMethodDescriptionattach(MessageContent... content) Return a new task with the given content items attached.Content attached to this task (images, PDFs), or an empty list.Task IDs that must complete before this task can start, or an empty list.Return a new task that depends on the given task IDs.The description of this task — what kind of work it represents.description(String description) Set the description of this task — what kind of work it represents.Per-request instructions, or empty string if none were provided.instructions(String instructions) Return a new task with per-request instructions attached.name()The name of this task definition — a stable identifier for the task type.Define a new task with the given name.<S> Task<S> resultConformsTo(Class<S> type) Set the expected result type.The expected result type.Rule classes that validate the result before accepting completion, or an empty list.Return a new task with the given rules.
-
Method Details
-
name
Define a new task with the given name. The name is a stable identifier for this task type. The default result type isString; callresultConformsTo(Class)to change it.- Parameters:
name- a stable identifier for this task type
-
name
Description copied from interface:TaskDefinitionThe name of this task definition — a stable identifier for the task type.- Specified by:
namein interfaceTaskDefinition<R>
-
description
Description copied from interface:TaskDefinitionThe description of this task — what kind of work it represents.- Specified by:
descriptionin interfaceTaskDefinition<R>
-
description
Set the description of this task — what kind of work it represents. -
resultType
Description copied from interface:TaskDefinitionThe expected result type.- Specified by:
resultTypein interfaceTaskDefinition<R>
-
instructions
Per-request instructions, or empty string if none were provided. -
instructions
Return a new task with per-request instructions attached. The original task definition is unchanged. -
attachments
Content attached to this task (images, PDFs), or an empty list. -
attach
Return a new task with the given content items attached. -
resultConformsTo
Set the expected result type. Returns a new task with the changed type parameter.- Type Parameters:
S- The new result type
-
dependencyTaskIds
Task IDs that must complete before this task can start, or an empty list. -
dependsOn
Return a new task that depends on the given task IDs. The agent will not start this task until all dependencies are completed. -
ruleClasses
Rule classes that validate the result before accepting completion, or an empty list.- Specified by:
ruleClassesin interfaceTaskDefinition<R>
-
rules
@SafeVarargs public final Task<R> rules(Class<? extends TaskRule<R>> firstRule, Class<? extends TaskRule<R>>... moreRules) Return a new task with the given rules. Rules are evaluated in order when the task is completed. If any rule rejects the result, the task is failed instead of completed.
-