Class ToolDefinition
java.lang.Object
group.worldstandard.pudel.api.agent.ToolDefinition
Definition of an agent tool.
A tool definition contains all metadata about a tool and its executor. Tools can be created either from @AgentTool annotated methods or programmatically using the builder.
Example using builder:
ToolDefinition tool = ToolDefinition.builder()
.name("search_web")
.description("Search the web for information")
.parameter("query", String.class, "The search query", true)
.parameter("limit", Integer.class, "Max results", false)
.keyword("search")
.keyword("find")
.keyword("lookup")
.executor((context, params) -> {
String query = (String) params.get("query");
int limit = (Integer) params.getOrDefault("limit", 5);
return "Results for: " + query;
})
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for constructing ToolDefinition instances.static final recordRepresents a parameter for a tool, defining its characteristics such as name, type, description, whether it is required, and its default value. -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolDefinition.Builderbuilder()Creates and returns a new instance of theToolDefinition.Builderclass for constructingToolDefinitioninstances.execute(AgentToolContext context, Map<String, Object> parameters) Execute this tool with the given context and parameters.Returns the description of this tool definition.Returns the set of keywords associated with this tool definition.getName()Returns the name of this object.Returns the list of parameters defined for this tool.Returns the permission level required to use this tool.Returns the unique identifier of the plugin that provides this tool.intReturns the priority level assigned to this tool definition.booleanisAvailableIn(AgentToolContext context) Determines if this tool is available for use within the specified execution context.booleanisDmOnly()Indicates whether this tool can only be used within a direct message context.booleanIndicates whether this tool can only be used within a guild context.toString()Returns a string representation of this ToolDefinition object.
-
Method Details
-
getName
-
getDescription
Returns the description of this tool definition. The description provides a human-readable explanation of what the tool does and is used by the AI agent to determine when to use this tool.- Returns:
- the description string
-
getPluginId
Returns the unique identifier of the plugin that provides this tool.- Returns:
- the plugin ID as a String
-
getParameters
Returns the list of parameters defined for this tool. Each parameter specifies its name, type, description, whether it is required, and its default value if applicable.- Returns:
- a list of ToolParameter objects representing the tool's parameters
-
getKeywords
Returns the set of keywords associated with this tool definition. Keywords are used by the AI agent to identify and match user intent when determining which tool to invoke. These keywords help improve the accuracy and relevance of tool selection during agent execution.- Returns:
- a set of keyword strings associated with this tool
-
isGuildOnly
public boolean isGuildOnly()Indicates whether this tool can only be used within a guild context. When true, the tool is restricted to execution in guild channels only.- Returns:
- true if the tool requires a guild context, false otherwise
-
isDmOnly
public boolean isDmOnly()Indicates whether this tool can only be used within a direct message context. When true, the tool is restricted to execution in private channels only.- Returns:
- true if the tool requires a direct message context, false otherwise
-
getPermission
Returns the permission level required to use this tool. The permission level determines which users are allowed to execute the tool based on their role or privileges within the guild or system.- Returns:
- the required permission level as defined in
AgentTool.ToolPermission
-
getPriority
public int getPriority()Returns the priority level assigned to this tool definition. The priority determines the order in which tools are considered when multiple tools match a given request. Higher values indicate higher priority and thus a greater likelihood of being selected.- Returns:
- the priority level as an integer
-
execute
Execute this tool with the given context and parameters.- Parameters:
context- the execution contextparameters- the tool parameters- Returns:
- the tool result as a string
-
isAvailableIn
Determines if this tool is available for use within the specified execution context. Availability is determined by the tool's configuration for guild-only or DM-only usage. If the tool is configured as guild-only, it will only be available in guild contexts. If configured as DM-only, it will only be available in direct message contexts.- Parameters:
context- the execution context in which tool availability is being checked- Returns:
- true if the tool can be used in the given context, false otherwise
-
builder
Creates and returns a new instance of theToolDefinition.Builderclass for constructingToolDefinitioninstances. The builder provides a fluent API for setting various properties of the tool definition such as name, description, plugin ID, parameters, keywords, context restrictions, permissions, priority, and execution logic.- Returns:
- a new Builder instance initialized with default values
-
toString
-