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
656

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 / é€ŁèŒ‰ăƒ­ăƒŒăƒ‰ăƒžăƒƒăƒ—

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!


Agent Tools: Integrating Google Search
Agentăƒ„ăƒŒăƒ«: Google æ€œçŽąă‚’ç”±ćˆ

1 | Overview / 抂芁

AI Agent is more than just chat models. Following the ReAct (Reason + Act) paradigm proposed by Yao et al. in 2022, LLMs are now able to both generate reasoning processes and perform concrete actions, such as calling external tools. For example, by executing actions like Google Search or database queries and then passing those results back to the LLM, the next step of reasoning is always backed by up-to-date information.
This approach helps to suppress hallucinations and enables the development of AI Agent that generate much more accurate responses.

AI Agent は、捘ăȘă‚‹ăƒăƒŁăƒƒăƒˆăƒąăƒ‡ăƒ«ă§ăŻă‚ă‚ŠăŸă›ă‚“ă€‚2022ćčŽă« Yao ă‚‰ăŒæć”±ă—ăŸ ReActReason + ActïŒ‰ăƒ‘ăƒ©ăƒ€ă‚€ăƒ ă«ćŸ“ă„ă€LLMăŒæŽšè«–éŽçš‹ă‚’ç”Ÿæˆă—ă€ă•ă‚‰ă«ć…·äœ“çš„ăȘèĄŒć‹•ïŒˆăƒ„ăƒŒăƒ«ć‘Œăłć‡șă—ïŒ‰ă‚‚ćźŸèĄŒă§ăă‚‹ă‚ˆă†ă«ăȘă‚ŠăŸă—ăŸă€‚äŸ‹ăˆă°ă€Google æ€œçŽąă‚„ăƒ‡ăƒŒă‚żăƒ™ăƒŒă‚č揂照ăȘă©ăźèĄŒć‹•ă‚’ćźŸèĄŒă—ă€ăăźç”æžœă‚’ć†ăł LLM ă«æžĄă™ă“ăšă§ă€æŹĄăźæ€è€ƒăŒćžžă«æœ€æ–°æƒ…ć ±ă«ćŸșă„ăă‚‚ăźă«ăȘă‚ŠăŸă™ă€‚ă“ăźä»•ç”„ăżă«ă‚ˆăŁăŠă€ăƒăƒ«ă‚·ăƒăƒŒă‚·ăƒ§ăƒłă‚’æŠ‘ăˆă€ă‚ˆă‚ŠçČŸćșŠăźé«˜ă„ç”ŸæˆăŒæœŸćŸ…ă§ăă‚‹ AI Agent ăŒćźŸçŸă—ăŸă—ăŸă€‚

LangChain the “ReAct agent” pattern is already built‑in. We just register tools (like google_search) and LangChain decides, at runtime, whether the model should think or act.

LangChain には “ReAct Agent” ăƒ‘ă‚żăƒŒăƒłăŒæš™æș–æ­èŒ‰ă•ă‚ŒăŠă„ăŸă™ă€‚google_search ăȘă©ăźăƒ„ăƒŒăƒ«ă‚’ç™»éŒČă™ă‚‹ă ă‘ă§ă€ćźŸèĄŒæ™‚ă«ăƒąăƒ‡ăƒ«ăŒă€Œæ€è€ƒă™ăčăă‹ïŒèĄŒć‹•ă™ăčきか」をè‡ȘćŸ‹çš„ă«ćˆ€æ–­ă—ăŸă™ă€‚

 

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環汃 & pip
  • VSCode, BAS or any IDE / VSCodeやBASăȘどたIDE

 

3 | Step 1 â€“ Get a Google API Key / Google API ă‚­ăƒŒă‚’ć–ćŸ—ă™ă‚‹

LangChain needs your Google API key and Custom Search Engine (CSE) ID so the agent can legally query Google. Think of it as giving your assistant a badge to enter the web.

Official docs : LangChain already provides a ready‑made Google Search Tool page.

