Skip to content

Commit 7a46bf2

Browse files
committed
Added more samples for AI agent
1 parent 7228d46 commit 7a46bf2

File tree

6 files changed

+166
-15
lines changed

6 files changed

+166
-15
lines changed

doc/source/user_guide/agent.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,30 @@ Python layer and persist the tool in the Database using
4646
- ``smtp_host``
4747
* - ``HTTP``
4848
- ``select_ai.agent.Tool.create_http_tool``
49-
- ``tool_name``, ``credential_name``, ``endpoint``
49+
- - ``tool_name``
50+
- ``credential_name``
51+
- ``endpoint``
5052
* - ``SQL``
5153
- ``select_ai.agent.Tool.create_sql_tool``
52-
- ``tool_name``, ``profile_name``
54+
- - ``tool_name``
55+
- ``profile_name``
5356
* - ``SLACK``
5457
- ``select_ai.agent.Tool.create_slack_notification_tool``
55-
- ``tool_name``, ``credential_name``, ``slack_channel``
58+
- - ``tool_name``
59+
- ``credential_name``
60+
- ``slack_channel``
5661
* - ``WEBSEARCH``
5762
- ``select_ai.agent.Tool.create_websearch_tool``
58-
- ``tool_name``, ``credential_name``
63+
- - ``tool_name``
64+
- ``credential_name``
5965
* - ``PL/SQL custom tool``
6066
- ``select_ai.agent.Tool.create_pl_sql_tool``
61-
- ``tool_name``, ``function``
67+
- - ``tool_name``
68+
- ``function``
6269
* - ``RAG``
6370
- ``select_ai.agent.Tool.create_rag_tool``
64-
- ``tool_name``, ``profile_name``
71+
- - ``tool_name``
72+
- ``profile_name``
6573

6674
.. latex:clearpage::
6775

samples/agent/websearch_agent.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import os
2+
3+
import select_ai
4+
from select_ai.agent import (
5+
Agent,
6+
AgentAttributes,
7+
Task,
8+
TaskAttributes,
9+
Team,
10+
TeamAttributes,
11+
Tool,
12+
)
13+
14+
OPEN_AI_CREDENTIAL_NAME = "OPENAI_CRED"
15+
OPEN_AI_PROFILE_NAME = "OPENAI_PROFILE"
16+
SELECT_AI_AGENT_NAME = "WEB_SEARCH_AGENT"
17+
SELECT_AI_TASK_NAME = "WEB_SEARCH_TASK"
18+
SELECT_AI_TOOL_NAME = "WEB_SEARCH_TOOL"
19+
SELECT_AI_TEAM_NAME = "WEB_SEARCH_TEAM"
20+
21+
USER_QUERIES = {
22+
"d917b055-e8a1-463a-a489-d4328a7b2210": "What are the key features for the product highlighted at this URL https://www.oracle.com/artificial-intelligence/database-machine-learning",
23+
"c2e3ff20-f56d-40e7-987c-cc72740c75a5": "What is the main topic at this URL https://www.oracle.com/artificial-intelligence/database-machine-learning",
24+
"25e23a25-07b9-4ed7-be11-f7e5e445d286": "What is the main topic at this URL https://openai.com",
25+
}
26+
27+
# connect
28+
user = os.getenv("SELECT_AI_USER")
29+
password = os.getenv("SELECT_AI_PASSWORD")
30+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
31+
select_ai.connect(user=user, password=password, dsn=dsn)
32+
33+
# Create Open AI credential
34+
select_ai.create_credential(
35+
credential={
36+
"credential_name": OPEN_AI_CREDENTIAL_NAME,
37+
"username": "OPENAI",
38+
"password": os.getenv("OPEN_AI_API_KEY"),
39+
},
40+
replace=True,
41+
)
42+
print("Created credential: ", OPEN_AI_CREDENTIAL_NAME)
43+
44+
# # Create Open AI Profile
45+
profile = select_ai.Profile(
46+
profile_name=OPEN_AI_PROFILE_NAME,
47+
attributes=select_ai.ProfileAttributes(
48+
credential_name=OPEN_AI_CREDENTIAL_NAME,
49+
provider=select_ai.OpenAIProvider(model="gpt-4.1"),
50+
),
51+
description="My Open AI Profile",
52+
replace=True,
53+
)
54+
print("Created profile: ", OPEN_AI_PROFILE_NAME)
55+
56+
# Create an AI Agent team
57+
team = Team(
58+
team_name=SELECT_AI_TEAM_NAME,
59+
attributes=TeamAttributes(
60+
agents=[{"name": SELECT_AI_AGENT_NAME, "task": SELECT_AI_TASK_NAME}]
61+
),
62+
)
63+
team.create(replace=True)
64+
65+
# Agent
66+
agent = Agent(
67+
agent_name=SELECT_AI_AGENT_NAME,
68+
attributes=AgentAttributes(
69+
profile_name=OPEN_AI_PROFILE_NAME,
70+
enable_human_tool=False,
71+
role="You are a specialized web search agent that can access web page contents and respond to questions based on its content.",
72+
),
73+
)
74+
agent.create(replace=True)
75+
76+
# Task
77+
task = Task(
78+
task_name=SELECT_AI_TASK_NAME,
79+
attributes=TaskAttributes(
80+
instruction="Answer the user question about the provided URL:{query}",
81+
enable_human_tool=False,
82+
tools=[SELECT_AI_TOOL_NAME],
83+
),
84+
)
85+
task.create(replace=True)
86+
87+
# Tool
88+
web_search_tool = Tool.create_websearch_tool(
89+
tool_name=SELECT_AI_TOOL_NAME,
90+
credential_name=OPEN_AI_CREDENTIAL_NAME,
91+
description="Web Search Tool using OpenAI",
92+
replace=True,
93+
)
94+
print("Created tool: ", SELECT_AI_TOOL_NAME)
95+
96+
# Run the Agent Team
97+
for conversation_id, prompt in USER_QUERIES.items():
98+
response = team.run(
99+
prompt=prompt, params={"conversation_id": conversation_id}
100+
)
101+
print(response)

