集成自定义工具与查询
您已经有一个用于计算屋顶长度的自定义数学工具。要将其集成到代理式工作流中,请创建一个名为 query 的变量,用于接收用户的自然语言问题(字符串)。您的工具已作为 hypotenuse_length 加载,同时还有 model。
本练习是课程的一部分
使用 LangChain 设计 Agentic 系统
练习说明
- 创建一个名为
tools的列表变量,并将您的工具hypotenuse_length放入列表中。 - 创建一个名为
query的变量,用于接收以自然语言编写的问题字符串。 - 使用
create_react_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)