Font Size:
Ask Joget AI

BeanShell Decision

Introduction

The BeanShell Decision runs a Java script after a task completes and uses the result to determine whether the agent continues, jumps to a different task, or stops entirely.

Before you start

No LLM service or external credentials are required. The script runs inside Joget and has access to the same variables available in other BeanShell components.

What it does

A BeanShell Decision sits on a task and runs after all Enhancers on that task have completed. You write a short Java script that examines the response and returns a routing instruction. The agent follows that instruction exactly.

The script must return one of the following routing instructions using the DecisionResult variable injected at runtime:

Return value What the agent does
DecisionResult.continueExecution() Proceed to the next task in sequence.
DecisionResult.abort() Stop the agent run immediately.
DecisionResult.goTo("task-id") Jump to a specific task by its exact ID string.
DecisionResult.goToLabel("Task Label") Jump to a task by its display label, case-insensitive.
DecisionResult.goToIndex(2) Jump to a task by its position in the agent, starting from 1.

If the script returns null or does not return a DecisionResult, the agent falls back to continueExecution().

The script receives the following variables:

Variable What it contains
response The task response object. Call response.getContent() to read the text.
DecisionResult The routing helper. Use this to build and return your instruction.
plugin The current agent plugin instance.
llm The LLM service configured for the task.
llmConfig The LLM configuration object.

Get started

How to use it

To use the BeanShell Condition Element, follow these steps:

  1. Locate the BeanShell Condition element under the Decisions section in the palette.
  2. Drag and drop the element into the Drop a decision rule to here section.

Configure Form Properties

To properly integrate and configure the Beanshell, set the following fields:

  • Personalized Names: Specify a name for the BeanShell condition.
  • Purpose: A label describing what this decision does. Not evaluated at runtime.
  • Script: The BeanShell script that determines the routing outcome. Required field.

Samples

Route based on a status field extracted from JSON:
import org.json.JSONObject;
JSONObject obj = new JSONObject(response.getContent());
String status = obj.optString("status", "unknown");
if ("error".equals(status)) {
    return DecisionResult.abort();
} else if ("pending".equals(status)) {
    return DecisionResult.goToLabel("Escalate to Manager");
}
return DecisionResult.continueExecution();
Abort when a numeric score falls below a threshold:
import org.json.JSONObject;
JSONObject obj = new JSONObject(response.getContent());
double score = obj.optDouble("confidence", 1.0);
if (score < 0.5) {
    return DecisionResult.abort();
}
return DecisionResult.continueExecution();
 

Best Practices

  • Use DecisionResult as an instance, not a class. BeanShell in an OSGi environment cannot dispatch static methods on the class directly. Always call DecisionResult.abort()DecisionResult.continueExecution(), and the other methods on the injected variable, not on a static reference.
  • Script errors halt the decision. A runtime exception in the script is treated as an agent error. Test your script logic thoroughly, especially around JSON parsing, where keys may be absent.
  • goTo requires the exact task ID. Task IDs are the internal identifiers set when the task was created, not the display labels. Use goToLabel when the label is more stable, or check the agent definition for the correct ID.
  • goToLabel is case-insensitive but literal. Spaces and punctuation in the label must match exactly.
  • Pair with a BeanShell Enhancer to prepare the response. If the response needs parsing or transformation before routing, run an enhancer first on the same task. The decision runs after all enhancers have completed.
Created by Debanraj Ravindran Last modified by Debanraj Ravindran on Jul 06, 2026