开始使用免费开始使用

Let Agents Search the Web

Your friend wants to send $500 to her sister in New York but isn't sure if the exchange rate is still favorable. She remembers seeing “1 GBP → 1.24 USD” last week, but exchange rates can change daily.

To help her make a smart decision, you decide to build a code agent that can:

  • Look up live GBP -> USD rate
  • Summarize how the rate has changed over the past 7 days

You'll give your agent web search powers using the built-in VisitWebpageTool.

Note: The model has been initialized for you. The CodeAgent class has been imported as well.

本练习是课程的一部分

AI Agents with Hugging Face smolagents

查看课程

练习说明

  • Import the VisitWebpageTool from the smolagents library.
  • Create the agent using the provided model and a tools list that includes an instance of VisitWebpageTool().
  • Run the agent using the .run() method and pass in the task.

交互式实操练习

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

# Import the VisitWebpageTool class
from smolagents import ____

# Create agent with web search capabilities
agent = CodeAgent(
    tools=[____],
    model=model
)

task = "Find GBP to USD exchange rates and summarize how this rate has changed over the past 7 days. A good source is usually Wise."

# Run the agent with the task
result = agent.run(____)
编辑并运行代码