Class TaskTemplate<R>

Object
akka.javasdk.agent.task.TaskTemplate<R>
Type Parameters:
R - The result type produced when the task completes.
All Implemented Interfaces:
TaskDefinition<R>

public final class TaskTemplate<R> extends Object implements TaskDefinition<R>
A task definition with a parameterized instruction template. Template parameters use {paramName} syntax and are resolved via params(Map) to produce a submittable Task.

Use define(String) to create a template, then resultConformsTo(Class) to set the result type and instructionTemplate(String) to set the template string. Templates are immutable and typically declared as static final constants.

At request time, resolve the template with params(Map) or override it entirely with instructions(String).

  • Method Details

    • define

      public static TaskTemplate<String> define(String name)
      Define a new task template 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 TaskTemplate<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>
    • resultConformsTo

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

      public TaskTemplate<R> instructionTemplate(String template)
      Set the instruction template with {paramName} placeholders.
    • instructionTemplate

      public String instructionTemplate()
      The instruction template string with {paramName} placeholders.
    • templateParameterNames

      public List<String> templateParameterNames()
      Extract parameter names from the template.
    • 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 TaskTemplate<R> rules(Class<? extends TaskRule<R>> firstRule, Class<? extends TaskRule<R>>... moreRules)
      Return a new task template with the given rules. Rules carry through to any Task produced by params(java.util.Map<java.lang.String, java.lang.String>) or instructions(java.lang.String).
    • params

      public Task<R> params(Map<String,String> templateParams)
      Resolve the template with named parameters, returning a submittable Task.
      Parameters:
      templateParams - parameter values keyed by name
      Throws:
      IllegalArgumentException - if a template parameter has no value in the map
    • instructions

      public Task<R> instructions(String instructions)
      Override the template with free-form instructions, returning a submittable Task.