开始使用免费开始使用

会话设置

现在,您已经有了一个用于计算屋顶长度的自定义工具,接下来可以让代理根据您输入的查询生成输出。通过对打印语句做些小改动,您可以直接对比查询与代理的回复,以核对结果是否准确。您的 toolsquery 已设置完毕,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({
    "____": ____,
    "____": ____["____"][____].____
})
编辑并运行代码