Font Size:
Ask Joget AI

BeanShell Tool

Introduction

The BeanShell Tool allows you to define custom Java-based functions that can be invoked from within your AI agent using function calls. This gives you the flexibility to extend your agent's capabilities with programmable logic, calculations, or utilities, entirely outside the AI model itself.

BeanShell Tools are designed for function-style reusability. You can define multiple tools that accept arguments, process them using Java logic, and return results to the AI agent.

Get started

How to use it

To use the BeanShell Element:

Adding the BeanShell tools

  1. Locate the BeanShell element under the Tools section in the palette.
  2. Drag and drop the element into the Drop a tool to here section.

Configure Form Properties

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

  • Function Name: Unique name used to call this tool function from the AI agent.
  • Function Description: Human-readable explanation of what this function does.
  • Function Arguments: Define the expected input parameters for this function.
    • Name: The variable name of the argument (used in the script).
    • Data Type: Expected type (e.g., String, Number, Boolean).
    • Description: Purpose or meaning of the argument.
    • Is Required?: Whether the argument must be provided.
  • Script: BeanShell (Java-like) code implementing the logic. Use argument names as variables. Return your result using the return keyword.

Example: Using Function Arguments in BeanShell

To demonstrate how to pass function arguments into a BeanShell script, use the following script when configuring the BeanShell Tool in the configuration page:

import org.joget.commons.util.LogUtil;

//"arguments" is a JSONObject

String username = arguments.getString("username");
Integer pageNumber = arguments.getInt("page_number");
Boolean sortDesc = arguments.getBoolean("sort_desc");

LogUtil.info("retrieve_task_list", "username: " + username);
LogUtil.info("retrieve_task_list", "page_number: " + pageNumber);
LogUtil.info("retrieve_task_list", "sort_desc: " + sortDesc);

return "ok";

The following is the log from the BeanShell script:

INFO  15 Jan 2026 17:38:59 retrieve_task_list - username: admin
INFO  15 Jan 2026 17:38:59 retrieve_task_list - page_number: 1
INFO  15 Jan 2026 17:38:59 retrieve_task_list - sort_desc: true

Created by Gabriel Last modified by Debanraj Ravindran on Apr 24, 2026