Skip to content

Commit 89cf73d

Browse files
authored
Merge pull request #61 from sandeepkhot/selectai_agent_v2
Web SQL Developer compatable scripts
2 parents fc7a000 + 03a642d commit 89cf73d

13 files changed

Lines changed: 265 additions & 255 deletions

autonomous-ai-agents/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ The repository is organized to align with the Select AI Agent framework:
6464

6565
---
6666

67+
## Creating a Select AI Profile
68+
69+
Before using Autonomous Database AI agents, you must create a Select AI profile using DBMS_CLOUD_AI.
70+
71+
Oracle provides several examples demonstrating how to create AI profiles for different providers and models. See the documentation below and follow one of the examples to create your profile:
72+
73+
Select AI profile management documentation:
74+
https://docs.oracle.com/en-us/iaas/autonomous-database-serverless/doc/select-ai-manage-profiles.html#GUID-3721296F-14A1-428A-B464-7FA25E9EC8F3
75+
76+
Start by reviewing the examples in this documentation and create a profile appropriate for your environment (OCI Generative AI, OpenAI, Azure OpenAI, etc.). The profile name you create will be used later when configuring AI agents.
77+
6778
## Agent Configuration (`SELECTAI_AGENT_CONFIG`)
6879

6980
### Overview

autonomous-ai-agents/nl2sql_data_retrieval/README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ This **NL2SQL Data Retrieval Agent** addresses these limitations by combining:
2020

2121
into a **single autonomous agent workflow**.
2222

23-
### Key Advantages Over Plain NL2SQL
24-
25-
| Capability | Plain Select AI NL2SQL | This Agent |
26-
|----------|------------------------|------------|
27-
| SQL generation |||
28-
| Automatic retry on failure |||
29-
| Distinct value discovery |||
30-
| Range discovery (DATE / NUMBER) |||
31-
| Predicate refinement |||
32-
| External web search |||
33-
| URL content validation |||
34-
| Chart generation |||
35-
| Config-driven and extensible |||
36-
37-
> **Result:** Higher accuracy, fewer hallucinations, accurate SQL, and richer analytical answers.
38-
3923
---
4024

4125
## Architecture Overview

autonomous-ai-agents/nl2sql_data_retrieval/nl2sql_data_retrieval_agent.sql

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ rem - Creating an NL2SQL Team linking the agent and task
2222
rem - Executing the installer procedure to complete setup
2323
rem
2424
rem RELEASE VERSION
25-
rem 1.0
25+
rem 1.1
2626
rem
2727
rem RELEASE DATE
28-
rem 30-Jan-2026
28+
rem 06-Feb-2026
2929
rem
3030
rem MAJOR CHANGES IN THIS RELEASE
3131
rem - Initial release
@@ -93,34 +93,35 @@ rem ============================================================================
9393

9494
SET SERVEROUTPUT ON
9595
SET VERIFY OFF
96-
WHENEVER SQLERROR EXIT SQL.SQLCODE
9796

9897
PROMPT ======================================================
9998
PROMPT NL2SQL Data Retrieval Agent Installer
10099
PROMPT ======================================================
101100

102-
-- Target schema (MANDATORY)
103-
ACCEPT SCHEMA_NAME CHAR PROMPT 'Enter target schema name (required): '
104-
DEFINE INSTALL_SCHEMA = '&SCHEMA_NAME'
101+
-- Target schema
102+
VAR v_schema VARCHAR2(128)
103+
EXEC :v_schema := '&SCHEMA_NAME';
105104

106-
-- AI Profile (MANDATORY)
107-
ACCEPT PROFILE_NAME CHAR PROMPT 'Enter AI Profile name (required): '
108-
DEFINE PROFILE_NAME = '&PROFILE_NAME'
105+
-- AI Profile
106+
VAR v_ai_profile_name VARCHAR2(128)
107+
EXEC :v_ai_profile_name := '&AI_PROFILE_NAME';
109108

