Integration Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction

A year ago, I published a VS Code extension that allows developers to write, run, and debug Groovy scripts locally in an environment that closely matches the SAP Cloud Integration (SAP CPI) runtime. You can learn more about the extension in my previous blog post: How to Debug SAP CPI Groovy Scripts Locally Using Visual Studio Code

Today, I'm excited to share a significant enhancement: I have created a custom AI agent and skill that help developers write SAP CPI Groovy scripts more efficiently using OpenCode directly within VS Code.

What is This Solution?

The AI Agent contains specific instructions about the project structure and best practices for working with the SAP CPI Groovy Script VS Code extension. It understands the SAP CPI environment and guides the AI model to generate appropriate code.

The Skill provides SAP CPI Groovy best practices, coding guidelines, and practical examples. This ensures that any AI-generated scripts are fully compatible with SAP Cloud Integration and follow industry standards.

OpenCode is an AI coding agent (similar to Claude Code and GitHub Codex) that runs directly in your terminal. It supports several free LLM providers with generous usage limits, making it an accessible option for developers. If you need extended usage, you can use OmniRoute, an open-source AI router that provides approximately 1.53 billion free tokens per month and can run locally on your laptop or server.

Prerequisites

Before you begin, ensure you have the following installed and configured:

  • OpenCode – The AI coding agent
  • Visual Studio Code – Your code editor
  • SAP CPI Groovy Script VS Code Extension – For local development and debugging
  • SAP CPI Tools Extension (Chrome) – For integration suite management
  • Custom AI Agent and Skill – I created an automated installation prompt to set these up
  • OmniRoute (optional) – For extended free token usage

Critical Step: Check Groovy and Java Version Compatibility

One of the most important aspects of SAP CPI development is ensuring your scripts are compatible with your tenant's Java and Groovy versions. Incompatible versions can cause runtime errors.

The SAP CPI Tools Extension (Chrome extension) makes this easy—it can automatically detect and display the default Java and Groovy versions used by your SAP Cloud Integration runtime. This information is essential:

  • When creating new scripts
  • When upgrading existing scripts
  • When configuring your AI agent to generate compatible code

JohanCalderon_0-1786114186301.png

JohanCalderon_1-1786114195114.png

Supported versions (as of the time of writing):

  • Java 17.0.19
  • Groovy 2.4.21
  • Groovy 4.0.29

Installation Steps

Step 1: Install OpenCode

Windows (from terminal):

 
winget install --id SST.opencode --exact

macOS / Linux (from terminal):

 
curl -fsSL https://opencode.ai/install | bash

JohanCalderon_2-1786114240715.png

After installation completes, close and reopen your terminal.

Step 2: Execute the Installation Prompt

If you want to change either the Java or Groovy version, download the file install.md https://github.com/nahhoj/SAP-CPI-AGENTS/blob/master/prompts/install.mdand update them in the Config Variables section

JohanCalderon_1-1786187189575.png

If you prefer, you can follow the instructions and install and configure everything manually.

I strongly recommend letting OpenCode install and configure everything using the prompt file instead.

Open your terminal and run OpenCode:

 
opencode

Then execute the installation prompt:

 
Run prompt https://github.com/nahhoj/SAP-CPI-AGENTS/blob/master/prompts/install.md

 

JohanCalderon_3-1786114291548.png

This automated prompt will install and configure the custom agent and skill on your machine. The process typically takes a few minutes to complete.

Feel free to customize this prompt to suit your own workflow.

JohanCalderon_0-1786186907004.png

Step 3: Verify Installation in OpenCode

Once installation is complete, close and open again it and verify that everything was set up correctly:

Check the agent:

 
/agent

Look for sap-cpi-groovy in the list.

JohanCalderon_4-1786114436084.png

Check the skill:

 
/skill

Look for sap-cpi-groovy-best-practice in the list.

JohanCalderon_5-1786114461585.png

Opening OpenCode in VS Code

  1. Open VS Code and navigate to your workspace folder
  2. Open the integrated terminal within VS Code
  3. Type opencode to launch the agent

You can now see your workspace path and start working with the SAP CPI agent.

JohanCalderon_6-1786114547351.png

Selecting Your Agent and Model

When you start coding, select the SAP CPI agent by pressing the Tab key to switch between available agents, then select sap-cpi-groovy.

JohanCalderon_7-1786114674384.png

 

By default, the agent uses the DeepSeek V4 Flash Free model. You can change this by typing:

 
/model

Then select a different model from the available options.

JohanCalderon_8-1786114701769.png

Creating Your First Project

Let's walk through two examples to demonstrate the agent's capabilities.

Example 1: Display Java and Groovy Versions

Prompt:

 
Create a project that prints the Java and Groovy versions to the message body as XML.

JohanCalderon_9-1786114778163.png

The agent will create a plan and show you what it will do — you can ask it to change anything before approving. Nothing is executed until you approve the plan.

JohanCalderon_0-1786188720133.png

After approval

Result: The AI agent generates a complete project structure with a script that outputs version information.

JohanCalderon_10-1786114814174.png

Example 2: Filter and Transform XML Data

Prompt:

 
Create a project that reads the XML payload from the message body (using the sample XML from https://learn.microsoft.com/en-us/dotnet/standard/linq/sample-xml-file-multiple-purchase-orders), filters purchase orders where the state is PA, and returns a JSON response containing only the basic information.

Result: The agent generates a full project with:

  • XML payload reading logic
  • State-based filtering
  • JSON transformation

JohanCalderon_11-1786114884002.png

Configuring Message Log Attachments

The generated scripts often use messageLog, which is an attachment feature in SAP CPI iFlows. To test this locally, configure the message log path in your VS Code settings.

Prompt:

 
Add to VS Code settings.json the property groovy.messagelog.path with value C:\Johan\SAPCPI\messageLog and restart the extension

After configuration, run your script again and check the specified folder for attachment output.

JohanCalderon_12-1786114969205.png

Testing in SAP Integration Suite

Once you're satisfied with your local testing:

  1. Deploy the iFlow to your SAP Cloud Integration tenant
  2. Verify execution using the SAP CPI Tools Chrome extension
  3. Check attachments to confirm expected output

The SAP CPI Tools Extension provides an easy interface to monitor script execution and validate results.

JohanCalderon_13-1786115016554.png

JohanCalderon_14-1786115026879.png

JohanCalderon_15-1786115033903.png

 

Tips for Success

  • Always verify version compatibility before deployment
  • Use the SAP CPI Tools Extension to detect your tenant's supported versions
  • Test locally first using the VS Code extension before deploying to SAP CPI
  • Leverage the skill to ensure your AI-generated code follows best practices
  • Customize the agent and skill to match your organization's coding standards

Next Steps

This workflow significantly reduces development time and helps ensure code quality. The combination of the AI agent, the skill, and the local debugging extension creates a complete development pipeline for SAP CPI Groovy scripts.

A note on the agent and skill: these were built based on my own experience and specific needs, so they're not perfect — you will likely find errors, edge cases, or gaps as you use them. Feel free to adapt, fix, and improve them to fit your own workflow and organization's standards. Contributions and suggestions are always welcome.

If you have questions or suggestions for improving the agent and skill, feel free to reach out in the comments below.

 

#

 

 

 

Labels in this area