Skip to content

Commit 7228d46

Browse files
committed
Initial code for Select AI Agents
1 parent 27846fc commit 7228d46

File tree

21 files changed

+2070
-4
lines changed

21 files changed

+2070
-4
lines changed

doc/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@
5656
html_static_path = ["_static"]
5757

5858
pygments_style = "sphinx"
59+
60+
latex_elements = {
61+
"maxlistdepth": "10", # Increase the maximum list nesting depth
62+
}

doc/source/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,13 @@ Synthetic Data
9797
:maxdepth: 3
9898

9999
user_guide/synthetic_data.rst
100+
101+
102+
Select AI Agents
103+
================
104+
105+
.. toctree::
106+
:numbered:
107+
:maxdepth: 3
108+
109+
user_guide/agent.rst

doc/source/user_guide/agent.rst

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
.. _agent:
2+
3+
``select_ai.agent`` adds a thin Python layer over Oracle Autonomous Database's
4+
``DBMS_CLOUD_AI_AGENT`` package so you can define tools, compose tasks, wire up
5+
agents and run teams from Python using the existing select_ai connection objects
6+
7+
- Keep agent state and orchestration in the database
8+
9+
- Register callable tools (PL/SQL procedure or functions, SQL, external HTTP
10+
endpoints, Slack or Email notifications) and attach them to tasks
11+
12+
- Group agents into teams and invoke them with a single API call
13+
14+
15+
********
16+
``Tool``
17+
********
18+
19+
A callable which Select AI agent can invoke to accomplish a certain task.
20+
Users can either register built-in tools or create a custom tool using a PL/SQL
21+
stored procedure.
22+
23+
Supported Tools
24+
+++++++++++++++
25+
26+
Following class methods of ``select_ai.agent.Tool`` class
27+
can be used to create tools. Invoking them will create a proxy object in the
28+
Python layer and persist the tool in the Database using
29+
``DBMS_CLOUD_AI_AGENT.CREATE_TOOL``
30+
31+
32+
.. list-table:: Select AI Agent Tools
33+
:header-rows: 1
34+
:widths: 20 50 30
35+
:align: left
36+
37+
* - Tool Type
38+
- Class Method
39+
- Arguments
40+
* - ``EMAIL``
41+
- ``select_ai.agent.Tool.create_email_notification_tool``
42+
- - ``tool_name``
43+
- ``credential_name``
44+
- ``recipient``
45+
- ``sender``
46+
- ``smtp_host``
47+
* - ``HTTP``
48+
- ``select_ai.agent.Tool.create_http_tool``
49+
- ``tool_name``, ``credential_name``, ``endpoint``
50+
* - ``SQL``
51+
- ``select_ai.agent.Tool.create_sql_tool``
52+
- ``tool_name``, ``profile_name``
53+
* - ``SLACK``
54+
- ``select_ai.agent.Tool.create_slack_notification_tool``
55+
- ``tool_name``, ``credential_name``, ``slack_channel``
56+
* - ``WEBSEARCH``
57+
- ``select_ai.agent.Tool.create_websearch_tool``
58+
- ``tool_name``, ``credential_name``
59+
* - ``PL/SQL custom tool``
60+
- ``select_ai.agent.Tool.create_pl_sql_tool``
61+
- ``tool_name``, ``function``
62+
* - ``RAG``
63+
- ``select_ai.agent.Tool.create_rag_tool``
64+
- ``tool_name``, ``profile_name``
65+
66+
.. latex:clearpage::
67+
68+
.. autoclass:: select_ai.agent.ToolAttributes
69+
:members:
70+
71+
.. autoclass:: select_ai.agent.ToolParams
72+
:members:
73+
74+
.. latex:clearpage::
75+
76+
.. autoclass:: select_ai.agent.Tool
77+
:members:
78+
79+
.. latex:clearpage::
80+
81+
Create Tool
82+
+++++++++++
83+
84+
The following example shows creation of an AI agent tool to perform natural
85+
language translation to SQL using an OCI AI profile
86+
87+
.. literalinclude:: ../../../samples/agent/tool_create.py
88+
:language: python
89+
:lines: 14-
90+
91+
output::
92+
93+
MOVIE_SQL_TOOL
94+
95+
ToolAttributes(instruction=None,
96+
function=None,
97+
tool_params=SQLToolParams(_REQUIRED_FIELDS=None,
98+
credential_name=None,
99+
endpoint=None,
100+
notification_type=None,
101+
profile_name='oci_ai_profile',
102+
recipient=None,
103+
sender=None,
104+
slack_channel=None,
105+
smtp_host=None),
106+
tool_inputs=None,
107+
tool_type=<ToolType.SQL: 'SQL'>)
108+
109+
110+
111+
.. latex:clearpage::
112+
113+
114+
List Tools
115+
++++++++++
116+
117+
.. literalinclude:: ../../../samples/agent/tool_list.py
118+
:language: python
119+
:lines: 14-
120+
121+
output::
122+
123+
Tool(tool_name=MOVIE_SQL_TOOL, attributes=ToolAttributes(instruction='This tool is used to work with SQL queries using natural language. Input should be a natural language query about data or database operations. The tool behavior depends on the configured action: RUNSQL - generates and executes the SQL query returning actual data; SHOWSQL - generates and displays the SQL statement without executing it; EXPLAINSQL - generates SQL and provides a natural language explanation of what the query does. Always provide clear, specific questions about the data you want to retrieve or analyze.', function='dbms_cloud_ai_agent.sql_tool', tool_params=SQLToolParams(_REQUIRED_FIELDS=None, credential_name=None, endpoint=None, notification_type=None, profile_name='oci_ai_profile', recipient=None, sender=None, slack_channel=None, smtp_host=None), tool_inputs=None, tool_type='SQL'), description=My Select AI MOVIE SQL agent tool)
124+
125+
Tool(tool_name=LLM_CHAT_TOOL, attributes=ToolAttributes(instruction='This tool is used to work with SQL queries using natural language. Input should be a natural language query about data or database operations. The tool behavior depends on the configured action: RUNSQL - generates and executes the SQL query returning actual data; SHOWSQL - generates and displays the SQL statement without executing it; EXPLAINSQL - generates SQL and provides a natural language explanation of what the query does. Always provide clear, specific questions about the data you want to retrieve or analyze.', function='dbms_cloud_ai_agent.sql_tool', tool_params=SQLToolParams(_REQUIRED_FIELDS=None, credential_name=None, endpoint=None, notification_type=None, profile_name='oci_ai_profile', recipient=None, sender=None, slack_channel=None, smtp_host=None), tool_inputs=None, tool_type='SQL'), description=My Select AI agent tool)
126+
127+
.. latex:clearpage::
128+
129+
********
130+
``Task``
131+
********
132+
133+
Each task is identified by a ``task_name`` and includes a set of attributes that
134+
guide the agent’s behavior during execution.
135+
Key attributes include the ``instruction``, which describes the task’s purpose and
136+
provides context for the agent to reason about when and how to use it,
137+
and the ``tools`` list, which specifies which tools the agent can choose from to
138+
accomplish the task. An optional ``input`` field allows a task to depend on the
139+
output of prior tasks, enabling task chaining and multi-step workflows.
140+
141+
.. autoclass:: select_ai.agent.TaskAttributes
142+
:members:
143+
144+
.. latex:clearpage::
145+
146+
.. autoclass:: select_ai.agent.Task
147+
:members:
148+
149+
.. latex:clearpage::
150+
151+
152+
Create Task
153+
+++++++++++
154+
155+
In the following task, we use the ``MOVIE_SQL_TOOL`` created in the
156+
previous step
157+
158+
.. literalinclude:: ../../../samples/agent/task_create.py
159+
:language: python
160+
161+
output::
162+
163+
ANALYZE_MOVIE_TASK
164+
165+
TaskAttributes(instruction='Help the user with their request about movies. '
166+
'User question: {query}. You can use SQL tool to '
167+
'search the data from database',
168+
tools=['MOVIE_SQL_TOOL'],
169+
input=None,
170+
enable_human_tool=False)
171+
172+
173+
.. latex:clearpage::
174+
175+
List Tasks
176+
+++++++++++
177+
178+
.. literalinclude:: ../../../samples/agent/tasks_list.py
179+
:language: python
180+
181+
output::
182+
183+
Task(task_name=ANALYZE_MOVIE_TASK, attributes=TaskAttributes(instruction='Help the user with their request about movies. User question: {query}. You can use SQL tool to search the data from database', tools='["MOVIE_SQL_TOOL"]', input=None, enable_human_tool=False), description=Movie task involving a human)
184+
185+
.. latex:clearpage::
186+
187+
*********
188+
``Agent``
189+
*********
190+
191+
A Select AI Agent is defined using ``agent_name``, its ``attributes`` and an
192+
optional description. The attributes must include key agent properties such as
193+
``profile_name`` which specifies the LLM profile used for prompt generation
194+
and ``role``, which outlines the agent’s intended role and behavioral context.
195+
196+
.. autoclass:: select_ai.agent.AgentAttributes
197+
:members:
198+
199+
.. latex:clearpage::
200+
201+
.. autoclass:: select_ai.agent.Agent
202+
:members:
203+
204+
.. latex:clearpage::
205+
206+
Create Agent
207+
++++++++++++
208+
209+
.. literalinclude:: ../../../samples/agent/agent_create.py
210+
:language: python
211+
212+
output::
213+
214+
Created Agent: Agent(agent_name=MOVIE_ANALYST, attributes=AgentAttributes(profile_name='LLAMA_4_MAVERICK', role='You are an AI Movie Analyst. Your can help answer a variety of questions related to movies. ', enable_human_tool=False), description=None)
215+
216+
217+
.. latex:clearpage::
218+
219+
****
220+
Team
221+
****
222+
223+
AI Agent Team coordinates the execution of multiple agents working together to
224+
fulfill a user request. Each team is uniquely identified by a ``team_name`` and
225+
configured through a set of ``attributes`` that define its composition and
226+
execution strategy. The ``agents`` attribute specifies an array of agent-task
227+
pairings, allowing users to assign specific tasks to designated agents. User
228+
can perform multiple tasks by assigning the same agent to different tasks.
229+
The ``process`` attribute defines how tasks should be executed.
230+
231+
.. autoclass:: select_ai.agent.TeamAttributes
232+
:members:
233+
234+
.. latex:clearpage::
235+
236+
.. autoclass:: select_ai.agent.Team
237+
:members:
238+
239+
.. latex:clearpage::
240+
241+
Run Team
242+
++++++++
243+
244+
.. literalinclude:: ../../../samples/agent/team_create.py
245+
:language: python
246+
247+
output::
248+
249+
To list the movies, you can use the SQL query: SELECT m.* FROM "SPARK_DB_USER"."MOVIE" m.

