對話設定
現在你已經有自訂工具來協助計算屋頂長度,可以讓代理回應你輸入的查詢。只要稍微調整列印語句,你就能直接比較你的查詢與代理的回應,以確保結果正確。你的 tools 與 query 都已設定完成,model 也已可用。
本練習屬於課程
Designing Agentic Systems with LangChain
練習說明
- 初始化
create_react_agent函式並建立名為app的物件,傳入必要參數。 - 呼叫代理
app,傳入你的query,再將代理的response儲存並列印出來。 - 將
"user_input"定義為query,將"agent_output"定義為從response的"messages"中擷取的最後一個項目,然後一併列印。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
tools = [hypotenuse_length]
query = "What is the value of the hypotenuse for a triangle with sides 3 and 5?"
# Create the ReAct agent
app = ____(____, ____)
# Invoke the agent with a query and store the messages
response = ____.____({"messages": [("human", ____)]})
# Define and print the input and output messages
print({
"____": ____,
"____": ____["____"][____].____
})