🚀 SAP AI Core Agent QuickLaunch Series / 秒速で学ぶ SAP AI Core Agent 開発 – Part 2 Building a Chat Model

Estimated read time 9 min read

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.

生成 AI は研究室の外へ飛び出し、今やビジネス現場の常識を塗り替えています。SAPは全速力でその波に乗っており、JouleというAgentを公開しました。このブログシリーズでは、Agentが裏側でどうなっているかを理解するため、SAP AI Core の既定モデルを最速で呼び出し、実務で使える AI Agentへ拡張する“秒速ハンズオン”をお届けします。

 

📖What You’ll Learn in This Series / 本シリーズで学べること

How to spin up a custom AI agent on SAP AI Core in minutes
SAP AI Core 上でカスタム AI エージェントを “秒速” で動かす方法

Hands‑on with LangChain, Google Search Tool, RAG, and Streamlit
LangChain・Google 検索ツール・RAG・Streamlit を使った実装

Exposing the agent as a REST API and rebuilding the UI in SAPUI5/Fiori
エージェントを REST API 化し、UI を SAPUI5/Fiori に載せ替える手順

Time Commitment / 学習時間
Each part is designed to be completed in 10–15 minutes.
各章は 10–15 分 で読める&手を動かせるを予定しています。

 

🗺️ Series Roadmap / 連載ロードマップ

Part 0 Prologue / プロローグ [current blog / 現在のブログ]Part 1 Env Setup: SAP AICore & AI Launchpad / 環境構築: SAP AI CoreとAI LaunchpadPart 2 Building a Chat Model with LangChain / LangChain でチャットモデルを構築Part 3 Agent Tools: Integrating Google Search / Agentツール: Google 検索を統合Part 4 RAG Basics ①: File Upload & HANA Cloud VectorEngine / RAG 基礎 ①: ファイルアップロード & HANA Cloud ベクターエンジンPart 5 RAG Basics ②: Retriever Tool / RAG 基礎 ②: Retriever Toolの構築Part 6 Streamlit UI Prototype / Streamlit でチャットUIPart 7 Expose as a REST API / AI Agent を REST API 化Part 8 Rebuild the UI with SAPUI5 / SAPUI5 でチャットUI を再構築

Note / 注記
Subsequent blogs will be published soon.
続編は順次公開予定です。

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
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!

本章では Jupyter Notebook を立ち上げ、必要な SDK をインストールします。その後、Part 1で作成した GPT‑4o‑mini デプロイメントに対してチャットを投げてみます!

 

2 | Prerequisites / 事前準備

BTP sub-account / BTP サブアカウントSAP AI Core instance / SAP AI Core インスタンスSAP AI LaunchPad Subscription / SAP AI LaunchpadのサブスクリプションPython 3.13 and pip / Python 3.13環境 & pipVSCode, BAS or any IDE / VSCodeやBASなどのIDE

 

3 | Step 1 – 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.

VS Code を開き Jupyter Notebook(langchain_chat.ipynb)を新規作成します。新しいフォルダを作り、(推奨)Python の 仮想環境 を作成して依存関係の衝突を防ぎましょう。

3‑A  Create requirements.txt

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

requirements.txt は 必要なPython パッケージとそのバージョンを列挙したリスト です。

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

 

3‑B  Install the packages

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 | Step 2 – Say Hello to GPT‑4o‑mini / GPT‑4o‑mini に “こんにちは”

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

新しいセルで .env を読み込み、プロンプトを送信しましょう。

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.

ドキュメントを読もう!

コードを書く前に必ず Generative AI Hub SDK の公式ドキュメント をざっと眺めてください → [リンク]。SDK が OpenAI・Vertex AI・Bedrock などをラップし、LangChain 互換 の API を提供していることが分かります。バージョン対応表をブックマークしておくと後で泣かずに済みます。

# ▶ 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”) # ← Part 1 で控えた ID
)

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.
「system」メッセージはモデルの役割・振る舞いを決めます。「human」メッセージはユーザー入力です。チャット UI から受け取った文字列をここに渡せば、そのまま対話が成立します。
Success = “Bonjour, le monde !”
 “Bonjour, le monde !” が返ってきたら成功です!
 

5 | Challenge – Embed Text like a Pro! / チャレンジ – Embedding モデルを動かそう!

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.

今度は AI Launchpad で OpenAI の text-embedding-ada-002(他の埋め込みモデルでも可)をデプロイし、LangChain から呼び出して ベクトルが返る ことを確認します。GPT‑4o‑mini と同じ手順なので復習だと思ってやってみてください。

手順は以下の通りです。

Deploy the embedding model in AI Launchpad. / AI Launchpad で Embedding モデルをデプロイ。

Copy the new Deployment ID. / 新しい Deployment ID を控えます。

Notebook Cell (some fields masked) / ノートブックセル(IDや関数は一部マスク)

# ▶ 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!

“[-0.012, 0.087, …]” のように 数字の羅列 が出てきたら成功です!

 

6 | Next Up / 次回予告

Part 3 Agent Tools: Integrating Google Search / Agentツール: Google 検索を統合

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.

Part 3 ではチャットモデルを LangChain エージェント に仕立て、Google 検索ツール を接続して最新情報も回答できるようにします。追加 API キーは不要。すべて SAP AI Core 内で完結しますのでお楽しみに!

 

Disclaimer / 免責事項

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.
免責事項 – 本ブログに記載された見解および意見はすべて私個人のものであり、私の個人的な立場で発信しています。SAP は本ブログの内容について一切の責任を負いません。

 

