The world of Large Language Models (LLMs) is evolving rapidly. We’ve moved beyond simple chat interactions to creating “Agents” — AI entities that can understand instructions, use tools, and take actions to achieve goals. For a foundational understanding of this concept, Google’s Agents white paper is a great resource.
Imagine the transformative potential of bringing this agent capability directly into your SAP environment or SAP BTP, empowering AI to interact with your ABAP functionalities and automate tasks. Exciting, isn’t it?
This post provides a practical starting point for building such intelligent agents using ABAP. Think of this as your initial blueprint, and we eagerly encourage you to contribute your own innovative ideas to evolve the realm of ABAP-based agents!
Forget static programs; envision an LLM empowered with the ability to interact with your SAP system. In our context, an ABAP Agent is essentially an LLM supercharged with:
To simplify the interaction with Google’s cutting-edge Generative AI models (like Gemini) from within your ABAP environment, Google Cloud provides an official and powerful SDK for ABAP. We will primarily leverage the /goog/cl_generative_model
class, utilizing its key features:
set_system_instructions()
: To precisely define our agent's behavior and capabilities through the system prompt.add_function_declaration()
: To clearly inform the LLM about the ABAP "tools" (Function Modules) it has at its disposal, including their names and expected parameters.set_auto_invoke_sap_function()
: A game-changer! This allows the SDK to automatically execute the ABAP Function Module when the LLM determines it's the appropriate tool to use.generate_content()
: The core method to send the user's request to the agent and receive its response, which might involve seamless internal calls to ABAP functionalities.Prerequisite: Ensure you have already installed and configured the ABAP SDK for Google Cloud and set up the Vertex AI SDK to work with Gemini. Refer to the official Google Cloud documentation for detailed setup instructions.
Our initial goal is to construct a foundational agent(skeleton) capable of understanding user requests related to weather and air quality and using specific ABAP functions to fetch the required data. Imagine a user asking, “What’s the air quality like in my current location?” and the agent intelligently figuring out how to answer.
The following outlines the architecture and component design of our initial agent framework:
To create a reusable and well-structured agent, we will develop the following ABAP objects:
ZCL_GEMINI_AGENT_BASE
(Abstract Class): This serves as the bedrock for all our agents. It provides the common logic for interacting with the ABAP SDK, manages resources (via a close
method), and defines the structure for shared components like tools. Crucially, it defines abstract methods that specific agent implementations must implement, ensuring consistency.ZCL_WEATHER_AGENT
(Concrete Class): This is our specific agent dedicated to handling weather and air quality inquiries. It inherits from ZCL_GEMINI_AGENT_BASE
and provides the concrete details for this use case, such as the specific system instructions tailored for weather-related tasks, the list of relevant weather and air quality tools, and the desired AI model ID.Z_TOOL_GET_CURRENT_LOCATION
(Function Module): An example of a "tool" – this function module simulates retrieving the user's current location (for simplicity in this initial example).Z_TOOL_GET_GEOCODE
(Function Module): Another example tool, this function module would take a location as input and return its geographical coordinates (latitude and longitude).Z_TOOL_GET_AIR_QUALITY
(Function Module): This tool would take geographical coordinates as input and return the corresponding air quality data.ZDEMO_USE_WEATHER_AGENT
(Report): A straightforward ABAP report demonstrating how to instantiate and interact with our ZCL_WEATHER_AGENT
, showcasing its capabilities.The framework’s structure can be visualized as follows:
Once this foundational framework is implemented, interacting with our weather agent becomes remarkably simple:
DATA(lv_prompt) = 'What is the air quality in my current location?'
DATA(lo_weather_agent) = NEW zcl_weather_agent( ).
lo_weather_agent->initialize_agent( ).
DATA(lv_response) = lo_weather_agent->process_prompt( iv_prompt = lv_prompt ).
Example output
Based on the simulated tools, the agent might respond with something like:
It uses the automatic function chaining capability of the SDK to traverse through the different tools.
You can explore and contribute to this sample code skeleton on GitHub:
In our next exciting installment, we will extend this agent’s capabilities to demonstrate seamless hand-offs to other specialized agents developed using Google’s powerful Agent Development Kit and deployed on Vertex AI Agent Engine. We will also delve into the fascinating world of interacting with Model Context Protocol (MCP Server) via the Vertex AI Agent Engine!
⭐️ Happy Learning! and Happy Innovating! ⭐️