Skip to content

Commit 729bd41

Browse files
committed
GCP Oracle AI Database agent
1 parent 79187a1 commit 729bd41

File tree

4 files changed

+1133
-1
lines changed

4 files changed

+1133
-1
lines changed

autonomous-ai-agents/nl2sql_data_retrieval/nl2sql_data_retrieval_agent.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ BEGIN
208208
'invoke GET_URL_CONTENT to validate the source content. ' ||
209209
'Always present answers in a clearly formatted and readable manner using bullet points. ' ||
210210
'At the end of the response, add a blank line followed by a **Sources** section. ' ||
211-
'If SQL_TOOL was used, include the source tag * DATABASE. ' ||
211+
'If SQL_TOOL was used, include the source tag * ORACLE AI DATABASE. ' ||
212212
'If WEBSEARCH was used, include a * WEBSEARCH section followed by a markdown list of referenced URLs. ' ||
213213
'If both were used, include both source sections. ' ||
214214
'Use {current_location} to identify the user location when required. ' ||
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# Oracle AI Database Agent
2+
3+
## Overview
4+
5+
The **Oracle AI Database Agent** enables natural-language data analysis workflows by combining NL2SQL generation, metadata inspection, query correction, and chart generation inside Oracle Autonomous AI Database.
6+
7+
For definitions of **Tool**, **Task**, **Agent**, and **Agent Team**, see the top-level guide: [README](../README.md#simple-agent-execution-flow).
8+
9+
## How the NL2SQL agent improves upon Select AI NL2SQL
10+
11+
Oracle Select AI already provides Natural Language to SQL (NL2SQL), but **real-world data retrieval often fails** due to:
12+
13+
- Ambiguous column values
14+
- Unknown or incorrect value ranges (dates, numbers)
15+
- Invalid predicates leading to zero-row results
16+
- Lack of visualization support
17+
18+
This **Oracle AI Database Agent** addresses these limitations by combining:
19+
20+
- Database introspection
21+
- Fail-safe retries
22+
- Distinct and range value discovery
23+
- Chart and visualization generation
24+
25+
into a **single autonomous agent workflow**.
26+
27+
---
28+
29+
## Architecture Overview
30+
31+
```text
32+
User Query
33+
34+
NL2SQL Task
35+
36+
Agent Reasoning
37+
├── SQL_TOOL
38+
├── DISTINCT_VALUES_CHECK
39+
├── RANGE_VALUES_CHECK
40+
└── GENERATE_CHART
41+
42+
Final Verified Answer + Sources
43+
```
44+
45+
The agent dynamically selects tools, retries intelligently, and produces **explainable outputs**.
46+
47+
---
48+
49+
## Repository Contents
50+
51+
```text
52+
.
53+
├── oracle_ai_database_agent_tool.sql
54+
│ ├── PL/SQL utility functions
55+
│ ├── Database-native analysis helpers
56+
│ └── AI tool registration
57+
58+
├── oracle_ai_database_agent.sql
59+
│ ├── Task definition
60+
│ ├── Agent creation
61+
│ ├── Team orchestration
62+
│ └── AI profile binding
63+
64+
└── README.md
65+
```
66+
67+
---
68+
69+
## Prerequisites
70+
71+
- Oracle Autonomous AI Database (26ai recommended)
72+
- Select AI enabled
73+
- Run as ADMIN
74+
75+
---
76+
77+
## Installation – Tools
78+
79+
Before running installation commands:
80+
81+
1. Clone or download this repository.
82+
2. Open a terminal and change directory to `google-gemini-marketplace-agents`.
83+
3. Choose one execution mode:
84+
- SQL*Plus/SQLcl: run script files directly with `@script_name`.
85+
- SQL Worksheet (Database Actions or other SQL IDE): open the `.sql` file and run/paste its contents.
86+
4. Uploading scripts to `DATA_PUMP_DIR` is not required for these methods.
87+
88+
Run as `ADMIN` (or another privileged user):
89+
90+
```sql
91+
sqlplus admin@<adb_connect_string> @oracle_ai_database_agent_tool.sql
92+
```
93+
### Input Parameters required to run
94+
- Target schema name (Schema where to the agent team needs to be installed)
95+
96+
### What This Script Does
97+
98+
- Grants required Select AI privileges
99+
- Creates `SELECTAI_AGENT_CONFIG`
100+
- Installs `ORACLE_AI_DATA_RETRIEVAL_FUNCTIONS`
101+
- Registers all AI agent tools.
102+
103+
---
104+
105+
## Installed Tools Explained
106+
107+
### 1️⃣ SQL_TOOL
108+
**Purpose:** Generate SQL from natural language and run it safely.
109+
110+
**Fail-safe behavior:**
111+
- SQL generation failure → feedback returned to the LLM
112+
- Zero rows → agent retries using range or distinct tools
113+
114+
---
115+
116+
### 2️⃣ DISTINCT_VALUES_CHECK
117+
**Purpose:** Discover valid categorical values before filtering.
118+
119+
**Use cases:**
120+
- Status columns
121+
- Country or region names
122+
- Product categories
123+
124+
**Matching modes:** `fuzzy` (default), `exact`, `regex`
125+
126+
---
127+
128+
### 3️⃣ RANGE_VALUES_CHECK
129+
**Purpose:** Determine minimum and maximum values for numeric, DATE, or TIMESTAMP columns.
130+
131+
**Use cases:**
132+
- Time-series analysis
133+
- Salary or revenue ranges
134+
- Boundary detection
135+
136+
---
137+
138+
### 4️⃣ GENERATE_CHART
139+
**Purpose:** Generate **Chart.js-compatible JSON** for visualizations.
140+
141+
**Supported chart types:**
142+
- bar, line, pie, doughnut
143+
- radar, scatter, bubble, polarArea
144+
145+
---
146+
147+
## Installation – Agent and Team
148+
149+
From `google-gemini-marketplace-agents`, run:
150+
151+
```sql
152+
sqlplus admin@<adb_connect_string> @oracle_ai_database_agent.sql
153+
```
154+
155+
You can also execute the contents of `oracle_ai_database_agent.sql` in SQL Worksheet.
156+
157+
### Input Parameters required to run.
158+
- Target schema name (Schema where to the agent team needs to be installed)
159+
- AI Profile name (Select AI Profile name that needs to be used with the Agent)
160+
161+
162+
### Objects Created
163+
164+
| Object | Name |
165+
|-------|------|
166+
| Task | ORACLE_AI_DATABASE_TASK |
167+
| Agent | ORACLE_AI_DATABASE_AGENT |
168+
| Team | ORACLE_AI_DATABASE_TEAM |
169+
170+
---
171+
172+
## Task Intelligence Highlights
173+
174+
The task definition enforces:
175+
- Tool-based reasoning
176+
- Mandatory source attribution
177+
- Structured, readable responses
178+
- Explicit chart generation flow
179+
- Retry logic for SQL failures
180+
- Metadata-aware querying
181+
182+
---
183+
184+
## Generalizing Teams Using Tools
185+
186+
### Recommended Design Pattern
187+
**Keep tools generic.
188+
Specialize agents using tasks.**
189+
190+
### Example Team Strategies
191+
192+
| Team | Tools Used | Purpose |
193+
|----|-----------|--------|
194+
| Data Retrieval Team | All tools | General analytics |
195+
| Finance Analytics Team | SQL + RANGE | Financial reporting |
196+
| Visualization Team | SQL + CHART | Dashboards and insights |
197+
198+
### Why This Scales Well
199+
- Tools are reusable
200+
- Tasks define behavior
201+
- Agents bind AI profiles
202+
- Teams orchestrate workflows
203+
204+
### Example prompts
205+
After creating the Oracle AI Database Agent team, you can interact with it using prompts such as:
206+
207+
- “How can you help?”
208+
- Ask questions related to the database tables associated with the selected profile.
209+
- To generate visualizations, explicitly mention the chart type, for example:
210+
“Generate a bar chart for the result.” (any supported chart type can be used)
211+
212+
---
213+
214+
## Best Practices
215+
216+
- Use `DISTINCT_VALUES_CHECK` before filtering text columns
217+
- Use `RANGE_VALUES_CHECK` for DATE and NUMBER columns
218+
- Maintain separate AI profiles per environment
219+
220+
---
221+
222+
## License
223+
224+
Universal Permissive License (UPL) 1.0
225+
https://oss.oracle.com/licenses/upl/
226+
Copyright (c) 2026 Oracle and/or its affiliates.
227+
228+
---
229+
230+
## ✨ Final Thoughts
231+
232+
This Oracle AI Database Agent elevates Select AI from a **SQL generator** to a **true autonomous data analyst** — capable of reasoning, validating, retrying, and visualizing data with confidence.
233+
234+
Designed for:
235+
- Domain-specific agents
236+
- Multi-team orchestration
237+
- UI / APEX integrations
238+
- Autonomous dashboards

0 commit comments

Comments
 (0)