ć…ŹćŒăƒ‰ă‚­ăƒ„ăƒĄăƒłăƒˆ : LangChain た Google Search Tool è§ŁèȘŹăƒšăƒŒă‚ž

  1. Open the Google Cloud Console. / Google Cloud ă‚łăƒłă‚œăƒŒăƒ«ă‚’é–‹ăăŸă™ă€‚Google Cloud Consoleç”»éą.png
  2. Select or create a project, and click “Create credentials â†’ API key”. A dialog shows your new key.
    ăƒ—ăƒ­ă‚žă‚§ă‚Żăƒˆă‚’éžæŠžăŸăŸăŻæ–°èŠäœœæˆă—ăŠ 「èȘèšŒæƒ…ć ±ă‚’äœœæˆ â†’ API ă‚­ăƒŒă€ をクăƒȘăƒƒă‚Żă—ăŸă™ă€‚ăƒ€ă‚€ă‚ąăƒ­ă‚°ă«æ–°ă—ă„ă‚­ăƒŒăŒèĄšç€șă•ă‚ŒăŸă™ă€‚
    APIă‚­ăƒŒäœœæˆç”»éą.png
    Tip: rename the key to something memorable. / ćŸŒă§è­˜ćˆ„ă—ă‚„ă™ă„ă‚ˆă†ă«ă‚­ăƒŒćă‚’ć€‰æ›Žă—ăŠăŠăăšäŸżćˆ©ă§ă™ă€‚
  3.  Go to the Programmable Search Engine create page. / Programmable Search Engine ăźäœœæˆç”»éąăžç§»ć‹•ă—ăŸă™ă€‚
  4. Enter any name, set Search the entire web, and click “Create.”
    ä»»æ„ăźæ€œçŽąă‚šăƒłă‚žăƒłćă‚’ć…„ćŠ›ă—ă€æ€œçŽąćŻŸè±Ąă‚’ă€Œă‚Šă‚§ăƒ–ć…šäœ“ă€ă«èš­ćźšă—ăŠ ă€Œäœœæˆă€ をクăƒȘăƒƒă‚Żă—ăŸă™ă€‚ă‚čクăƒȘăƒŒăƒłă‚·ăƒ§ăƒƒăƒˆ 2025-04-22 15.25.22.png
  5.  A screen with an HTML snippet appears.
    ă™ă‚‹ăšäž‹èš˜ăźă‚ˆă†ăȘ HTML ă‚čăƒ‹ăƒšăƒƒăƒˆăšçźĄç†ç”»éąăŒèĄšç€șă•ă‚ŒăŸă™ă€‚
<script async src="https://cse.google.com/cse.js?cx=GOOGLE_CSE_ID">
</script>
<div class="gcse-search"></div>​

æ–°ă—ă„æ€œçŽąă‚šăƒłă‚·ă‚™ăƒłäœœæˆćźŒäș†ç”»éą.png

  • Add both values to your project‑root .env file and keep them out of source code.
    2 ă€ăźć€€ă‚’ăƒ—ăƒ­ă‚žă‚§ă‚Żăƒˆç›Žäž‹ăź .env ă«èżœèš˜ă—ă€ă‚œăƒŒă‚čă‚łăƒŒăƒ‰ăžăƒ™ă‚żæ›žăă—ăȘă„ă‚ˆă†ă«ă—ăŸă—ă‚‡ă†ă€‚
GOOGLE_CSE_ID = "your GOOGLE_CSE_ID"
GOOGLE_API_KEY = "your GOOGLE_API_KEY"​


Your notebook can now authenticate to Google when the agent calls google_search!

Agentが google_search ăƒ„ăƒŒăƒ«ă‚’ć‘Œăłć‡șす際に Google ぞèȘèšŒă§ăă‚‹æș–ć‚™ăŒæ•Žă„ăŸă—ăŸïŒ

 

4 | Step 2 â€“ Add the Google Search Tool to LangChain / Googleæ€œçŽąăƒ„ăƒŒăƒ«ă‚’ćźŸèŁ…ă™ă‚‹

We wrap Google’s JSON API inside a LangChain Tool so the agent can call google_search the same way it calls the LLM.

Google た JSON API を LangChain Tool ă«ăƒ©ăƒƒăƒ—ă—ă€ă‚šăƒŒă‚žă‚§ăƒłăƒˆăŒ LLM ăšćŒă˜æ„ŸèŠšă§ google_search ă‚’ć‘Œăčă‚‹ă‚ˆă†ă«ă—ăŸă™ă€‚

Open the notebook from Part 2, and add the following cell.

Part 2 ăźăƒŽăƒŒăƒˆăƒ–ăƒƒă‚Żă‚’é–‹ăăŸă™ă€‚ăă—ăŠă€æŹĄăźă‚»ăƒ«ă‚’èżœćŠ ă—ăŸă™ă€‚