110109

111-
PROMPT ------------------------------------------------------
112-
PROMPT Installing into schema: &&INSTALL_SCHEMA
113-
PROMPT Using AI Profile : &&PROFILE_NAME
114-
PROMPT ------------------------------------------------------
115-
116110
----------------------------------------------------------------
117111
-- 1. Grants (safe to re-run)
118112
----------------------------------------------------------------
113+
DECLARE
114+
l_sql VARCHAR2(500);
119115
BEGIN
120-
DBMS_OUTPUT.PUT_LINE('Granting required privileges to &&INSTALL_SCHEMA ...');
121-
EXECUTE IMMEDIATE 'GRANT EXECUTE ON DBMS_CLOUD_AI_AGENT TO &&INSTALL_SCHEMA';
122-
EXECUTE IMMEDIATE 'GRANT EXECUTE ON DBMS_CLOUD_AI TO &&INSTALL_SCHEMA';
123-
EXECUTE IMMEDIATE 'GRANT EXECUTE ON DBMS_CLOUD TO &&INSTALL_SCHEMA';
116+
l_sql := 'GRANT EXECUTE ON DBMS_CLOUD_AI_AGENT TO ' || :v_schema;
117+
EXECUTE IMMEDIATE l_sql;
118+
119+
l_sql := 'GRANT EXECUTE ON DBMS_CLOUD_AI TO ' || :v_schema;
120+
EXECUTE IMMEDIATE l_sql;
121+
122+
l_sql := 'GRANT EXECUTE ON DBMS_CLOUD TO ' || :v_schema;
123+
EXECUTE IMMEDIATE l_sql;
124+
124125
DBMS_OUTPUT.PUT_LINE('Grants completed.');
125126
END;
126127
/
@@ -129,17 +130,20 @@ END;
129130
----------------------------------------------------------------
130131
-- 2. Create installer procedure in target schema
131132
----------------------------------------------------------------
132-
PROMPT Creating installer procedure in &&INSTALL_SCHEMA ...
133+
BEGIN
134+
EXECUTE IMMEDIATE
135+
'ALTER SESSION SET CURRENT_SCHEMA = ' || :v_schema;
136+
END;
137+
/
133138

134-
CREATE OR REPLACE PROCEDURE &&INSTALL_SCHEMA..data_retrieval_agent (
139+
CREATE OR REPLACE PROCEDURE data_retrieval_agent (
135140
p_profile_name IN VARCHAR2
136141
)
137142
AUTHID DEFINER
138143
AS
139144
BEGIN
140145
DBMS_OUTPUT.PUT_LINE('--------------------------------------------');
141146
DBMS_OUTPUT.PUT_LINE('Starting Data Retrieval Agent Team installation');
142-
DBMS_OUTPUT.PUT_LINE('Schema : ' || USER);
143147
DBMS_OUTPUT.PUT_LINE('--------------------------------------------');
144148

145149
------------------------------------------------------------
@@ -165,7 +169,7 @@ BEGIN
165169
END;
166170

167171
------------------------------------------------------------
168-
-- DROP & CREATE TASK
172+
-- DROP and CREATE TASK
169173
------------------------------------------------------------
170174
BEGIN
171175
DBMS_CLOUD_AI_AGENT.DROP_TASK('NL2SQL_DATA_RETRIEVAL_TASK');
@@ -215,7 +219,7 @@ BEGIN
215219
DBMS_OUTPUT.PUT_LINE('Created task NL2SQL_DATA_RETRIEVAL_TASK');
216220

217221
------------------------------------------------------------
218-
-- DROP & CREATE AGENT
222+
-- DROP and CREATE AGENT
219223
------------------------------------------------------------
220224
BEGIN
221225
DBMS_CLOUD_AI_AGENT.DROP_AGENT('NL2SQL_DATA_RETRIEVAL_AGENT');
@@ -240,7 +244,7 @@ BEGIN
240244
DBMS_OUTPUT.PUT_LINE('Created agent NL2SQL_DATA_RETRIEVAL_AGENT');
241245

242246
------------------------------------------------------------
243-
-- DROP & CREATE TEAM
247+
-- DROP and CREATE TEAM
244248
------------------------------------------------------------
245249
BEGIN
246250
DBMS_CLOUD_AI_AGENT.DROP_TEAM('NL2SQL_DATA_RETRIEVAL_TEAM');
@@ -259,7 +263,6 @@ BEGIN
259263
'}'
260264
);
261265

