001/* 002 * Copyright (c) 2026, Oracle and/or its affiliates. 003 * 004 * Licensed under the Universal Permissive License Version 1.0 as shown at 005 * https://oss.oracle.com/licenses/upl/ 006 */ 007package com.oracle.database.selectai.agent; 008 009import com.oracle.database.selectai.model.agent.ToolAttributes; 010import com.oracle.database.selectai.model.agent.ToolRunResult; 011import com.oracle.database.selectai.model.agent.ToolStatus; 012import com.oracle.database.selectai.model.SelectAIException; 013 014/** 015 * Contract for Select AI agent tool lifecycle, description, and execution 016 * operations. 017 * <p> 018 * A tool is a database-side resource managed by the 019 * {@code DBMS_CLOUD_AI_AGENT} PL/SQL package. Tools expose callable 020 * functionality to agents or teams and may define an input schema. 021 * <p> 022 * A {@code Tool} instance can represent an existing database tool or be 023 * configured for creation. The name-only {@link SelectAIAgent#tool(String)} 024 * factory verifies that the tool exists and loads its metadata and attributes 025 * before returning. {@link SelectAIAgent#listTools()} also returns handles with 026 * loaded metadata and attributes. A handle configured for creation is obtained with 027 * {@link SelectAIAgent#tool(String, ToolAttributes, String, ToolStatus)}. 028 * <p> 029 * A creation-configured handle retains its supplied attributes, description, 030 * and status without querying the database. Only such a handle can call 031 * {@link #create()}; after creation succeeds, it becomes database-backed. 032 * {@link #enable()}, {@link #disable()}, {@link #drop(boolean)}, 033 * {@link #describe()}, and {@link #run(String)} require an existing 034 * database-side tool. 035 * Existing tools can update individual attributes with 036 * {@link #setAttribute(String, String)} or multiple attributes with 037 * {@link #setAttributes(ToolAttributes)}; both operations reload the typed 038 * attributes after the database update succeeds. 039 * <p> 040 * Before creation, {@link #getStatus()} and {@link #getToolAttributes()} return 041 * the configured values. For a database-backed handle, each call to either 042 * method queries the database. {@code getStatus()} does not change the 043 * description returned by {@link #getDescription()}. The description is 044 * supplied or loaded when the handle is initialized; {@code getDescription()} 045 * does not query the database. Use {@link #describe()} to retrieve 046 * the database-generated tool definition. 047 * <p> 048 * Names and required Java arguments are checked locally. Loading metadata and 049 * executing tool operations require database access; the database checks 050 * privileges and validates tool attributes when they are submitted. The input 051 * supplied to {@link #run(String)} must be a JSON payload accepted by the 052 * configured tool; the Java method checks only that it is not null or blank. 053 * <p> 054 * For a complete runnable example, see 055 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateToolSample.html"> 056 * CreateToolSample source</a>. 057 * 058 * @see SelectAIAgent 059 * @see <a href="https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/dbms-cloud-ai-agent-package.html"> 060 * DBMS_CLOUD_AI_AGENT package documentation</a> 061 * @since 1.1.0 062 */ 063public interface Tool { 064 /** 065 * Creates this creation-configured tool in the database. 066 * For a runnable example, see 067 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateToolSample.html"> 068 * CreateToolSample source</a>. 069 * 070 * @return {@code true} when the database creates the tool 071 * @throws IllegalStateException when this handle was loaded from an existing tool 072 * @throws SelectAIException when the database rejects or cannot complete the operation 073 * @see <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateSqlToolSample.html"> 074 * CreateSqlToolSample source</a> 075 * @see <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ToolParamsSample.html"> 076 * ToolParamsSample source</a> 077 * @see <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateToolWithInputsSample.html"> 078 * CreateToolWithInputsSample source</a> 079 */ 080 boolean create() throws SelectAIException; 081 /** 082 * Enables this database-backed tool. 083 * For a runnable example, see 084 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/EnableToolSample.html"> 085 * EnableToolSample source</a>. 086 * 087 * @return {@code true} when the database enables the tool 088 * @throws IllegalStateException when this tool has not been created 089 * @throws SelectAIException when the database operation fails 090 */ 091 boolean enable() throws SelectAIException; 092 /** 093 * Disables this database-backed tool. 094 * For a runnable example, see 095 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/DisableToolSample.html"> 096 * DisableToolSample source</a>. 097 * 098 * @return {@code true} when the database disables the tool 099 * @throws IllegalStateException when this tool has not been created 100 * @throws SelectAIException when the database operation fails 101 */ 102 boolean disable() throws SelectAIException; 103 /** 104 * Drops this database-backed tool. When {@code force} is {@code true}, 105 * the operation may be retried after the handle has already been dropped; 106 * the database force-drop semantics determine the result. 107 * For a runnable example, see 108 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/DropToolSample.html"> 109 * DropToolSample source</a>. 110 * 111 * @param force database force-drop option 112 * @return {@code true} when the drop completes 113 * @throws IllegalStateException when {@code force} is {@code false} and 114 * this tool has not been created 115 * @throws SelectAIException when the database operation fails 116 */ 117 boolean drop(boolean force) throws SelectAIException; 118 119 /** 120 * Updates one tool attribute in the database. 121 * For a runnable example, see 122 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetToolAttributeSample.html"> 123 * SetToolAttributeSample source</a>. 124 * 125 * @param attributeName database tool attribute name 126 * @param attributeValue string value, or {@code null} where supported 127 * @return {@code true} when the update succeeds 128 * @throws IllegalArgumentException when {@code attributeName} is null or blank 129 * @throws IllegalStateException when this tool has not been created 130 * @throws SelectAIException when the database update fails 131 */ 132 boolean setAttribute(String attributeName, String attributeValue) throws SelectAIException; 133 134 /** 135 * Updates one boolean tool attribute in the database. 136 * For a runnable example, see 137 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetToolAttributeSample.html"> 138 * SetToolAttributeSample source</a>. 139 * 140 * @param attributeName database tool attribute name 141 * @param attributeValue boolean value 142 * @return {@code true} when the update succeeds 143 * @throws IllegalArgumentException when {@code attributeName} is null or blank 144 * @throws IllegalStateException when this tool has not been created 145 * @throws SelectAIException when the database update fails 146 */ 147 boolean setAttribute(String attributeName, boolean attributeValue) throws SelectAIException; 148 149 /** 150 * Updates one integer tool attribute in the database. 151 * For a runnable example, see 152 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetToolAttributeSample.html"> 153 * SetToolAttributeSample source</a>. 154 * 155 * @param attributeName database tool attribute name 156 * @param attributeValue integer value 157 * @return {@code true} when the update succeeds 158 * @throws IllegalArgumentException when {@code attributeName} is null or blank, 159 * or {@code attributeValue} is null 160 * @throws IllegalStateException when this tool has not been created 161 * @throws SelectAIException when the database update fails 162 */ 163 boolean setAttribute(String attributeName, Integer attributeValue) throws SelectAIException; 164 165 /** 166 * Updates one floating-point tool attribute in the database. 167 * For a runnable example, see 168 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetToolAttributeSample.html"> 169 * SetToolAttributeSample source</a>. 170 * 171 * @param attributeName database tool attribute name 172 * @param attributeValue floating-point value 173 * @return {@code true} when the update succeeds 174 * @throws IllegalArgumentException when {@code attributeName} is null or blank, 175 * or {@code attributeValue} is null 176 * @throws IllegalStateException when this tool has not been created 177 * @throws SelectAIException when the database update fails 178 */ 179 boolean setAttribute(String attributeName, Float attributeValue) throws SelectAIException; 180 181 /** 182 * Updates multiple tool attributes in one database operation. 183 * For a runnable example, see 184 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetToolAttributesSample.html"> 185 * SetToolAttributesSample source</a>. 186 * 187 * @param toolAttributes tool attributes to update 188 * @return {@code true} when the update succeeds 189 * @throws IllegalArgumentException when {@code toolAttributes} is null 190 * @throws IllegalStateException when this tool has not been created 191 * @throws SelectAIException when the database update fails 192 * @see <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetSqlToolParamsSample.html"> 193 * SetSqlToolParamsSample source</a> 194 * @see <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetToolInputsSample.html"> 195 * SetToolInputsSample source</a> 196 */ 197 boolean setAttributes(ToolAttributes toolAttributes) throws SelectAIException; 198 199 /** 200 * Returns the database-generated tool definition and input metadata as raw JSON. 201 * For a runnable example, see 202 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/DescribeToolSample.html"> 203 * DescribeToolSample source</a>. 204 * 205 * @return JSON returned by the database package 206 * @throws IllegalStateException when this tool has not been created 207 * @throws SelectAIException when the database operation fails 208 */ 209 String describe() throws SelectAIException; 210 /** 211 * Runs this tool with a JSON input payload. 212 * <p> 213 * The SDK checks only that the payload is non-null and non-blank. The 214 * configured tool and database validate the JSON shape and its values. 215 * For a runnable example, see 216 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/RunToolSample.html"> 217 * RunToolSample source</a>. 218 * 219 * @param inputJson JSON input accepted by the configured tool 220 * @return typed result retaining the raw value returned by the database package 221 * @throws IllegalArgumentException when {@code inputJson} is null or blank 222 * @throws IllegalStateException when this tool has not been created 223 * @throws SelectAIException when the database operation fails 224 */ 225 ToolRunResult run(String inputJson) throws SelectAIException; 226 /** 227 * Returns the configured or database-reported tool name without database access. 228 * For a runnable example, see 229 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadToolSample.html"> 230 * LoadToolSample source</a>. 231 * 232 * @return configured or database-reported tool name 233 */ 234 String getToolName(); 235 /** 236 * Returns the description supplied or loaded when this handle was initialized. 237 * This method does not access the database and the value is not changed by 238 * {@link #getStatus()}. 239 * For a runnable example, see 240 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadToolSample.html"> 241 * LoadToolSample source</a>. 242 * 243 * @return supplied or loaded tool description, or {@code null} when absent 244 */ 245 String getDescription(); 246 /** 247 * Returns the configured status before creation or the current database 248 * status for an existing tool. A pending tool with no configured status 249 * returns {@code null}. This method does not change the description. 250 * For a runnable example, see 251 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadToolSample.html"> 252 * LoadToolSample source</a>. 253 * 254 * @return configured or current tool status 255 * @throws SelectAIException when current tool metadata cannot be fetched 256 */ 257 ToolStatus getStatus() throws SelectAIException; 258 /** 259 * Returns tool attributes for this handle. 260 * <p> 261 * For a database-backed tool, this method reloads the attributes from the 262 * database on each call and therefore can fail if the resource was deleted. 263 * For a creation-configured tool, it returns the configured attributes 264 * without querying the database. 265 * Built-in tool parameters use immutable 266 * {@link com.oracle.database.selectai.model.agent.ToolParams} models. 267 * Input metadata is exposed as immutable 268 * {@link com.oracle.database.selectai.model.agent.ToolInput} entries. 269 * Unknown parameter fields and newer database schemas are preserved. 270 * For a runnable example, see 271 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadToolSample.html"> 272 * LoadToolSample source</a>. 273 * 274 * @return current tool attributes for an existing tool, or configured 275 * attributes for a tool pending creation 276 * @throws SelectAIException when the tool no longer exists or current attributes cannot be fetched 277 */ 278 ToolAttributes getToolAttributes() throws SelectAIException; 279}