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.SelectAI;
010import com.oracle.database.selectai.impl.agent.SelectAIAgentFactory;
011import com.oracle.database.selectai.model.agent.AgentAttributes;
012import com.oracle.database.selectai.model.agent.AgentObjectType;
013import com.oracle.database.selectai.model.agent.AgentStatus;
014import com.oracle.database.selectai.model.agent.AvailableTeam;
015import com.oracle.database.selectai.model.agent.ExecutionStateRequest;
016import com.oracle.database.selectai.model.agent.ImportTeamRequest;
017import com.oracle.database.selectai.model.agent.RunTeamRequest;
018import com.oracle.database.selectai.model.agent.TaskAttributes;
019import com.oracle.database.selectai.model.agent.TaskStatus;
020import com.oracle.database.selectai.model.agent.TeamAttributes;
021import com.oracle.database.selectai.model.agent.TeamExecutionState;
022import com.oracle.database.selectai.model.agent.TeamRunResult;
023import com.oracle.database.selectai.model.agent.TeamStatus;
024import com.oracle.database.selectai.model.agent.ToolAttributes;
025import com.oracle.database.selectai.model.agent.ToolStatus;
026import com.oracle.database.selectai.model.DbConnectionConfig;
027import com.oracle.database.selectai.model.SelectAIException;
028import com.oracle.database.selectai.model.SelectAIOptions;
029
030import javax.sql.DataSource;
031import java.util.List;
032
033/**
034 * Client interface for Oracle Select AI Agent operations.
035 * <p>
036 * This interface provides access to the agent framework resources managed by
037 * {@code DBMS_CLOUD_AI_AGENT}: agents, tasks, tools, and teams. It also
038 * provides collection-level operations for listing agents, tasks, tools, and
039 * teams, executing teams, inspecting and updating team state, accessing
040 * runtime variables, retrieving object definitions, and importing team
041 * definitions.
042 * <p>
043 * Use {@code SelectAIAgent} separately from {@code SelectAI} so agent
044 * orchestration and application-facing Select AI profile operations remain
045 * explicit. Agent resources may use Select AI profiles, but creating or
046 * managing an agent resource does not create or modify a profile.
047 * <p>
048 * {@code SelectAIAgent} extends {@link AutoCloseable}. Creating a client with
049 * {@link #create(DbConnectionConfig)} opens one SDK-owned JDBC connection
050 * immediately. Call {@link #close()} when the client is no longer needed to
051 * release that connection and its database session.
052 * <p>
053 * Creating a client with {@link #create(DataSource)} does not obtain a
054 * connection immediately. The application owns the {@code DataSource}; the
055 * SDK borrows a connection for each database operation and closes that
056 * connection after use, returning pooled connections to their pool. Calling
057 * {@link #close()} does not close the caller-owned {@code DataSource}. Each
058 * operation may therefore use a different pooled connection; applications
059 * should not depend on uncommitted transaction or other session state being
060 * available to a later operation.
061 * <p>
062 * The name-only {@link #agent(String)}, {@link #task(String)},
063 * {@link #tool(String)}, and {@link #team(String)} factories verify that the
064 * current user owns the resources and load their metadata and attributes before returning.
065 * Granted cross-schema teams can be run through {@link #runTeam(String, RunTeamRequest)}
066 * without loading owner-only metadata.
067 * The owner-scoped list methods also load metadata and attributes for each
068 * returned handle. {@link #listAvailableTeams()} provides a separate read-only
069 * discovery view backed by {@code DBMS_CLOUD_AI_AGENT.LIST_TEAMS}; its results
070 * may include shared teams that cannot be opened with {@link #team(String)}.
071 * The overloads that accept attributes retain their configuration without a
072 * database query; a resource is not persisted until its {@code create()}
073 * method succeeds. For agents, required attribute values such as profile name
074 * and role are validated by the database during {@link Agent#create()}, not
075 * by the {@link AgentAttributes} builder.
076 * <p>
077 * For a complete runnable example, see
078 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateAgentSample.html">
079 * CreateAgentSample source</a>.
080 * For an end-to-end example that creates a tool, task, agent, and team, runs
081 * the team, and continues the same conversation, see
082 * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/AgentWorkflowSample.html">
083 * AgentWorkflowSample source</a>.
084 *
085 * @see SelectAI
086 * @see <a href="https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/dbms-cloud-ai-agent-package.html">
087 *      DBMS_CLOUD_AI_AGENT package documentation</a>
088 * @since 1.1.0
089 */
090public interface SelectAIAgent extends AutoCloseable {
091    /**
092     * Creates a SelectAIAgent client from database connection configuration.
093     * <p>
094     * For a runnable example, see
095     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/RunTeamSample.html">
096     * RunTeamSample source</a>.
097     *
098     * @param dbConnectionConfig database connection configuration
099     * @return SelectAIAgent client
100     * @throws IllegalArgumentException when {@code dbConnectionConfig} is null
101     * @throws SelectAIException when the database connection cannot be initialized
102     */
103    static SelectAIAgent create(DbConnectionConfig dbConnectionConfig) throws SelectAIException {
104        return SelectAIAgentFactory.create(dbConnectionConfig);
105    }
106
107    /**
108     * Creates a SelectAIAgent client from database connection configuration and
109     * SDK execution options.
110     * <p>
111     * For a runnable example, see
112     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateSelectAIAgentWithOptionsSample.html">
113     * CreateSelectAIAgentWithOptionsSample source</a>.
114     *
115     * @param dbConnectionConfig database connection configuration
116     * @param options SDK execution options; {@code null} uses defaults
117     * @return SelectAIAgent client
118     * @throws IllegalArgumentException when {@code dbConnectionConfig} is null
119     * @throws SelectAIException when the database connection cannot be initialized
120     */
121    static SelectAIAgent create(DbConnectionConfig dbConnectionConfig, SelectAIOptions options)
122            throws SelectAIException {
123        return SelectAIAgentFactory.create(dbConnectionConfig, options);
124    }
125
126    /**
127     * Creates a DataSource-backed SelectAIAgent client.
128     * <p>
129     * For a runnable example, see
130     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateSelectAIAgentDataSourceSample.html">
131     * CreateSelectAIAgentDataSourceSample source</a>.
132     *
133     * @param dataSource DataSource used to obtain JDBC connections
134     * @return SelectAIAgent client
135     * @throws IllegalArgumentException when {@code dataSource} is null
136     */
137    static SelectAIAgent create(DataSource dataSource) {
138        return SelectAIAgentFactory.create(dataSource);
139    }
140
141    /**
142     * Creates a DataSource-backed SelectAIAgent client with SDK execution options.
143     * <p>
144     * For a runnable example, see
145     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateSelectAIAgentDataSourceWithOptionsSample.html">
146     * CreateSelectAIAgentDataSourceWithOptionsSample source</a>.
147     *
148     * @param dataSource DataSource used to obtain JDBC connections
149     * @param options SDK execution options; {@code null} uses defaults
150     * @return SelectAIAgent client
151     * @throws IllegalArgumentException when {@code dataSource} is null
152     */
153    static SelectAIAgent create(DataSource dataSource, SelectAIOptions options) {
154        return SelectAIAgentFactory.create(dataSource, options);
155    }
156
157    /**
158     * Loads an existing agent, including its metadata and attributes.
159     * <p>
160     * For a runnable example, see
161     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadAgentSample.html">
162     * LoadAgentSample source</a>.
163     *
164     * @param agentName agent name
165     * @return database-backed agent object
166     * @throws IllegalArgumentException when {@code agentName} is null or blank
167     * @throws SelectAIException when the agent does not exist or its metadata or attributes cannot be loaded
168     */
169    Agent agent(String agentName) throws SelectAIException;
170
171    /**
172     * Initializes an agent object for explicit creation.
173     * <p>
174     * For a runnable example, see
175     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateAgentSample.html">
176     * CreateAgentSample source</a>.
177     *
178     * @param agentName agent name
179     * @param attributes agent creation attributes
180     * @param description optional agent description
181     * @param status optional initial status; {@code null} uses the database default
182     * @return agent object configured for creation
183     * @throws IllegalArgumentException when {@code agentName} is null or blank,
184     *         or {@code attributes} is null
185     */
186    Agent agent(String agentName, AgentAttributes attributes, String description, AgentStatus status);
187
188    /**
189     * Loads an existing task, including its metadata and attributes.
190     * <p>
191     * For a runnable example, see
192     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadTaskSample.html">
193     * LoadTaskSample source</a>.
194     *
195     * @param taskName task name
196     * @return database-backed task object
197     * @throws IllegalArgumentException when {@code taskName} is null or blank
198     * @throws SelectAIException when the task does not exist or its metadata or attributes cannot be loaded
199     */
200    Task task(String taskName) throws SelectAIException;
201
202    /**
203     * Initializes a task object for explicit creation.
204     * <p>
205     * For a runnable example, see
206     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateTaskSample.html">
207     * CreateTaskSample source</a>.
208     *
209     * @param taskName task name
210     * @param attributes task creation attributes
211     * @param description optional task description
212     * @param status optional initial status; {@code null} uses the database default
213     * @return task object configured for creation
214     * @throws IllegalArgumentException when {@code taskName} is null or blank,
215     *         or {@code attributes} is null
216     */
217    Task task(String taskName, TaskAttributes attributes, String description, TaskStatus status);
218
219    /**
220     * Loads an existing tool, including its metadata and attributes.
221     * <p>
222     * For a runnable example, see
223     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadToolSample.html">
224     * LoadToolSample source</a>.
225     *
226     * @param toolName tool name
227     * @return database-backed tool object
228     * @throws IllegalArgumentException when {@code toolName} is null or blank
229     * @throws SelectAIException when the tool does not exist or its metadata or attributes cannot be loaded
230     */
231    Tool tool(String toolName) throws SelectAIException;
232
233    /**
234     * Initializes a tool object for explicit creation.
235     * <p>
236     * For runnable examples, see
237     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateToolSample.html">
238     * CreateToolSample source</a>,
239     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateSqlToolSample.html">
240     * CreateSqlToolSample source</a>, and
241     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ToolParamsSample.html">
242     * ToolParamsSample source</a>.
243     *
244     * @param toolName tool name
245     * @param attributes tool creation attributes
246     * @param description optional tool description
247     * @param status optional initial status; {@code null} uses the database default
248     * @return tool object configured for creation
249     * @throws IllegalArgumentException when {@code toolName} is null or blank,
250     *         or {@code attributes} is null
251     */
252    Tool tool(String toolName, ToolAttributes attributes, String description, ToolStatus status);
253
254    /**
255     * Loads a team owned by the current database user, including its metadata
256     * and attributes. To run a granted team owned by another user, use
257     * {@link #runTeam(String, RunTeamRequest)} with an owner-qualified name.
258     * <p>
259     * For a runnable example, see
260     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/LoadTeamSample.html">
261     * LoadTeamSample source</a>.
262     *
263     * @param teamName team name
264     * @return database-backed team object
265     * @throws IllegalArgumentException when {@code teamName} is null or blank
266     * @throws SelectAIException when the team does not exist or its metadata or attributes cannot be loaded
267     */
268    Team team(String teamName) throws SelectAIException;
269
270    /**
271     * Initializes a team object for explicit creation.
272     * <p>
273     * For a runnable example, see
274     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateTeamSample.html">
275     * CreateTeamSample source</a>.
276     *
277     * @param teamName team name
278     * @param attributes team creation attributes
279     * @param description optional team description
280     * @param status optional initial status; {@code null} uses the database default
281     * @return team object configured for creation
282     * @throws IllegalArgumentException when {@code teamName} is null or blank,
283     *         or {@code attributes} is null
284     */
285    Team team(String teamName, TeamAttributes attributes, String description, TeamStatus status);
286
287    /**
288     * Runs an existing team by name without loading owner-only team metadata.
289     * A consumer can run a team granted by another database user with a name
290     * such as {@code TEAM_OWNER.SHARED_SUPPORT_TEAM}. The database checks team
291     * existence and the caller's access; this method does not grant access to
292     * manage the team's definition.
293     * Without established session context, the request must contain a
294     * database-created conversation identifier. The operation is synchronous.
295     * In {@code DataSource} mode, the borrowed JDBC connection can remain
296     * occupied for the duration of the workflow. The SDK does not provide a
297     * cancellation API, and a JDBC timeout or interrupted call may not stop
298     * server-side or provider work. Retry only when the workflow is known to
299     * be safe to repeat.
300     *
301     * <p>For a runnable example, see
302     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/RunSharedTeamSample.html">
303     * RunSharedTeamSample source</a>.</p>
304     * <p>For a human-input workflow resumed in a new process through a pooled
305     * {@code DataSource}, see
306     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/PooledTeamResumeSample.html">
307     * PooledTeamResumeSample source</a>.</p>
308     *
309     * @param teamName team name, optionally owner-qualified
310     * @param request prompt and optional runtime parameters
311     * @return typed team-run result retaining the database response
312     * @throws IllegalArgumentException when {@code teamName} is null or blank,
313     *         or {@code request} is null
314     * @throws SelectAIException when the database rejects or cannot complete the run
315     */
316    TeamRunResult runTeam(String teamName, RunTeamRequest request) throws SelectAIException;
317
318    /**
319     * Returns the latest state for a team run identified by a database
320     * conversation identifier.
321     *
322     * <p>This operation does not load a {@link Team} handle and supports an
323     * owner-qualified team name for a shared team.</p>
324     * <p>
325     * For a runnable example, see
326     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/GetTeamStateSample.html">
327     * GetTeamStateSample source</a>.
328     * For a runnable example that verifies {@code WAITING_FOR_HUMAN} before
329     * resuming through a pooled {@code DataSource}, see
330     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/PooledTeamResumeSample.html">
331     * PooledTeamResumeSample source</a>.
332     *
333     * @param teamName team name, optionally owner-qualified
334     * @param conversationId existing database conversation identifier
335     * @return typed team execution state retaining the original database value
336     * @throws IllegalArgumentException when either argument is null or blank
337     * @throws SelectAIException when the database operation fails
338     * @since 1.1.0
339     */
340    TeamExecutionState getTeamStateByConversationId(String teamName, String conversationId)
341            throws SelectAIException;
342
343    /**
344     * Updates the execution state of a team run.
345     *
346     * <p>This operation does not load a {@link Team} handle and therefore also
347     * supports an owner-qualified team name for a team granted to the current
348     * database user. Set the request's conversation identifier to address a
349     * run across pooled database connections.</p>
350     * <p>
351     * For a runnable example, see
352     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetTeamExecutionStateSample.html">
353     * SetTeamExecutionStateSample source</a>.
354     *
355     * @param teamName team name, optionally owner-qualified
356     * @param request execution state and a typed conversation identifier
357     * @return {@code true} when the database operation succeeds
358     * @throws IllegalArgumentException when {@code teamName} is null or blank,
359     *         or {@code request} is null or does not identify a conversation
360     * @throws SelectAIException when the database operation fails
361     */
362    boolean setTeamExecutionState(String teamName, ExecutionStateRequest request)
363            throws SelectAIException;
364
365    /**
366     * Grants a database user or role permission to run an owner-managed team.
367     * The connected database user must own the team, and {@code teamName} must
368     * be the owner's unqualified team name. This method does not load a
369     * {@link Team} handle and is useful when the owner wants a client-level
370     * sharing operation.
371     * <p>
372     * For a runnable example, see
373     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/GrantTeamAccessSample.html">
374     * GrantTeamAccessSample source</a>.
375     *
376     * @param teamName owner's unqualified team name
377     * @param userOrRoleName database user or role receiving execution access
378     * @return {@code true} when the database accepts the grant
379     * @throws IllegalArgumentException when either name is null, blank, invalid,
380     *         or the grantee is {@code PUBLIC}
381     * @throws SelectAIException when the database rejects or cannot complete the grant
382     * @since 1.1.0
383     */
384    boolean grantTeamAccess(String teamName, String userOrRoleName) throws SelectAIException;
385
386    /**
387     * Revokes a database user or role permission to run an owner-managed team.
388     * The connected database user must own the team, and {@code teamName} must
389     * be the owner's unqualified team name.
390     * <p>
391     * For a runnable example, see
392     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/RevokeTeamAccessSample.html">
393     * RevokeTeamAccessSample source</a>.
394     *
395     * @param teamName owner's unqualified team name
396     * @param userOrRoleName database user or role losing execution access
397     * @return {@code true} when the database accepts the revoke
398     * @throws IllegalArgumentException when either name is null, blank, invalid,
399     *         or the grantee is {@code PUBLIC}
400     * @throws SelectAIException when the database rejects or cannot complete the revoke
401     * @since 1.1.0
402     */
403    boolean revokeTeamAccess(String teamName, String userOrRoleName) throws SelectAIException;
404
405    /**
406     * Reads an ephemeral runtime variable from the current database session.
407     *
408     * <p>Runtime variables are session-scoped. In {@code DataSource} mode,
409     * separate calls may use different pooled connections, so applications
410     * that require the value to remain available across calls should use a
411     * connection mode that retains one database session or manage the session
412     * explicitly.</p>
413     * <p>
414     * For a runnable example, see
415     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/GetVariableSample.html">
416     * GetVariableSample source</a>.
417     *
418     * @param namespace runtime-variable namespace, such as {@code state_variables}
419     * @param name runtime-variable key
420     * @return the variable value, or {@code null} when the key is not set
421     * @throws IllegalArgumentException when {@code namespace} or {@code name} is null or blank
422     * @throws SelectAIException when the database operation fails
423     * @since 1.1.0
424     */
425    default String getVariable(String namespace, String name) throws SelectAIException {
426        return getVariable(namespace, name, "ephemeral");
427    }
428
429    /**
430     * Reads a runtime variable from the current database session and scope.
431     * <p>
432     * For a runnable example, see
433     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/GetVariableSample.html">
434     * GetVariableSample source</a>.
435     *
436     * @param namespace runtime-variable namespace, such as {@code state_variables}
437     * @param name runtime-variable key
438     * @param scope runtime-variable scope; the database currently supports {@code ephemeral}
439     * @return the variable value, or {@code null} when the key is not set
440     * @throws IllegalArgumentException when an argument is null or blank
441     * @throws SelectAIException when the database operation fails
442     * @since 1.1.0
443     */
444    String getVariable(String namespace, String name, String scope) throws SelectAIException;
445
446    /**
447     * Sets or clears an ephemeral runtime variable in the current database session.
448     * A {@code null} value clears the variable.
449     * <p>
450     * For a runnable example, see
451     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetVariableSample.html">
452     * SetVariableSample source</a>.
453     *
454     * @param namespace runtime-variable namespace, such as {@code state_variables}
455     * @param name runtime-variable key
456     * @param value value to store, or {@code null} to clear the key
457     * @return {@code true} when the database accepts the operation
458     * @throws IllegalArgumentException when {@code namespace} or {@code name} is null or blank
459     * @throws SelectAIException when the database operation fails
460     * @since 1.1.0
461     */
462    default boolean setVariable(String namespace, String name, String value) throws SelectAIException {
463        return setVariable(namespace, name, value, "ephemeral");
464    }
465
466    /**
467     * Sets or clears a runtime variable in the current database session and scope.
468     * A {@code null} value clears the variable.
469     * <p>
470     * For a runnable example, see
471     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/SetVariableSample.html">
472     * SetVariableSample source</a>.
473     *
474     * @param namespace runtime-variable namespace, such as {@code state_variables}
475     * @param name runtime-variable key
476     * @param value value to store, or {@code null} to clear the key
477     * @param scope runtime-variable scope; the database currently supports {@code ephemeral}
478     * @return {@code true} when the database accepts the operation
479     * @throws IllegalArgumentException when an argument is null or blank, except {@code value}
480     * @throws SelectAIException when the database operation fails
481     * @since 1.1.0
482     */
483    boolean setVariable(String namespace, String name, String value, String scope)
484            throws SelectAIException;
485
486    /**
487     * Lists agents owned by the current database user.
488     * <p>
489     * For a runnable example, see
490     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListAgentsSample.html">
491     * ListAgentsSample source</a>.
492     *
493     * @return agent handles initialized from {@code USER_AI_AGENTS} metadata
494     *         and their current database attributes
495     * @throws SelectAIException when agent metadata or attributes cannot be loaded
496     */
497    List<Agent> listAgents() throws SelectAIException;
498
499    /**
500     * Lists owned agents whose names match a database regular-expression pattern.
501     * Matching is case-insensitive. Each returned handle includes metadata and
502     * attributes loaded from the database.
503     * <p>
504     * For a runnable example, see
505     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListAgentsSample.html">
506     * ListAgentsSample source</a>.
507     *
508     * @param agentNamePattern regular-expression pattern matched against agent names
509     * @return matching agent handles
510     * @throws IllegalArgumentException when {@code agentNamePattern} is null or blank
511     * @throws SelectAIException when listing agents fails
512     */
513    List<Agent> listAgents(String agentNamePattern) throws SelectAIException;
514
515    /**
516     * Lists tasks owned by the current database user.
517     * <p>
518     * For a runnable example, see
519     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListTasksSample.html">
520     * ListTasksSample source</a>.
521     *
522     * @return task handles initialized from {@code USER_AI_AGENT_TASKS} metadata
523     *         and their current database attributes
524     * @throws SelectAIException when task metadata or attributes cannot be loaded
525     */
526    List<Task> listTasks() throws SelectAIException;
527
528    /**
529     * Lists owned tasks whose names match a database regular-expression pattern.
530     * Matching is case-insensitive. Each returned handle includes metadata and
531     * attributes loaded from the database.
532     * <p>
533     * For a runnable example, see
534     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListTasksSample.html">
535     * ListTasksSample source</a>.
536     *
537     * @param taskNamePattern regular-expression pattern matched against task names
538     * @return matching task handles
539     * @throws IllegalArgumentException when {@code taskNamePattern} is null or blank
540     * @throws SelectAIException when listing tasks fails
541     */
542    List<Task> listTasks(String taskNamePattern) throws SelectAIException;
543
544    /**
545     * Lists tools owned by the current database user.
546     * <p>
547     * For a runnable example, see
548     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListToolsSample.html">
549     * ListToolsSample source</a>.
550     *
551     * @return tool handles initialized from {@code USER_AI_AGENT_TOOLS} metadata
552     *         and their current database attributes
553     * @throws SelectAIException when tool metadata or attributes cannot be loaded
554     */
555    List<Tool> listTools() throws SelectAIException;
556
557    /**
558     * Lists owned tools whose names match a database regular-expression pattern.
559     * Matching is case-insensitive. Each returned handle includes metadata and
560     * attributes loaded from the database.
561     * <p>
562     * For a runnable example, see
563     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListToolsSample.html">
564     * ListToolsSample source</a>.
565     *
566     * @param toolNamePattern regular-expression pattern matched against tool names
567     * @return matching tool handles
568     * @throws IllegalArgumentException when {@code toolNamePattern} is null or blank
569     * @throws SelectAIException when listing tools fails
570     */
571    List<Tool> listTools(String toolNamePattern) throws SelectAIException;
572
573    /**
574     * Lists agent teams owned by the current database user.
575     * <p>
576     * For a runnable example, see
577     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListAgentTeamsSample.html">
578     * ListAgentTeamsSample source</a>.
579     *
580     * @return team handles initialized from {@code USER_AI_AGENT_TEAMS}
581     *         metadata and their current database attributes
582     * @throws SelectAIException when team metadata or attributes cannot be loaded
583     */
584    List<Team> listTeams() throws SelectAIException;
585
586    /**
587     * Lists owned teams whose names match a database regular-expression pattern.
588     * Matching is case-insensitive. Each returned handle includes metadata and
589     * attributes loaded from the database. Granted cross-schema teams are not
590     * returned; use {@link #runTeam(String, RunTeamRequest)} to run those teams.
591     * <p>
592     * For a runnable example, see
593     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListAgentTeamsSample.html">
594     * ListAgentTeamsSample source</a>.
595     *
596     * @param teamNamePattern regular-expression pattern matched against team names
597     * @return matching team handles
598     * @throws IllegalArgumentException when {@code teamNamePattern} is null or blank
599     * @throws SelectAIException when listing teams fails
600     */
601    List<Team> listTeams(String teamNamePattern) throws SelectAIException;
602
603    /**
604     * Lists teams available to the calling database user for discovery.
605     * <p>
606     * The returned objects are read-only discovery
607     * snapshots, not mutable {@link Team} lifecycle handles.
608     * <p>
609     * For a runnable example, see
610     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ListAvailableTeamsSample.html">
611     * ListAvailableTeamsSample source</a>.
612     *
613     * @return available team discovery snapshots
614     * @throws SelectAIException when the database discovery operation or its
615     *         JSON response cannot be processed
616     */
617    List<AvailableTeam> listAvailableTeams() throws SelectAIException;
618
619    /**
620     * Returns the definition produced by
621     * {@code DBMS_CLOUD_AI_AGENT.GET_DEFINITION} for an agent framework object.
622     * <p>
623     * For a runnable example, see
624     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/GetDefinitionSample.html">
625     * GetDefinitionSample source</a>.
626     *
627     * @param objectType object type to describe
628     * @param objectName agent, task, tool, or team name
629     * @param includeDependentObjects whether dependent objects should be included
630     * @return definition returned by the database package
631     * @throws IllegalArgumentException when {@code objectType} is null or
632     *         {@code objectName} is null or blank
633     * @throws SelectAIException when the database operation fails
634     */
635    String getDefinition(AgentObjectType objectType, String objectName,
636                         boolean includeDependentObjects) throws SelectAIException;
637
638    /**
639     * Imports an agent team definition into the database.
640     * <p>
641     * For a runnable example, see
642     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/ImportTeamSample.html">
643     * ImportTeamSample source</a>.
644     *
645     * @param request import request
646     * @return {@code true} when import succeeds
647     * @throws IllegalArgumentException when {@code request} is null
648     * @throws SelectAIException when import fails
649     */
650    boolean importTeam(ImportTeamRequest request) throws SelectAIException;
651
652    /**
653     * Releases resources owned by this client.
654     * <p>
655     * For a runnable example, see
656     * <a href="{@docRoot}/src-html/com/oracle/database/selectai/samples/agent/CreateSelectAIAgentWithOptionsSample.html">
657     * CreateSelectAIAgentWithOptionsSample source</a>.
658     *
659     * @throws SelectAIException when an owned JDBC connection cannot be closed
660     */
661    @Override
662    void close() throws SelectAIException;
663}