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>

public final class Task<R> extends Object implements 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 Details

    • name

      public static Task<String> name(String name)
      Define a new task with the given name. The name is a stable identifier for this task type. The default result type is String; call resultConformsTo(Class) to change it.
      Parameters:
      name - a stable identifier for this task type
    • name

      public String name()
      Description copied from interface: TaskDefinition
      The name of this task definition — a stable identifier for the task type.
      Specified by:
      name in interface TaskDefinition<R>
    • description

      public String description()
      Description copied from interface: TaskDefinition
      The description of this task — what kind of work it represents.
      Specified by:
      description in interface TaskDefinition<R>
    • description

      public Task<R> description(String description)
      Set the description of this task — what kind of work it represents.
    • resultType

      public Class<R> resultType()
      Description copied from interface: TaskDefinition
      The expected result type.
      Specified by:
      resultType in interface TaskDefinition<R>
    • instructions

      public String instructions()
      Per-request instructions, or empty string if none were provided.
    • instructions

      public Task<R> instructions(String instructions)
      Return a new task with per-request instructions attached. The original task definition is unchanged.
    • attachments

      public List<MessageContent> attachments()
      Content attached to this task (images, PDFs), or an empty list.
    • attach

      public Task<R> attach(MessageContent... content)
      Return a new task with the given content items attached.
    • resultConformsTo

      public <S> Task<S> resultConformsTo(Class<S> type)
      Set the expected result type. Returns a new task with the changed type parameter.
      Type Parameters:
      S - The new result type
    • dependencyTaskIds

      public List<String> dependencyTaskIds()
      Task IDs that must complete before this task can start, or an empty list.
    • dependsOn

      public Task<R> dependsOn(String... taskIds)
      Return a new task that depends on the given task IDs. The agent will not start this task until all dependencies are completed.
    • ruleClasses

      public List<Class<? extends TaskRule<R>>> ruleClasses()
      Rule classes that validate the result before accepting completion, or an empty list.
      Specified by:
      ruleClasses in interface TaskDefinition<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.