|
| 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. |
0 commit comments