doc/source/user_guide/vector_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ output::
229229

230230
OracleVectorIndexAttributes(chunk_size=1024, chunk_overlap=128, location='https://objectstorage.us-ashburn-1.oraclecloud.com/n/dwcsdev/b/conda-environment/o/tenant1-pdb3/graph', match_limit=5, object_storage_credential_name='my_oci_ai_profile_key', profile_name='oci_vector_ai_profile', refresh_rate=1450, similarity_threshold=0.5, vector_distance_metric='COSINE', vector_db_endpoint=None, vector_db_credential_name=None, vector_db_provider=<VectorDBProvider.ORACLE: 'oracle'>, vector_dimension=None, vector_table_name=None, pipeline_name='TEST_VECTOR_INDEX$VECPIPELINE')
231231

232+
.. latex:clearpage::
232233
233234
Async RAG using vector index
234235
++++++++++++++++++++++++++++

samples/agent/agent_create.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
import select_ai
4+
from select_ai.agent import (
5+
Agent,
6+
AgentAttributes,
7+
)
8+
9+
user = os.getenv("SELECT_AI_USER")
10+
password = os.getenv("SELECT_AI_PASSWORD")
11+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
12+
13+
select_ai.connect(user=user, password=password, dsn=dsn)
14+
15+
# Agent
16+
agent_attributes = AgentAttributes(
17+
profile_name="LLAMA_4_MAVERICK",
18+
role="You are an AI Movie Analyst. "
19+
"Your can help answer a variety of questions related to movies. ",
20+
enable_human_tool=False,
21+
)
22+
agent = Agent(
23+
agent_name="MOVIE_ANALYST",
24+
attributes=agent_attributes,
25+
)
26+
agent.create(enabled=True, replace=True)
27+
print("Created Agent:", agent)

