开始使用免费开始使用

连接工具,解锁 Agentic RAG

您现在已经有一个可用的自定义工具,可以利用语义相似度搜索家电手册。在本练习中,您将把该工具连接到一个代理上,让代理基于手册内容回答问题。

在后台,您已经可以使用以下内容:

  • 名为 vector_store 的变量,保存了可搜索的手册内容
  • 用于执行语义搜索的 ApplianceSearchTool
  • 名为 model 的变量,其中包含为代理预配置的语言模型

您的目标是把这些组件串联起来,让代理能够使用您的工具,像一位有帮助的家电助手一样回答问题。

本练习是课程的一部分

使用 Hugging Face smolagents 的 AI Agents

查看课程

练习说明

  • 传入 vector_store 来实例化 ApplianceSearchTool
  • 在初始化 CodeAgent 时,将您的 appliance_tool 添加到 tools 列表中。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Create appliance search tool
appliance_tool = ApplianceSearchTool(____)

# Create AI assistant for appliance help
assistant = CodeAgent(
    tools=[____],
    model=model,
    instructions="Help with appliance questions using manual information. Search multiple times if needed for complete answers.",
    verbosity_level=1,
    max_steps=6
)

result = assistant.run("If the AC isn’t cooling and shows error E1, what should I check and what’s the next step?")
print(result)
编辑并运行代码