会话设置
现在,您已经有了一个用于计算屋顶长度的自定义工具,接下来可以让代理根据您输入的查询生成输出。通过对打印语句做些小改动,您可以直接对比查询与代理的回复,以核对结果是否准确。您的 tools 和 query 已设置完毕,model 也可以直接使用。
本练习是课程的一部分
使用 LangChain 设计 Agentic 系统
练习说明
- 初始化
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({
"____": ____,
"____": ____["____"][____].____
})