samples/agent/movie_analyst.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import uuid
3+
4+
import select_ai
5+
from select_ai.agent import (
6+
Agent,
7+
AgentAttributes,
8+
Task,
9+
TaskAttributes,
10+
Team,
11+
TeamAttributes,
12+
)
13+
14+
user = os.getenv("SELECT_AI_USER")
15+
password = os.getenv("SELECT_AI_PASSWORD")
16+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
17+
18+
select_ai.connect(user=user, password=password, dsn=dsn)
19+
20+
# Agent
21+
agent_attributes = AgentAttributes(
22+
profile_name="oci_ai_profile",
23+
role="You are an AI Movie Analyst. "
24+
"Your can help answer a variety of questions related to movies. ",
25+
enable_human_tool=False,
26+
)
27+
agent = Agent(
28+
agent_name="MOVIE_ANALYST",
29+
attributes=agent_attributes,
30+
)
31+
agent.create(enabled=True, replace=True)
32+
print("Create Agent", agent)
33+
34+
# Task
35+
task_attributes = TaskAttributes(
36+
instruction="Help the user with their request about movies. "
37+
"User question: {query}",
38+
enable_human_tool=False,
39+
)
40+
task = Task(
41+
task_name="ANALYZE_MOVIE_TASK",
42+
description="Movie task involving a human",
43+
attributes=task_attributes,
44+
)
45+
task.create(replace=True)
46+
print("Created Task", task)
47+
48+
# Team
49+
team_attributes = TeamAttributes(
50+
agents=[{"name": "MOVIE_ANALYST", "task": "ANALYZE_MOVIE_TASK"}],
51+
process="sequential",
52+
)
53+
team = Team(
54+
team_name="MOVIE_AGENT_TEAM",
55+
attributes=team_attributes,
56+
)
57+
team.create(enabled=True, replace=True)
58+
print(
59+
team.run(
60+
prompt="In the movie Titanic, was there enough space for Jack ? ",
61+
params={"conversation_id": str(uuid.uuid4())},
62+
)
63+
)

0 commit comments

Comments
 (0)