samples/enable_ai_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323

2424
select_ai.connect(user=admin_user, password=password, dsn=dsn)
2525
select_ai.enable_provider(
26-
users=select_ai_user, provider_endpoint="*.openai.azure.com"
26+
users=select_ai_user, provider_endpoint="api.OPENAI.com"
2727
)
2828
print("Enabled AI provider for user: ", select_ai_user)

src/select_ai/agent/task.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
import json
99
from abc import ABC
1010
from dataclasses import dataclass
11-
from typing import AsyncGenerator, Iterator, List, Mapping, Optional, Union
11+
from typing import (
12+
Any,
13+
AsyncGenerator,
14+
Iterator,
15+
List,
16+
Mapping,
17+
Optional,
18+
Union,
19+
)
1220

1321
import oracledb
1422

@@ -168,9 +176,15 @@ def delete(self, force: bool = False):
168176
)
169177

170178
def disable(self):
179+
"""
180+
Disable AI Task
181+
"""
171182
pass
172183

173184
def enable(self):
185+
"""
186+
Enable AI Task
187+
"""
174188
pass
175189

176190
@classmethod
@@ -217,9 +231,15 @@ def fetch(cls, task_name: str) -> "Task":
217231
pass
218232

219233
def set_attributes(self, attributes: TaskAttributes):
234+
"""
235+
Set AI Task attributes
236+
"""
220237
pass
221238

222-
def set_attribute(self):
239+
def set_attribute(self, attribute_name: str, attribute_value: Any):
240+
"""
241+
Set a single AI Task attribute specified using name and value
242+
"""
223243
pass
224244

225245

src/select_ai/agent/team.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,15 @@ def delete(self, force: Optional[bool] = False):
168168
)
169169

170170
def disable(self):
171+
"""
172+
Disable the AI agent team
173+
"""
171174
pass
172175

173176
def enable(self):
177+
"""
178+
Enable the AI agent team
179+
"""
174180
pass
175181