# ▶ Notebook Cell 3
from langchain.tools import Tool
from langchain_community.utilities import GoogleSearchAPIWrapper

search = GoogleSearchAPIWrapper(k=5) # return top‑5 results

google_tool = Tool.from_function(
    name="google_search",
    description="Search Google and return the first results",
    func=search.run
)

What exactly happens in this step? / ă“たă‚čăƒ†ăƒƒăƒ—ă§äœ•ă‚’ă—ăŠă„ă‚‹ă‹ïŒŸ

  • GoogleSearchAPIWrapper: A class that returns a search result string based on the query entered by the agent.
    GoogleSearchAPIWrapper: Agent ăŒć…„ćŠ›ă—ăŸæ€œçŽąă‚Żă‚šăƒȘă«ćżœă˜ăŠă€æ€œçŽąç”æžœăźæ–‡ć­—ćˆ—ă‚’èż”ă™ă‚Żăƒ©ă‚čです。
  • Tool.from_function: converts any Python function into a LangChain Tool by attaching a human‑readable name and description.
    Tool.from_function: ä»»æ„ăź Python é–ąæ•°ă« name ず description ă‚’ä»˜ă‘ăŠ LangChain Tool ćŒ–ă—ăŸă™ă€‚

  • description: Agents refer to the description of each tool to determine when and how to use it.
    Think of it as an “instruction manual” for the model.
    description: Agent ăŻć„ăƒ„ăƒŒăƒ«ăźèȘŹæ˜Žæ–‡ă‚’èȘ­ă‚€ă“ăšă§ă€ă€Œă„ă€ăƒ»ă©ăźă‚ˆă†ă«ăƒ„ăƒŒăƒ«ă‚’äœżă†ă‹ă€ă‚’ćˆ€æ–­ă—ăŸă™ă€‚ă“ă‚ŒăŻă€ăƒąăƒ‡ăƒ«ă«ăšăŁăŠăźâ€œć–æ‰±èȘŹæ˜Žæ›žâ€ăźă‚ˆă†ăȘćœčć‰Čă‚’æžœăŸă—ăŸă™ă€‚

 

5 | Step 3 â€“ Build a LangChain Agent / LangChain ă‚šăƒŒă‚žă‚§ăƒłăƒˆă‚’æ§‹ç݉

We combine the chat model from Part 2 with the Google tool to form an Agent that can decide on‑the‑fly whether it needs external information.

Part 2 ă§äœœăŁăŸ ăƒăƒŁăƒƒăƒˆăƒąăƒ‡ăƒ« ず Google ăƒ„ăƒŒăƒ« ă‚’ćˆäœ“ă•ă›ă€ćż…èŠă«ćżœă˜ăŠć€–éƒšæƒ…ć ±ă‚’ć–ă‚Šă«èĄŒă Agent ă‚’äœœæˆă—ăŸă™ă€‚

# ▶ Notebook Cell 4
from langchain.agents import initialize_agent, AgentType

agent = initialize_agent(
    tools=[google_tool],
    llm=chat_llm,
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True,
)

agent.invoke("Who won the Tokyo Marathon in 2025, and what was the finishing time?")

What exactly happens in this step? / ă“たă‚čăƒ†ăƒƒăƒ—ă§äœ•ă‚’ă—ăŠă„ă‚‹ă‹ïŒŸ

  • initialize_agent: wires your LLM, tools, and optional memory into a single Agent object.
    initialize_agent: LLMăƒ»ăƒ„ăƒŒăƒ«çŸ€ăƒ»ăƒĄăƒąăƒȘă‚’ăŸăšă‚ăŠ 1 ă€ăź Agent ă«ç”„ăżäžŠă’ăŸă™ă€‚
  • tools=[google_tool]: hands the agent a toolbox—right now it contains only Google Search, but you can append more later.
    tools=[google_tool]: Agentă«ăƒ„ăƒŒăƒ«ăƒœăƒƒă‚Żă‚čă‚’æžĄă—ăŸă™ă€‚çŸæ™‚ç‚čでは Google Search ă ă‘ă§ă™ăŒă€ćŸŒă§èżœćŠ ćŻèƒœă§ă™ă€‚
  • agent=AgentType.OPENAI_FUNCTIONS: Since we’re using OpenAI’s LLM in this case, we’ll choose the function calling specification that is compatible with OpenAI models.
    今曞は OpenAI た LLM ă‚’äœżç”šă™ă‚‹ăŸă‚ă€OpenAI ăƒąăƒ‡ăƒ«ă«ćŻŸćżœă—ăŸăƒ„ăƒŒăƒ«ć‘Œăłć‡șă—ïŒˆFunction CallingïŒ‰ăźä»•æ§˜ă‚’éžæŠžă—ăŸă™ă€‚

