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
The Japanese version is available here.
Ā
šWhat Youāll Learn in This Series
How to spin up a custom AIāÆagent on SAPāÆAIĀ Core in minutesHandsāon with LangChain, Google Search Tool, RAG, and StreamlitExposing the agent as a RESTĀ API and rebuilding the UI in SAPUI5/Fiori
Time Commitment
Each part is designed to be completed inĀ 10ā15Ā minutes
Ā
šŗļø Series Roadmap
Part 0 ProloguePart 1 Env Setup: SAP AICore & AI LaunchpadPart 2 Building a Chat Model withĀ LangChainPart 3 AgentĀ Tools: Integrating GoogleĀ SearchĀ [current blog]Part 4 RAG Basics ā : HANA Cloud VectorEngine & EmbeddingPart 5 RAG Basics ā”: Building Retriever ToolPart 6 Streamlit BasicsPart 7Ā Streamlit UI PrototypePart 8 Expose as a RESTĀ APIPart 9 Rebuild theĀ UI withĀ SAPUI5 1st HalfĀ Part 10 Rebuild theĀ UI withĀ SAPUI5 2ndĀ Half
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
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.
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.
Ā
2 | Prerequisites
BTP sub-accountSAP AI Core instanceSAP AI LaunchPad SubscriptionPython 3.13 and pipVSCode, BAS or any IDE
Ā
3Ā | Get aĀ GoogleĀ APIĀ Key
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.
Open the Google Cloud Console.
Select or create a project, and click āCreateĀ credentialsĀ āĀ APIĀ keyā. A dialog shows your new key.
Tip: rename the key to something memorable.
Go to the ProgrammableĀ SearchĀ Engine create page, and enter any name, set Search the entire web, and click āCreate.ā
A screen with an HTML snippet appears.
<script async src=”https://cse.google.com/cse.js?cx=GOOGLE_CSE_ID”>
</script>
<div class=”gcse-search”></div>ā
Add both values to your projectāroot .env file and keep them out of source code.
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!
Ā
4Ā | Add the GoogleĀ SearchĀ Tool to LangChain
We wrap Googleās JSONĀ API inside a LangChainĀ Tool so the agent can call google_search the same way it calls the LLM.
Open the notebook from Part 2, and add the following cell.
# ā¶ 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.Tool.from_function: converts any Python function into a LangChainĀ Tool by attaching a humanāreadable name and description.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.
Ā
5Ā | Build a LangChainĀ Agent
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.
# ā¶ 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.tools=[google_tool]:Ā hands the agent a toolboxāright now it contains only GoogleĀ Search, but you can append more later.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.
Expect to see a printed google_search call, followed by the championās name and time!
Ā
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.
# ā¶ 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(“pick a fortune for me”)
Ā
If agent.invoke(“pick a fortune for me”) returns one of the predefined results, it’s a pass!
Have fun customizing!
Ā
7 | NextĀ Up
Part 4 RAG Basics ā : HANA Cloud VectorEngine & Embedding
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.
Ā
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.
Ā
āĀ 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.NoticeThe Japanese version is available here.Ā šWhat Youāll Learn in This SeriesHow to spin up a custom AIāÆagent on SAPāÆAIĀ Core in minutesHandsāon with LangChain, Google Search Tool, RAG, and StreamlitExposing the agent as a RESTĀ API and rebuilding the UI in SAPUI5/FioriTime CommitmentEach part is designed to be completed inĀ 10ā15Ā minutesĀ šŗļø Series RoadmapPart 0 ProloguePart 1 Env Setup: SAP AICore & AI LaunchpadPart 2 Building a Chat Model withĀ LangChainPart 3 AgentĀ Tools: Integrating GoogleĀ SearchĀ [current blog]Part 4 RAG Basics ā : HANA Cloud VectorEngine & EmbeddingPart 5 RAG Basics ā”: Building Retriever ToolPart 6 Streamlit BasicsPart 7Ā Streamlit UI PrototypePart 8 Expose as a RESTĀ APIPart 9 Rebuild theĀ UI withĀ SAPUI5 1st HalfĀ Part 10 Rebuild theĀ UI withĀ SAPUI5 2ndĀ HalfIf 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Ā Search1Ā |Ā OverviewAI 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.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.Ā 2 | PrerequisitesBTP sub-accountSAP AI Core instanceSAP AI LaunchPad SubscriptionPython 3.13 and pipVSCode, BAS or any IDEĀ 3Ā | Get aĀ GoogleĀ APIĀ KeyLangChain 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.Open the Google Cloud Console.Select or create a project, and click āCreateĀ credentialsĀ āĀ APIĀ keyā. A dialog shows your new key.Tip: rename the key to something memorable.Go to the ProgrammableĀ SearchĀ Engine create page, and enter any name, set Search the entire web, and click āCreate.āA screen with an HTML snippet appears.<script async src=”https://cse.google.com/cse.js?cx=GOOGLE_CSE_ID”>
</script>
<div class=”gcse-search”></div>āAdd both values to your projectāroot .env file and keep them out of source code.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!Ā 4Ā | Add the GoogleĀ SearchĀ Tool to LangChainWe wrap Googleās JSONĀ API inside a LangChainĀ Tool so the agent can call google_search the same way it calls the LLM.Open the notebook from Part 2, and add the following cell.# ā¶ 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.Tool.from_function: converts any Python function into a LangChainĀ Tool by attaching a humanāreadable name and description.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.Ā 5Ā | Build a LangChainĀ AgentWe 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.# ā¶ 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.tools=[google_tool]:Ā hands the agent a toolboxāright now it contains only GoogleĀ Search, but you can append more later.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.Expect to see a printed google_search call, followed by the championās name and time!Ā 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.# ā¶ 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(“pick a fortune for me”)Ā If agent.invoke(“pick a fortune for me”) returns one of the predefined results, it’s a pass!Have fun customizing!Ā 7 | NextĀ UpPart 4 RAG Basics ā : HANA Cloud VectorEngine & EmbeddingIn 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.Ā DisclaimerAll 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.Ā Ā Ā Read MoreĀ Technology Blog Posts by SAP articlesĀ
#SAP
#SAPTechnologyblog