176182
@classmethod
@@ -232,11 +238,12 @@ def run(self, prompt: str = None, params: Mapping = None):
232238
WAITING_FOR_HUMAN state, the input serves as the human response.
233239
234240
:param Mapping[str, str] params: Optional parameters for the task.
235-
This supports:
236-
1) conversation_id: Identifies the conversation session associated
237-
with the agent team
238-
2) variables: key-value pairs that provide additional input to
239-
the agent team.
241+
Currently, the following parameters are supported:
242+
243+
- conversation_id: Identifies the conversation session associated
244+
with the agent team
245+
246+
- variables: key-value pairs that provide additional input to the agent team.
240247
241248
"""
242249
parameters = {
@@ -260,7 +267,14 @@ def run(self, prompt: str = None, params: Mapping = None):
260267
return result
261268

262269
def set_attributes(self, attributes: TeamAttributes) -> None:
270+
"""
271+
Set the attributes of the AI Agent team
272+
"""
263273
pass
264274

265275
def set_attribute(self, attribute_name: str, attribute_value: Any) -> None:
276+
"""
277+
Set the attribute of the AI Agent team specified by
278+
`attribute_name` and `attribute_value`.
279+
"""
266280
pass

src/select_ai/agent/tool.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def create_built_in_tool(
315315
cls,
316316
tool_name: str,
317317
tool_params: ToolParams,
318+
tool_type: ToolType,
318319
description: Optional[str] = None,
319320
replace: Optional[bool] = False,
320321
) -> Tool:
@@ -324,6 +325,7 @@ def create_built_in_tool(
324325
:param str tool_name: The name of the tool
325326
:param select_ai.agent.ToolParams tool_params:
326327
Parameters required by built-in tool
328+
:param select_ai.agent.ToolType tool_type: The built-in tool type
327329
:param str description: Description of the tool
328330
:param bool replace: Whether to replace the existing tool.
329331
Default value is False
@@ -336,7 +338,7 @@ def create_built_in_tool(
336338
"type select_ai.agent.ToolParams"
337339
)
338340
attributes = ToolAttributes(
339-
tool_params=tool_params, tool_type=ToolType.SQL
341+
tool_params=tool_params, tool_type=tool_type
340342
)
341343
tool = cls(
342344
tool_name=tool_name, attributes=attributes, description=description
@@ -378,6 +380,7 @@ def create_email_notification_tool(
378380
)
379381
return cls.create_built_in_tool(
380382
tool_name=tool_name,
383+
tool_type=ToolType.EMAIL,
381384
tool_params=email_notification_tool_params,
382385
description=description,
383386
replace=replace,
@@ -397,6 +400,7 @@ def create_http_tool(
397400
)
398401
return cls.create_built_in_tool(
399402
tool_name=tool_name,
403+
tool_type=ToolType.HTTP,
400404
tool_params=http_tool_params,
401405
description=description,
402406
replace=replace,
@@ -450,6 +454,7 @@ def create_rag_tool(
450454
tool_params = RAGToolParams(profile_name=profile_name)
451455
return cls.create_built_in_tool(
452456
tool_name=tool_name,
457+
tool_type=ToolType.RAG,
453458
tool_params=tool_params,
454459
description=description,
455460
replace=replace,
@@ -476,6 +481,7 @@ def create_sql_tool(
476481
tool_params = SQLToolParams(profile_name=profile_name)
477482
return cls.create_built_in_tool(
478483
tool_name=tool_name,
484+
tool_type=ToolType.SQL,
479485
tool_params=tool_params,
480486
description=description,
481487
replace=replace,
@@ -507,6 +513,7 @@ def create_slack_notification_tool(
507513
)
508514
return cls.create_built_in_tool(
509515
tool_name=tool_name,
516+
tool_type=ToolType.SLACK,
510517
tool_params=slack_notification_tool_params,
511518
description=description,
512519
replace=replace,
@@ -536,6 +543,7 @@ def create_websearch_tool(
536543
)
537544
return cls.create_built_in_tool(
538545
tool_name=tool_name,
546+
tool_type=ToolType.WEBSEARCH,
539547
tool_params=web_search_tool_params,
540548
description=description,
541549
replace=replace,

0 commit comments

Comments
 (0)