​ 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.生成 AI は研究室の外へ飛び出し、今やビジネス現場の常識を塗り替えています。SAPは全速力でその波に乗っており、JouleというAgentを公開しました。このブログシリーズでは、Agentが裏側でどうなっているかを理解するため、SAP AI Core の既定モデルを最速で呼び出し、実務で使える AI Agentへ拡張する“秒速ハンズオン”をお届けします。 📖What You’ll Learn in This Series / 本シリーズで学べることHow to spin up a custom AI agent on SAP AI Core in minutesSAP AI Core 上でカスタム AI エージェントを “秒速” で動かす方法Hands‑on with LangChain, Google Search Tool, RAG, and StreamlitLangChain・Google 検索ツール・RAG・Streamlit を使った実装Exposing the agent as a REST API and rebuilding the UI in SAPUI5/Fioriエージェントを REST API 化し、UI を SAPUI5/Fiori に載せ替える手順Time Commitment / 学習時間Each part is designed to be completed in 10–15 minutes.各章は 10–15 分 で読める&手を動かせるを予定しています。 🗺️ Series Roadmap / 連載ロードマップPart 0 Prologue / プロローグ [current blog / 現在のブログ]Part 1 Env Setup: SAP AICore & AI Launchpad / 環境構築: SAP AI CoreとAI LaunchpadPart 2 Building a Chat Model with LangChain / LangChain でチャットモデルを構築Part 3 Agent Tools: Integrating Google Search / Agentツール: Google 検索を統合Part 4 RAG Basics ①: File Upload & HANA Cloud VectorEngine / RAG 基礎 ①: ファイルアップロード & HANA Cloud ベクターエンジンPart 5 RAG Basics ②: Retriever Tool / RAG 基礎 ②: Retriever Toolの構築Part 6 Streamlit UI Prototype / Streamlit でチャットUIPart 7 Expose as a REST API / AI Agent を REST API 化Part 8 Rebuild the UI with SAPUI5 / SAPUI5 でチャットUI を再構築Note / 注記Subsequent blogs will be published soon.続編は順次公開予定です。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 LangChainLangChain でチャットモデルを構築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!本章では Jupyter Notebook を立ち上げ、必要な SDK をインストールします。その後、Part 1で作成した GPT‑4o‑mini デプロイメントに対してチャットを投げてみます! 2 | Prerequisites / 事前準備BTP sub-account / BTP サブアカウントSAP AI Core instance / SAP AI Core インスタンスSAP AI LaunchPad Subscription / SAP AI LaunchpadのサブスクリプションPython 3.13 and pip / Python 3.13環境 & pipVSCode, BAS or any IDE / VSCodeやBASなどのIDE 3 | Step 1 – 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.VS Code を開き Jupyter Notebook(langchain_chat.ipynb)を新規作成します。新しいフォルダを作り、(推奨)Python の 仮想環境 を作成して依存関係の衝突を防ぎましょう。3‑A  Create requirements.txtA requirements.txt file is simply a checklist of Python packages (and versions) your notebook needs. requirements.txt は 必要なPython パッケージとそのバージョンを列挙したリスト です。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 3‑B  Install the packagesOpen a terminal inside your project folder after activating your virtual environment (e.g. .venv). Then execute the command:プロジェクトフォルダ内で 仮想環境を有効化してから ターミナルを開き、次のコマンドを実行します。pip install -r requirements.txtOnce the install finishes, restart your Notebook kernel so it picks up the new libraries.インストールが完了したら、ノートブックのカーネルを再起動してライブラリを読み込み直しましょう。 4 | Step 2 – Say Hello to GPT‑4o‑mini / GPT‑4o‑mini に “こんにちは”In a new notebook cell, load your .env and send a prompt.新しいセルで .env を読み込み、プロンプトを送信しましょう。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.ドキュメントを読もう!コードを書く前に必ず Generative AI Hub SDK の公式ドキュメント をざっと眺めてください → [リンク]。SDK が OpenAI・Vertex AI・Bedrock などをラップし、LangChain 互換 の API を提供していることが分かります。バージョン対応表をブックマークしておくと後で泣かずに済みます。# ▶ 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”) # ← Part 1 で控えた ID
)

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.「system」メッセージはモデルの役割・振る舞いを決めます。「human」メッセージはユーザー入力です。チャット UI から受け取った文字列をここに渡せば、そのまま対話が成立します。Success = “Bonjour, le monde !” “Bonjour, le monde !” が返ってきたら成功です! 5 | Challenge – Embed Text like a Pro! / チャレンジ – Embedding モデルを動かそう!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.今度は AI Launchpad で OpenAI の text-embedding-ada-002(他の埋め込みモデルでも可)をデプロイし、LangChain から呼び出して ベクトルが返る ことを確認します。GPT‑4o‑mini と同じ手順なので復習だと思ってやってみてください。手順は以下の通りです。Deploy the embedding model in AI Launchpad. / AI Launchpad で Embedding モデルをデプロイ。Copy the new Deployment ID. / 新しい Deployment ID を控えます。Notebook Cell (some fields masked) / ノートブックセル(IDや関数は一部マスク)# ▶ 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 charsYou’re good if you see “[-0.012, 0.087, …]” – a string of numbers!“[-0.012, 0.087, …]” のように 数字の羅列 が出てきたら成功です! 6 | Next Up / 次回予告Part 3 Agent Tools: Integrating Google Search / Agentツール: Google 検索を統合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.Part 3 ではチャットモデルを LangChain エージェント に仕立て、Google 検索ツール を接続して最新情報も回答できるようにします。追加 API キーは不要。すべて SAP AI Core 内で完結しますのでお楽しみに! Disclaimer / 免責事項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.免責事項 – 本ブログに記載された見解および意見はすべて私個人のものであり、私の個人的な立場で発信しています。SAP は本ブログの内容について一切の責任を負いません。   Read More Technology Blogs by SAP articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author