Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Develop a Simple AI Agent Tool using Oracle Cloud Infrastructure Generative AI and REST APIs
Introduction
The use of Large Language Models (LLM) has revolutionized the way we interact with systems and business processes. With the ability to understand natural language and integrate with legacy services, these models make applications more intelligent and efficient.
This material aims to demonstrate, through a practical example, how LLM concepts can be applied to optimize integrations with legacy systems. By using AI agents, it is possible to significantly reduce the complexity of API consumption, making process automation more flexible and accessible.
Throughout the document, common scenarios will be presented where the application of AI agents can simplify business operations, reducing the need for manual configuration and facilitating communication between different systems.
Use LLM models to understand business processes and direct execution for legacy services. Understanding is possible through the inclusion of context, which greatly facilitates and speeds up the construction of applications. LLM models use natural language, including translation into several other languages.
The following tutorial will show how to build a simple application based on a legacy. When there is a legacy of APIs, the use of AI agents allows for powerful integrations. Applying LLM concepts to AI agents often allows for solving complex API consumption problems. Without AI, an API requires a lot of work for integration, as it involves knowing all the input and output attributes
Objectives
- Develop a simple AI agent tool using OCI Generative AI and REST APIs.
Task 1: Download and Understand the Code
Download the code from here: agent_ocigenai.py.
The code is divided in five modules:
Simple Database Persistence Services: The code defines the creation of a simple database for insert, delete, query and summarize the order.
Service Definition::The code defines several services, such as insert_order
, delete_order
, search_order
, order_cost
, and delivery_address
. These services are decorated with the @tool decorator, which indicates that they can be called by the conversational agent.
Language Model Definition: The code uses the ChatOCIGenAI language model to generate responses to user questions.
Conversational Agent Definition: The code creates a conversational agent using LangChain’s create_tool_calling_agent
function, passing as parameters the language model, the defined services and a prompt template.
Conversational Loop: The code enters an infinite loop, where it waits for user input and processes responses using the conversational agent.
-
Database Services:
To store the data into a simple database, this demo creates a SQLite3 database for persistence. These services will be used in the Business Services.
-
REST Services:
These services are used to define the REST calls. For the example of fetching the address from the zip code, a call is being made to the OCI API Gateway which exposes an integration built in Oracle Integration to get the address from a microservice on Oracle Cloud Infrastructure Kubernetes Engine (OKE).
-
Business Services:
When implementing business services, it is possible to expose these services so that OCI Generative AI can better explore each of them. This is possible through a library called
langchain_core.tools
, which is capable of interpreting a given context in natural language and associating it with a specific business service. When declaring the services that will be part of the business logic, it is possible to declare aliases in the docstrings of each of them to help contextualize them.As well as the context declaration is necessary in the prompt to use the AI model.
In each service definition, it is possible to determine a specific context so that, when sending a request in natural language, the library can interpret what was requested and determine which appropriate service should be executed.
The langchain_core.tools
library understands the scope of work by associating the contexts and services available for use. This is done by the declaration shown in the following image.
Another interesting point about the langchain_core.tools
library is that the service signature attributes are also interpreted, that is, the library itself determines how to forward the request in natural language and define the attributes of the parameters of the service in question. This is already very impressive in itself, as it greatly reduces the implementation burden on integrations. In the traditional integration model, there is time to be spent defining the FROM-TO between the source and destination of these integrations. This is a very reasonable effort. In the agent AI model, it is through the context that the attributes are passed, that is, the library can determine what each parameter is and pass it to the service in the correct way.
Task 2: Modify the Code
You can test and modify the code for your purposes. The service named delivery_address
was implemented calling a REST API. In this example, you can test the code and change the real REST request to a fake request.
-
Comment the following code by putting
#
into the lines. -
Uncomment the following code.
You can integrate your own API using the OCI resources, you can use:
- OCI API Gateway
- Oracle Integration
- OCI Kubernetes Engine
- OCI Streaming
And you can integrate with on-premises or other cloud resources.
Task 3: Configure the Code
-
This python code needs some libraries. So you need to download the requirements.txt file. This file contains the libraries.
-
Run the following command to install the libraries.
pip install -r requirements.txt
-
You need to configure the Oracle Cloud Infrastructure Command Line Interface (OCI CLI) and link with your tenancy. To install and configure, see Installing the OCI-CLI.
-
Configure a compartment to store your resources for the OCI Generative AI. Update
compartment_id
and keepauth_profile
as DEFAULT.
Task 4: Run the Code
Run the code using the following command.
python agent_ocigenai.py
Scenarios for AI Agents
There are several scenarios for integrations with multiple REST APIs and the use of agents AI. The complexities between mapping business information and available APIs are many. This is very common in several corporate business situations. Here are some examples where an agents AI can facilitate this task:
-
Financial Process Automation (ERP and Banks)
- Scenario: Companies need to integrate with multiple banks to obtain statements, generate payment slips, process payments and validate tax information.
- Challenges: Each bank has its own API, with specific parameters for payments, PIX, transfers and financial reconciliation.
- How AI Agents helps: It can interpret requests such as Pay the invoice for supplier X and redirect to the correct bank API with the required parameters.
-
Order Management and Logistics (E-commerce, ERP, WMS)
- Scenario: An e-commerce needs to orchestrate orders, update inventories and request carriers for different types of delivery.
- Challenges: Carrier APIs vary (Post Office, FedEx, DHL, local carriers), requiring specific request formats.
- How AI Agents helps: It can translate requests like Ship this order via the cheapest carrier and automatically select the right service.
-
Customer Service and Helpdesk
- Scenario: Companies with CRMs like Siebel, Oracle CX, ServiceNow need to integrate customer requests with different APIs.
- Challenges: Each system has different endpoints for creating tickets, updating statuses, retrieving customer information, and tracking history.
- How AI Agents helps: It can understand requests like Show me the last calls from customer X and call the correct CRM API.
-
HR and Payroll Integration
- Scenario: HR systems need to synchronize payroll, benefits, and onboarding across multiple vendors and ERPs.
- Challenges: Benefits, payroll, and talent management APIs have different regulatory parameters and validations.
- How AI Agents helps: It can interpret commands like Admit new employee to payroll and translate that into appropriate calls to the right APIs.
-
Infrastructure and Security Monitoring (SIEM and ITSM)
- Scenario: Large enterprises use multiple monitoring systems (Splunk, Datadog, ServiceNow, Zabbix) to track incidents and anomalies.
- Challenges: Each tool has a different API for alerts, logs, and automated responses.
- How AI Agents helps: It can interpret commands like List the latest critical alerts and open a ticket in ServiceNow.
-
Contract Management and Digital Signatures
- Scenario: Companies use services like DocuSign and Adobe Sign to manage contracts and signatures.
- Challenges: Each service has different requirements for sending documents, validating signatures, and tracking status.
- How AI Agents helps: It might receive a request like Send this contract to client X for signature and notify me when it’s signed, and direct it to the correct API.
-
Healthcare Management and Electronic Medical Records (HIS, PACS, LIS, ERP)
- Scenario: Hospitals and clinics use different systems to store patient information, lab tests, and medical images.
- Challenges: APIs from systems such as Tasy (Philips), MV, Epic, and PACS (DICOM image files) have different request formats.
- How AI Agents helps: It can interpret commands such as Retrieve patient John Smith’s latest blood test and attach it to the medical record, automatically calling the right APIs.
-
Telecommunications (Technical Support and Service Provisioning)
- Scenario: Telecommunications operators offer telephone, internet and TV services, and need to integrate multiple billing, CRM and network monitoring systems.
- Challenges: Each operation (for example, opening calls, changing plans, checking consumption) involves different APIs specific to each service.
- How AI Agents helps: It can understand I want to increase my internet allowance to 500 MB and trigger the correct API to upgrade the plan.
-
Insurance Automation (Claims and Policy Issuance)
- Scenario: Insurance companies need to integrate APIs for quoting, policy issuance, and claims.
- Challenges: Each insurance company has its own API, and the parameters vary depending on the type of insurance (vehicle, health, home).
- How AI Agents helps: It can translate a request like Register a claim for customer Pedro Souza’s car, with a side impact into automatic calls to the right APIs.
-
Foreign Trade and Customs Clearance
- Scenario: Companies that import/export need to deal with IRS APIs, international carriers, and customs control systems.
- Challenges: Each country has different rules and formats for documentation (DU-E, DI, Invoice, Packing List).
- How AI Agents helps: It can interpret Track the release of cargo X at the port of Santos and translate this into requests in the IRS and carriers API.
-
Hotel Management and Online Booking
- Scenario: Hotels need to integrate with platforms like Booking, Expedia, and Airbnb to manage reservations and room availability.
- Challenges: Each platform has different rules for cancellations, rate adjustments, and response times.
- How AI Agents helps: It can understand Adjust the rate to R$400 on Friday and block reservations for Monday and call the correct APIs.
-
Marketing Automation and Advertising Campaigns
- Scenario: Companies use tools such as Meta Ads, Google Ads, HubSpot and RD Station for digital campaigns.
- Challenges: Creating campaigns, segmenting audiences and analyzing metrics requires integration with multiple APIs.
- How AI Agents helps: It can interpret Create an ad on Facebook for the 25 to 40 year old audience interested in technology, with a budget of R$500 and configure the campaign automatically.
-
Supply Chain and Inventory Management
- Scenario: Large retail chains need to monitor inventory in real time and predict automatic replenishment.
- Challenges: ERP, WMS, and supplier systems have separate APIs for product requisition and demand forecasting.
- How AI Agents helps: It can understand Replenish product X when it reaches 10 units and trigger the right APIs.
-
Integration of Chatbots and Omnichannel Service
- Scenario: Companies offer support via WhatsApp, Telegram, email and chatbot, needing to centralize everything in the CRM.
- Challenges: Different APIs for each channel, with different rules for automatic responses and routing.
- How AI Agents helps: It can interpret Forward this payment question to a human attendant and redirect to the correct channel.
-
Energy Management and IoT (Smart Grid)
- Scenario: Electric power companies use APIs to measure consumption, forecast demand and preventative maintenance.
- Challenges: IoT systems, sensors and energy distributors have different and regulated APIs.
- How AI Agents helps: It can understand Monitor the consumption of factory X and notify me if it exceeds 100 kWh and configure automatic alerts.
Next Steps
The adoption of AI agents powered by LLMs has demonstrated enormous potential to streamline integration with legacy systems. By interpreting natural language commands and translating requests into accurate API calls, these agents significantly reduce the complexity of automating business processes.
The examples presented here demonstrate how this approach can be applied to a variety of industries, from finance and logistics to customer service and infrastructure monitoring. The ability of AI agents to dynamically adapt to different services and contexts provides a new level of flexibility and efficiency in the digital transformation of companies.
As AI models continue to evolve, these integrations are expected to become even more intelligent, enabling increasingly natural and accurate interactions between users and systems. The future of automation involves the combination of artificial intelligence and APIs, and AI agents are the key to this new era of digital connectivity.
Related Links
Acknowledgments
- Author - Cristiano Hoshikawa (Oracle LAD A-Team Solution Engineer)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Develop a Simple AI Agent Tool using Oracle Cloud Infrastructure Generative AI and REST APIs
G29022-01
Copyright ©2025, Oracle and/or its affiliates.