Build Your First AI Agent in Oracle APEX, Step by Step
Tutorial

Build Your First AI Agent in Oracle APEX, Step by Step

ASKLYZE Team
ASKLYZE TeamAuthor
7 Mins Read
Oct 17, 2026

Reading about agents is one thing. Building one takes about twenty minutes, and you learn more from those twenty minutes than from any slide deck. In this walkthrough we'll build an order assistant for a simple sales app on APEX 26.x. It will answer questions about a customer's orders and, with confirmation, flag an order for follow-up.

We'll assume you have an ORDERS table with columns like ORDER_ID, CUSTOMER_ID, STATUS, ORDER_TOTAL and ORDER_DATE.

Step 1: Create a Generative AI Service

Go to App Builder > Workspace Utilities > Generative AI and click Create.

  • Pick a provider. APEX supports OCI Generative AI, OpenAI, Cohere, Google Gemini, Anthropic Claude, Mistral AI, Ollama for local models, and any OpenAI-compatible endpoint.
  • Give it a name and paste your API key. APEX stores it as a Web Credential.
  • Click Test Connection. You want to see "Connection Succeeded!".
  • Optionally set Maximum AI Tokens to cap usage per 24 hours. Do it now, before someone leaves a test loop running over the weekend.

Step 2: Set the application default

Open your application, go to Edit Application Definition > AI, and select the service you just created. You can also write a Consent Message. Users see it the first time they use an AI feature, and their accept or deny choice is stored as a preference.

Step 3: Create the agent

Go to Shared Components > Generative AI > AI Agents > Create.

  • Name: Order Assistant
  • Static ID: order_assistant
  • System Prompt: something like "You help sales reps understand customer orders. Use the available tools to look up data. Never guess numbers. If you can't find something, say so."
  • Welcome Message: "Hi! Ask me about this customer's orders."
  • Response Format: Text

Keep the temperature low. You want accurate answers, not creative ones.

Step 4: Add a Retrieve Data tool

On the agent's Tools tab click Add Tool and choose Retrieve Data.

  • Name it customer_orders and write a clear description: "Returns the current customer's orders with status, total and date."
  • Execution point: On Demand.
  • Type: SQL Query, for example selecting the order columns where customer_id = :P10_CUSTOMER_ID order by order_date desc.
  • Set Maximum Tokens so a customer with 5,000 orders doesn't blow up the prompt.

Because the query uses a page item, the model can only see orders for the customer on screen.

Step 5: Add an action tool with confirmation

Add a second tool, this time Execute Server-side Code.

  • Name: flag_for_followup, with a parameter for the order ID.
  • PL/SQL: update the order's follow-up flag.
  • Turn on Requires Confirmation and add a notification message like "Order flagged for follow-up."

Now the agent can propose the action, but the user has to approve it.

Step 6: Put it on a page

On the customer page, add a button called AI_ASSISTANT. Create a Click dynamic action with a True action of Show AI Assistant.

  • Generative AI, Agent: Order Assistant
  • Items to Submit: P10_CUSTOMER_ID, so the tool query has a value
  • Display As: Dialog, or Inline if you want it inside a region
  • Add a couple of Quick Actions such as "Summarize open orders".

Run the page, click the button and ask "What's the biggest open order?" Then try "Flag it for follow-up" and watch the confirmation appear.

What to check before going live

  • Ask questions the agent should refuse. It will tell you whether your system prompt is clear.
  • Look at Agent Utilization to see token usage per conversation.
  • Test with a user who should not see other customers' data. Your tools run with the user's session, so your normal security still applies, but check it anyway.

That's a working agent. From here you can add tools one at a time, which is exactly how you should grow it.

Sources: Creating Generative AI Service Objects, Managing AI Agents and AI Tools, Creating a Dynamic Action to Display AI Assistant