262-
263266
DBMS_OUTPUT.PUT_LINE('Created team NL2SQL_DATA_RETRIEVAL_TEAM');
264267

265268
DBMS_OUTPUT.PUT_LINE('------------------------------------------------');
@@ -274,19 +277,12 @@ END data_retrieval_agent;
274277
----------------------------------------------------------------
275278
PROMPT Executing installer procedure ...
276279
BEGIN
277-
&&INSTALL_SCHEMA..data_retrieval_agent('&&PROFILE_NAME');
280+
data_retrieval_agent(p_profile_name => :v_ai_profile_name);
278281
END;
279282
/
280283

281284
PROMPT ======================================================
282285
PROMPT Installation finished successfully
283286
PROMPT ======================================================
284287

285-
alter session set current_schema = ADMIN;
286-
287-
288-
289-
290-
291-
292-
288+
alter session set current_schema = ADMIN;

autonomous-ai-agents/nl2sql_data_retrieval/nl2sql_data_retrieval_tool.sql

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,36 @@ rem AI Agent tools used to refine the Select AI NL2SQL operations
1616
rem via Select AI Agent (Oracle AI Database).
1717
rem
1818
rem RELEASE VERSION
19-
rem 1.0
19+
rem 1.1
2020
rem
2121
rem RELEASE DATE
22-
rem 30-Jan-2026
22+
rem 6-Feb-2026
2323
rem
2424
rem MAJOR CHANGES IN THIS RELEASE
25-
rem - Initial release
25+
rem - Run compatibility with Web SQL Developer
2626
rem
2727
rem SCRIPT STRUCTURE
2828
rem 1. Initialization:
2929
rem - Grants
3030
rem - Configuration setup
3131
rem
3232
rem 2. Package Deployment:
33-
rem - &&INSTALL_SCHEMA.nl2sql_data_retrieval_agents
33+
rem - &&SCHEMA_NAME.nl2sql_data_retrieval_agents
3434
rem (package specification and body)
3535
rem
3636
rem 3. AI Tool Setup:
3737
rem - Creation of all NL2SQl data retrieval agent tools
3838
rem
3939
rem INSTALL INSTRUCTIONS
4040
rem 1. Connect as ADMIN or a user with required privileges
41-
rem 2. Run the script using SQL*Plus or SQLcl:
42-
rem
43-
rem sqlplus admin@db @nl2sql_data_retrieval_tools.sql <INSTALL_SCHEMA>
44-
rem
41+
rem 2. Run the script using websqldeveloper/SQL Developer
4542
rem 3. Verify installation by checking tool registration
4643
rem and package compilation status.
4744
rem
4845
rem PARAMETERS
49-
rem INSTALL_SCHEMA (Required)
46+
rem SCHEMA_NAME (Required)
5047
rem Schema in which the package and tools will be created.
48+
rem
5149
rem ----------------------------------------------------------------------------
5250
rem GOOGLE CUSTOM SEARCH – SETUP INSTRUCTIONS
5351
rem ----------------------------------------------------------------------------
@@ -108,8 +106,8 @@ SET VERIFY OFF
108106
-- ============================================================================
109107