Expect to see a printed google_search call, followed by the champion’s name and time!

google_search ć‘Œăłć‡șă—ăƒ­ă‚°ăšăšă‚‚ă«ă€ć„Șć‹è€…ăšă‚żă‚€ăƒ ăŒèĄšç€șされれば OK ă§ă™ïŒ

Ryota_Ito_0-1745313803663.png

 

6 | Challenge – Add the original Tool! / チャレンゾ – ă‚ȘăƒȘă‚žăƒŠăƒ«ăƒ„ăƒŒăƒ«ă‚’èżœćŠ ă—ă‚ˆă†

Let’s create an agent that draws omikuji (a Japanese fortune) while following LangChain’s “How to create tools” guide.

LangChain ăźă€Œăƒ„ăƒŒăƒ«ăźäœœă‚Šæ–čHow to create toolsïŒ‰ă€ă‚’ć‚è€ƒă«ă—ăȘăŒă‚‰ă€ăŠăżăă˜ă‚’ćŒ•ă Agent ă‚’äœœăŁăŠăżăŸă—ă‚‡ă†ă€‚

# ▶ Notebook Cell 5
import random

def omikuji(_: str) -> str:
    return random.choice([
        "XXXXXX"
    ])

omikuji_tool = Tool.from_function(
    name="xxxxxx",
    description="......",
    # ?????
)

omikuji_agent = initialize_agent(
    tools=XXXXXXXX,
    llm=chat_llm,
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True,
)

omikuji_agent.invoke("ăŠăżăă˜ă‚’ćŒ•ă„ăŠăă ă•ă„")

If agent.invoke("ăŠăżăă˜ă‚’ćŒ•ă„ăŠăă ă•ă„") returns one of the predefined results, it's a pass!

agent.invoke("ăŠăżăă˜ă‚’ćŒ•ă„ăŠăă ă•ă„") ăŒă€æŒ‡ćźšă—ăŸç”æžœăźă„ăšă‚Œă‹ă‚’èż”ă›ă°ćˆæ Œă§ă™ïŒ

Ryota_Ito_1-1745314553623.png

Have fun customizing! / è‡Șćˆ†ă ă‘ăźăƒ„ăƒŒăƒ«ă‚’ă©ă‚“ă©ă‚“èżœćŠ ă—ăŠéŠă‚“ă§ăżăŸă—ă‚‡ă†ă€‚

 
 

7 | Next Up / æŹĄć›žäșˆć‘Š

Part 4 RAG Basics ①: File Upload & HANA Cloud VectorEngine / RAG ćŸș瀎 ①: ăƒ•ă‚Ąă‚€ăƒ«ă‚ąăƒƒăƒ—ăƒ­ăƒŒăƒ‰ & HANA Cloud ăƒ™ă‚Żă‚żăƒŒă‚šăƒłă‚žăƒł

In Part 4 we upload PDFs, vectorise them in HANA Cloud Vector Engine, and let the agent answer with your own documents — the first step toward full‑blown RAG.

Part 4 では PDF ă‚’ă‚ąăƒƒăƒ—ăƒ­ăƒŒăƒ‰ă— HANA Cloud Vector Engine ă«ăƒ™ă‚Żăƒˆăƒ«ćŒ–ă€‚ă‚šăƒŒă‚žă‚§ăƒłăƒˆăŒè‡Șç€Ÿæ–‡æ›žă‚’ćŒ•ç”šă—ăŠć›žç­”ă™ă‚‹ RAG ăźçŹŹäž€æ­©ă«é€ČăżăŸă™ă€‚

 

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 ăŻæœŹăƒ–ăƒ­ă‚°ăźć†…ćźčă«ă€ă„ăŠäž€ćˆ‡ăźèȏ任をèČ ă„ăŸă›ă‚“ă€‚

Labels in this area