整合自訂工具與查詢
你現在有一個用來計算屋頂長度的自訂數學工具。你可以將它與 agentic 工作流程整合:建立名為 query 的變數,用來接收使用者以自然語言提出的問題(字串)。你的工具已載入為 hypotenuse_length,model 也已經就緒。
本練習屬於課程
Designing Agentic Systems with LangChain
練習說明
- 建立名為
tools的清單變數,並在清單中包含你的工具hypotenuse_length。 - 建立名為
query的變數,接收以自然語言撰寫的問題字串。 - 使用
create_react_agent()函式建立代理(agent),並傳入model與tools。 - 叫用代理
app,將以"human"標記的query傳入,在儲存並列印代理的response之前完成呼叫。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a list variable and pass in your tool
____ = [____]
# Create a query using natural language
____ = "What is the hypotenuse length of a triangle with side lengths of 10 and 12?"
# Pass in the hypotenuse length tool and create the agent
app = ____(____, ____)
# Invoke the agent and print the response
response = ____.____({"messages": [("____", ____)]})
print(____['messages'][-1].content)