開始使用免費開始

對話設定

現在你已經有自訂工具來協助計算屋頂長度,可以讓代理回應你輸入的查詢。只要稍微調整列印語句,你就能直接比較你的查詢與代理的回應,以確保結果正確。你的 toolsquery 都已設定完成,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({
    "____": ____,
    "____": ____["____"][____].____
})
編輯並執行程式碼