上場時間:執行完整 Agent
你的籃球教練 agent 幾乎可以上場了。你已經寫好一個回呼函式,用來顯示步驟編號與權杖使用量。
現在要把一切組裝起來:你將設定一個使用該回呼的 CodeAgent。
你已經可以使用:
- 可讓 agent 搜尋球探報告的
basketball_tool - 你的語言模型變數
model - 回呼函式:
action_callback
你的目標是完成 agent 的串接設定。
本練習屬於課程
使用 Hugging Face smolagents 的 AI 代理
練習說明
- 匯入
ActionStep類別,才能註冊動作回呼。 - 為
ActionStep類別註冊action_callback函式,讓 agent 在執行時顯示其動作。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import ActionStep to register a callback for it
from smolagents import ____
coach_agent = CodeAgent(
tools=[basketball_tool],
model=model,
verbosity_level=0,
# Register a callback that runs when an ActionStep is triggered
step_callbacks={ActionStep: ____}
)
# Run a question through the agent
result = coach_agent.run("What defensive strategy should we use to stop their point guard who averages 25 points per game?")
print(result)