Decision methods are optional workflow phases that determine whether and how the workflow should proceed. Multiple decision methods can be defined and can be intermixed with actions to create conditional branching logic.
Execution Order
The execution order of @Decision and @Action methods is
determined by the following precedence rules, applied in order:
@Priorityon the method — the annotation value is the sort key; lower values execute first.order()attribute — used as the sort key when@Priorityis absent on the method; lower values execute first.- Source declaration order — used when no action
or decision method in the agent declares either
@Priorityor an explicitorder. In this case, methods execute in the order they are declared in the source code. Note that Java SE does not guarantee that reflection returns methods in source declaration order. However, all major JVM implementations do so in practice. Portable applications that require a strict, guaranteed execution order must use@Priorityororder.
@Decision or
@Action method in an agent declares an explicit order
or @Priority, every @Decision and @Action method
in that agent must do the same. Mixing explicitly ordered and unordered
methods is a deployment error.
Decision methods typically use a LargeLanguageModel to analyze the
workflow state and make intelligent decisions.
Parameters
Decision methods can have the following types of parameters that will be
automatically resolved:
- Workflow state domain objects - Any objects used by prior phases in the workflow, particularly the triggering event object
LargeLanguageModel- LLM instance- Any other CDI injectable dependencies available to the agent - typically in the application scope or managed by the container
Parameters can declare Jakarta Validation constraints (e.g., @Valid,
@NotNull, @Email). Validation occurs before the decision
method is invoked. Validation failures raise
jakarta.validation.ConstraintViolationException, which can be
handled by @HandleException methods.
Return types
Decision methods support multiple return patterns:
- Boolean:
truemeans proceed with the workflow,falsemeans stop the workflow Result: AResultrecord with success flag and optional details to control workflow and pass data to subsequent phases- Object: A non-null object means proceed (and
the object is available for injection into subsequent phases),
nullmeans stop the workflow
Examples
// Boolean return
@Decision
public boolean shouldGenerateDocs(PullRequest pr) {
String response = llm.query(
"Does this PR require documentation updates?",
pr);
return response.contains("yes");
}
// Result return - provides structured outcome
@Decision
public Result checkFraud(BankTransaction transaction) {
String output = llm.query(
"Is this a fraudulent transaction?", transaction);
boolean fraud = isFraud(output);
Fraud details = fraud ? getFraudDetails(output) : null;
return new Result(fraud, details);
}
// Object return - provides data for next phases
@Decision
public DocumentationPlan planDocumentation(PullRequest pr) {
String analysis = llm.query(
"Analyze what documentation is needed for this pull request",
pr);
if (analysis.contains("no documentation needed")) {
return null; // Stop workflow
}
return new DocumentationPlan(analysis); // Proceed with this plan
}
// Later phases can receive the decision result
@Action
public void generateDocs(DocumentationPlan plan) {
// Use the plan from the decision phase
createDocumentation(plan.getFiles(), plan.getContent());
}
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintThe position of this decision in the workflow execution sequence.
-
Element Details
-
order
int orderThe position of this decision in the workflow execution sequence. Lower values execute first.Ignored when
@Priorityis also present on the method —@Prioritytakes precedence.Defaults to
0. When all@Decisionand@Actionmethods in an agent use the default value, source declaration order determines execution order. If any method in the agent explicitly setsorderor declares@Priority, all other@Decisionand@Actionmethods in that agent must also declare one.- Returns:
- the sort key for this decision; lower values execute first
- Default:
- 0
-