連上工具,解鎖 Agentic RAG
你現在已經有一個可用的自訂工具,能以語意相似度搜尋家電手冊。這個練習中,你會把該工具串接到代理,讓它能根據手冊內容回答問題。
幕後你已具備以下資源:
- 一個名為
vector_store的變數,內含可搜尋的手冊內容 - 一個
ApplianceSearchTool,用於執行語意搜尋 - 一個名為
model的變數,包含為代理預先設定好的語言模型
你的目標是把這些元件串接起來,讓代理可以使用你的工具,像貼心的家電助理一樣回答問題。
本練習屬於課程
使用 Hugging Face smolagents 的 AI 代理
練習說明
- 以傳入
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)