开始使用免费开始使用

Game Time: Run the Full Agent

Your basketball coaching agent is almost ready to hit the court. You've written a callback function to show the step number and token usage.

Now it's time to assemble everything: you'll configure a CodeAgent that uses that callback.

You already have access to:

  • A basketball_tool that enables the agent to search scouting reports
  • A model variable with your language model
  • A callback function: action_callback

Your goal is to finish wiring up the agent.

本练习是课程的一部分

AI Agents with Hugging Face smolagents

查看课程

练习说明

  • Import the ActionStep class so it can be used to register the action callback.
  • Register the action_callback function for the ActionStep class so the agent shows its actions while executing.

交互式实操练习

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

# 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)
编辑并运行代码