
This blog provides a primer on how you can build AI Agents that can automatically call RAP APIs to perform various business process actions in SAP ERP systems such as S/4HANA.
AI agents are sophisticated software systems designed to perceive business context, make intelligent decisions, and take autonomous actions to achieve specific goals or complete tasks on behalf of users.
Let’s imagine a scenario where an SAP user is tasked with “Cancelling all purchase orders for blocked vendors”. The user would then need to perform the following steps :
- Finding all newly blocked vendors in SAP
- For each vendor, find a list of open purchase orders
- For each purchase order, set the status as canceled
This can be a cumbersome task !
Let’s explore how easy it is to build a smart Purchasing Agent by using Google Vertex AI SDK for ABAP & Prompt Engineering that automagically call SAP released RAP APIs.
If you need a quick introduction to Agents, Read this blog from Ameya Suvarna.
First, we add a system instruction that tells AI model what actions it can propose in response to user queries.
You are a helpful Purchasing Bot Your capabilities include:
* Getting a list and details of vendors & their current block status
* Getting a list of Purchase Orders and its corresponding details
* Performing various CRUD operations on Purchase Orders. Please use the tools to get any missing information.
You are strictly limited to these tasks.
Do not perform any other actions or
provide information outside of purchasing related operations.
A key note here is that AI model does not perform the action, instead it merely tells the calling application what it should do next.
Second, we add various RAP APIs released by SAP as tools that the agent can call.
For the purchasing agent, we can use 2 APIs that can perform various tasks
- API_BUSINESS_PARTNER can be used to get blocked vendors
- API_PURCHASEORDER_2 can be used to get a list of Purchase Orders. It can be used to update purchase orders as well
Here’s how you can create a list of tools by using standard RAP Service Definitions.
r_result = VALUE #(
( name = 'API_BLOCKED_VENDORS' " Tool-1
description = 'API returns a list of vendors that are blocked'
implementation =
VALUE #( service = 'API_BUSINESS_PARTNER'
version = 'V2'
entity = 'A_BusinessPartner'
cds_name = 'A_BUSINESSPARTNER'
cds_column = 'SUPPLIER'
operation = 'GET'
const_qp = VALUE #( (
name = 'BUSINESSPARTNERISBLOCKED' value = 'X' ) ) )
parameters = VALUE tt_tool_parameters( ) )
( name = 'API_PURCHASE_ORDER_READ' " Tool-2
description = 'Get a list of purchase orders for a given set of vendors'
implementation =
VALUE #( service = 'API_PURCHASEORDER_2'
version = 'V4'
cds_name = 'A_PURCHASEORDER_2'
cds_column = 'PURCHASEORDER'
entity = 'PURCHASEORDER'
operation = 'GET' )
parameters = VALUE tt_tool_parameters(
type = 'string'
is_required = abap_true
( name = 'SUPPLIER' description = 'Business partner who offers or provides materials or services' ) ) )
( name = 'API_PURCHASE_ORDER_CANCEL' " Tool-3
description = 'Cancel Purchase Orders'
implementation =
VALUE #( service = 'API_PURCHASEORDER_2'
version = 'V4'
cds_name = 'A_PURCHASEORDER_2'
cds_column = 'PURCHASEORDER'
entity = 'PURCHASEORDER'
operation = 'PATCH'
upd_param = VALUE #( (
name = 'PURCHASEORDERDELETIONCODE' value = 'X' ) ) ) "Deletion
parameters = VALUE tt_tool_parameters( type = 'string'
is_required = abap_true
( name = 'PURCHASEORDER' description = 'Purchase Order Number' ) ) ) ).
Here’s how our Purchasing agent looks
That’s it, your Agent is ready to serve !
Here’s the test data, which includes a blocked vendor and corresponding Purchase Order
Let’s start with simple tasks that only require a single API call.
The AI model made an intelligent decision that the API_BLOCKED_VENDORS should be called for the user prompt.
Let’s try one more simple prompt –
Let’s move on tasks with medium complexity with a prompt “Give me Purchase orders for vendors that are blocked”.
Again, the AI Agent is intelligently chaining tool calls by first getting list of blocked vendors and then using that list to get the list of purchase orders
Finally, lets see if the Agent can perform correct set of steps for prompt “Cancel all open purchase orders for vendors that are blocked”
Even for a complex prompt, the agent intelligently chained calls to 3 tools:
- Getting the list of blocked vendors, then,
- Getting list of purchase orders for those vendors, and
- Finally, cancelling the orders by setting appropriate status.
While the demo shows how to run this using a standalone program, you can embed the functionality into your own Chat assistant that is embedded into your Fiori Launchpad.
The sample code of Purchasing Agent is available on Github. The repo also includes several other examples on how to use Vertex AI to build GenAI applications in SAP.
As you can see, Vertex AI SDK for ABAP makes it easy to build AI agents 🤖 for your SAP processes.
By passing RAP Service Metadata as tools to the AI model, you can build Agentic workflows that can automatically call RAP services with correct payload. What’s more, because the agent runs within SAP, it uses the underlying authorizations of SAP user.
Start building AI agents with Vertex AI SDK for ABAP today !
Stay tuned for more. Until next time, Happy Learning and Happy Innovating!
Source Credit: https://medium.com/google-cloud/abap-rap-agents-ceba63797ade?source=rss—-e52cf94d98af—4