
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ăžæĄćŒ”ăăâç§éăăłășăȘăłâăăć±ăăăŸăă
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 ć ă§èȘăăïŒæăćăăăăäșćźăăŠăăŸăă
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!
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 ăȘă©ăźăăŒă«ăç»éČăăă ăă§ăćźèĄæă«ăąăă«ăăæèăăčăăïŒèĄćăăčăăăăèȘćŸçă«ć€æăăŸăă
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 è§ŁèȘŹăăŒăž
<script async src="https://cse.google.com/cse.js?cx=GOOGLE_CSE_ID">
</script>
<div class="gcse-search"></div>â
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 ăžèȘ蚌ă§ăăæșćăæŽăăŸăăïŒ
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? / ăăźăčăăăă§äœăăăŠăăăïŒ
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 ăŻćăăŒă«ăźèȘŹææăèȘăăăšă§ăăăă€ă»ă©ăźăăă«ăăŒă«ăäœżăăăă〿ăăŸăăăăăŻăăąăă«ă«ăšăŁăŠăźâćæ±èȘŹææžâăźăăăȘćœčćČăæăăăŸăă
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? / ăăźăčăăăă§äœăăăŠăăăïŒ
Expect to see a printed google_search call, followed by the championâs name and time!
google_search ćŒăłćșăăă°ăšăšăă«ăćȘćè ăšăżă€ă ăèĄšç€șăăăă° OK ă§ăïŒ
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("ăăżăăăćŒăăŠăă ăă") ăăæćźăăç”æăźăăăăăèżăă°ćæ Œă§ăïŒ
Have fun customizing! / èȘćă ăăźăăŒă«ăă©ăă©ăèżœć ăăŠéăă§ăżăŸăăăă
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 â 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 ăŻæŹăăă°ăźć
ćźčă«ă€ăăŠäžćăźèČŹä»»ăèČ ăăŸăăă
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
29 | |
18 | |
16 | |
16 | |
10 | |
8 | |
8 | |
7 | |
7 | |
6 |