一個提示,多種工具
你已經為 AgentsCafé 建立了兩個工具:
generate_order_id:產生一個含時間戳記的 ID,如T5_Latte_20250812_0915lookup_orders:讀取orders.csv,並回傳該桌的飲品清單
現在來建立一個會使用這兩個工具的代理。對於任一桌號,代理都能抓取該桌的訂單,並為每杯飲品指定唯一的 ID。
注意:模型、工具與必要的匯入都已經替你定義好。一份範例 orders.csv 也已上傳。
本練習屬於課程
使用 Hugging Face smolagents 的 AI 代理
練習說明
- 使用先前定義的
lookup_orders與generate_order_id工具建立一個程式代理。 - 將
pandas加入已授權匯入清單,確保代理可以讀取 CSV。 - 使用代理的
.run()方法處理一個task:抓取某桌的訂單並為每杯飲品指派 ID。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a code agent with the lookup_orders and generate_order_id tools
agent = CodeAgent(
tools=[____, ____],
model=model,
# Authorize pandas import
additional_authorized_imports=['____']
)
task = (
"For table 5, list their current drink orders and generate a unique order ID for each one."
)
# Run the agent passing the task
result = ____
print(result)