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
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 --exactmacOS / Linux (from terminal):
curl -fsSL https://opencode.ai/install | bashAfter 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
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:
opencodeThen execute the installation prompt:
Run prompt https://github.com/nahhoj/SAP-CPI-AGENTS/blob/master/prompts/install.md
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.
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:
/agentLook for sap-cpi-groovy in the list.
Check the skill:
/skillLook for sap-cpi-groovy-best-practice in the list.
Opening OpenCode in VS Code
- Open VS Code and navigate to your workspace folder
- Open the integrated terminal within VS Code
- Type
opencodeto launch the agent
You can now see your workspace path and start working with the SAP CPI agent.
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.
By default, the agent uses the DeepSeek V4 Flash Free model. You can change this by typing:
/modelThen select a different model from the available options.
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.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.
After approval
Result: The AI agent generates a complete project structure with a script that outputs version information.
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
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 extensionAfter configuration, run your script again and check the specified folder for attachment output.
Testing in SAP Integration Suite
Once you're satisfied with your local testing:
- Deploy the iFlow to your SAP Cloud Integration tenant
- Verify execution using the SAP CPI Tools Chrome extension
- Check attachments to confirm expected output
The SAP CPI Tools Extension provides an easy interface to monitor script execution and validate results.
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.
#
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.