Technology Blog Posts by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Ryota_Ito
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,238

Generative AI has broken out of research labs and is now transforming the way business is done. SAP is moving at full speed to embrace this trend and has launched an agent called Joule. In this blog series, I’ll provide a “super-fast hands-on” guide to help you quickly call default models of SAP AI Core and expand them into practical AI agents for real-world business use, so you can understand how these agents work behind the scenes.

Notice
日本語版はこちらです。

 

📖What You’ll Learn in This Series

  • How to Run a Custom AI Agent on SAP AI Core in Seconds
  • Implementation Using LangChain, Google Search Tool, and RAG
  • Steps to Convert the AI Agent into a REST API, Integrate It into an SAPUI5/Fiori UI, and Deploy to Cloud Foundry

Time Commitment
Each part is designed to be completed in 10–15 minutes

 

🗺️ Series Roadmap

If you enjoyed this post, please give it a kudos! Your support really motivates me. Also, if there’s anything you’d like to know more about, feel free to leave a comment!


Building a Chat Model with LangChain

1 | Overview

We’ll move into a Jupyter Notebook, install the required SDKs, and send our first chat to the GPT‑4o‑mini deployment we created in Part 1!

 

2 | Prerequisites

  • BTP sub-account
  • SAP AI Core instance
  • SAP AI LaunchPad Subscription
  • Python 3.13 and pip
  • VSCode, BAS or any IDE

 

3 | Prepare Local Notebook Env

Open VS Code and create a new Jupyter Notebook (langchain_chat.ipynb). Create a fresh folder and (optionally) a Python virtual environment so dependencies don’t clash with other projects.

A requirements.txt file is simply a checklist of Python packages (and versions) your notebook needs. 

ai_core_sdk>=2.5.7
pydantic==2.9.2
openai>=1.56.0
google-cloud-aiplatform==1.61.0       # Google
boto3==1.35.76                         # Amazon
langchain~=0.3.0
langgraph==0.3.30
langchain-community~=0.3.0
langchain-openai>=0.2.14
langchain-google-vertexai==2.0.1
langchain-google-community==2.0.7
langchain-aws==0.2.9
python-dotenv==1.1.0
generative-ai-hub-sdk

 

Open a terminal inside your project folder after activating your virtual environment (e.g. .venv). Then execute the command:

pip install -r requirements.txt

Once the install finishes, restart your Notebook kernel so it picks up the new libraries.

 

4 | Say Hello to GPT‑4o‑mini

In a new notebook cell, load your .env and send a prompt.

Read the docs!
Before you type a single line of code, skim the Generative AI Hub SDK documentation . Notice how the SDK wraps OpenAI, Vertex AI, Bedrock, and exposes a LangChain‑compatible interface. Keep the version matrix handy—mis‑matched pins are the #1 support ticket.

Add the following cell. (Add the Deployment ID you created in Part 1 (Section 5, Step 6) to your .env file like this: DEPLOYMENT_ID="debXXXXXXXXXXXX".)
# ▶ Notebook Cell 1
from dotenv import load_dotenv
from gen_ai_hub.proxy.langchain.openai import ChatOpenAI
import os

load_dotenv()                       # Read credentials & DEPLOYMENT_ID

chat_llm = ChatOpenAI(
    deployment_id=os.getenv("DEPLOYMENT_ID")  # ← Deployment ID created in Part 1 (Section 5, Step 6)
)

messages = [
    ("system", "You are a helpful assistant that translates English to French."),
    ("human",  "Hello, World!"),
]

chat_llm.invoke(messages)​

“system” message defines the model’s role and behaviour. The “human” message is the user’s input—replace it with whatever text comes from your chat UI.

Success = “Bonjour, le monde !”

Ryota_Ito_0-1747623150177.png
 

5 | Challenge – Embed Text like a Pro!

You’ll now deploy OpenAI’s text-embedding-ada-002  (or any embedding model) in AI Launchpad exactly the same way you deployed GPT‑4o‑mini. Then call it from LangChain and make sure you receive a vector.

The steps are as follows:

  1. Deploy the embedding model in AI Launchpad.
  2. Copy the new Deployment ID.

Notebook Cell (some fields masked)

# ▶ Notebook Cell 2
from gen_ai_hub.proxy.langchain.openai import AAAAAAAAAAAA

embedding_model = AAAAAAAAAAAA(
    deployment_id="debXXXXXXXXX"
)

single_vector = embedding_model.BBBBBBBBBBBB("Hello world")
print(str(single_vector)[:100])           # Print first 100 chars

You’re good if you see “[-0.012, 0.087, …]” – a string of numbers!

 

6 | Next Up

Part 3 Agent Tools: Integrating Google Search

Part 3 upgrades our chat model into a LangChain Agent and bolts on the Google Search tool so answers stay fresh. No extra API keys—everything still runs inside SAP AI Core.

 

Disclaimer

All the views and opinions in the blog are my own and is made in my personal capacity and that SAP shall not be responsible or liable for any of the contents published in this blog.