Tool Use

Give a HuggingFace agent web search with WebSearchTools.

Code

from agno.agent import Agent
from agno.models.huggingface import HuggingFace
from agno.tools.websearch import WebSearchTools

agent = Agent(
    model=HuggingFace(id="openai/gpt-oss-120b"),
    tools=[WebSearchTools()],
    markdown=True,
)

if __name__ == "__main__":
    # --- Sync ---
    agent.print_response("What is the latest news on AI?")

    # --- Sync + Streaming ---
    agent.print_response("What is the latest news on AI?", stream=True)

Usage

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Set your API key

export HF_TOKEN=xxx

Install dependencies

uv pip install -U huggingface_hub ddgs agno

Save the example

Save the code above as huggingface_tool_use.py.

Run Agent

python huggingface_tool_use.py