110108
-- First argument: Schema Name (Required)
111-
ACCEPT SCHEMA_NAME CHAR PROMPT 'Enter schema name (required): '
112-
DEFINE INSTALL_SCHEMA = '&SCHEMA_NAME'
109+
VAR v_schema VARCHAR2(128)
110+
EXEC :v_schema := '&SCHEMA_NAME';
113111

114112
-- Second argument: NL2SQL Data Retrieval Agent configuration (Required)
115113
PROMPT
@@ -131,10 +129,9 @@ PROMPT "cxid_vault_secret_ocid":"ocid1.vaultsecret.oc1..aaaa",
131129
PROMPT "api_key_vault_secret_ocid":"ocid1.vaultsecret.oc1..bbbb"
132130
PROMPT }
133131
PROMPT
134-
PROMPT
135132

136-
ACCEPT INSTALL_CONFIG_JSON CHAR PROMPT 'Enter INSTALL_CONFIG_JSON (optional and can be set later in SELECTAI_AGENT_CONFIG table): '
137-
DEFINE INSTALL_CONFIG_JSON = '&INSTALL_CONFIG_JSON'
133+
VAR v_config VARCHAR2(256)
134+
EXEC :v_config := '&CONFIG_JSON';
138135

139136

140137
CREATE OR REPLACE PROCEDURE initialize_nl2sql_data_retrieval_agent(
@@ -145,11 +142,11 @@ IS
145142
l_use_rp BOOLEAN := NULL;
146143
l_schema_name VARCHAR2(128);
147144
c_nlb_agent CONSTANT VARCHAR2(64) := 'NL2SQL_DATA_RETRIEVAL_AGENT';
148-
l_credential_name VARCHAR2(100);
149-
l_oci_region VARCHAR2(100);
150-
l_vault_secret_id1 VARCHAR2(512);
151-
l_vault_secret_id2 VARCHAR2(512);
152-
l_ai_profile VARCHAR2(100);
145+
l_credential_name VARCHAR2(100);
146+
l_oci_region VARCHAR2(100);
147+
l_vault_secret_id1 VARCHAR2(512);
148+
l_vault_secret_id2 VARCHAR2(512);
149+
l_ai_profile VARCHAR2(100);
153150

154151
TYPE priv_list_t IS VARRAY(200) OF VARCHAR2(4000);
155152
l_priv_list CONSTANT priv_list_t := priv_list_t(
@@ -401,15 +398,20 @@ END initialize_nl2sql_data_retrieval_agent;
401398
-- Run the setup for the NL2SQL data retrieval AI agent.
402399
-------------------------------------------------------------------------------
403400
BEGIN
401+
404402
initialize_nl2sql_data_retrieval_agent(
405-
p_install_schema_name => '&&INSTALL_SCHEMA',
406-
p_config_json => '&&INSTALL_CONFIG_JSON'
403+
p_install_schema_name => :v_schema,
404+
p_config_json => :v_config
407405
);
406+
408407
END;
409408
/
410409

411-
412-
alter session set current_schema = &&INSTALL_SCHEMA;
410+
BEGIN
411+
EXECUTE IMMEDIATE
412+
'ALTER SESSION SET CURRENT_SCHEMA = ' || :v_schema;
413+
END;
414+
/
413415

414416
------------------------------------------------------------------------
415417
-- Package specification
@@ -965,7 +967,7 @@ END nl2sql_data_retrieval_functions;
965967
------------------------------------------------------------------------------------------
966968
-- This procedure installs or refreshes the NL2SQL data retrieval Agent tools in the
967969
-- current schema. It drops any existing tool definitions and recreates them
968-
-- pointing to the latest implementations in &&INSTALL_SCHEMA.nl2sql_data_retrieval_agents.
970+
-- pointing to the latest implementations in &&SCHEMA_NAME.nl2sql_data_retrieval_agents.
969971
------------------------------------------------------------------------------------------
970972

971973
CREATE OR REPLACE PROCEDURE initialize_nl2sql_data_retrieval_tools

0 commit comments

Comments
 (0)