Hugging Face Tool Use

Add web search tools to a GPT-OSS 120B agent on Hugging Face.

tool_use.py
"""
Huggingface Tool Use
====================

Cookbook example for `huggingface/tool_use.py`.
"""

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

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

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

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
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)

The current Hugging Face streaming parser can omit additional tool calls when a single streamed delta contains more than one call. Use the non-streaming invocation for this example when all requested tools must execute.

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno ddgs huggingface-hub

Export environment variables

export HF_TOKEN="your_hf_token_here"

Use the non-streaming tool path

Save the source as tool_use.py and remove stream=True from the second print_response call. Both calls will then use the non-streaming path.

Run the example

Save the code above as tool_use.py, then run:

python tool_use.py

Full source: cookbook/90_models/huggingface/tool_use.py