Skip to content

Tool.from_space() fails with gradio_client 2.5.0: Client.init() got an unexpected keyword argument 'hf_token' #2481

Description

@osmangulercan

Problem

Tool.from_space() fails when following the Hugging Face Agents Course example due to an unexpected keyword argument (hf_token) passed to gradio_client.Client.

This appears to be a compatibility issue between smolagents and gradio_client.

Steps to reproduce

  1. Install smolagents==1.26.0 and gradio_client==2.5.0.
  2. Run the following example from the Hugging Face Agents Course:
  3. The code raises a TypeError.
from smolagents import CodeAgent, InferenceClientModel, Tool

image_generation_tool = Tool.from_space(
    "black-forest-labs/FLUX.1-schnell",
    name="image_generator",
    description="Generate an image from a prompt"
)

model = InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct")

agent = CodeAgent(
    tools=[image_generation_tool],
    model=model
)

Actual behavior and error logs

The following exception is raised:

Traceback (most recent call last):
  File "ImportingaHuggingFaceSpaceAsaTool.py", line 3, in <module>
    image_generation_tool = Tool.from_space(
        "black-forest-labs/FLUX.1-schnell",
        name="image_generator",
        description="Generate an image from a prompt"
    )
  File "...\\site-packages\\smolagents\\tools.py", line 733, in from_space
    return SpaceToolWrapper(...)
  File "...\\site-packages\\smolagents\\tools.py", line 658, in __init__
    self.client = Client(space_id, hf_token=token)
TypeError: Client.__init__() got an unexpected keyword argument 'hf_token'

After investigating, I found that the installed gradio_client.Client accepts token instead of hf_token.

Changing

Client(space_id, hf_token=token)

to

Client(space_id, token=token)

inside smolagents/tools.py resolved the issue and the example worked successfully.

Expected behavior

The example from the Hugging Face Agents Course should run successfully without requiring any modification to the smolagents source code.

Environment:

  • OS: Windows 10
  • Python version: 3.14.3
  • Package version:
Name: smolagents
Version: 1.26.0

Name: gradio_client
Version: 2.5.0

Additional context (optional)

I encountered this issue while following the Hugging Face Agents Course:

https://huggingface.co/learn/agents-course/unit2/smolagents/tools

The issue appears to be related to the Client constructor using hf_token, while the installed gradio_client expects token.


Checklist

  • I have searched the existing issues and have not found a similar bug report.
  • I have provided a minimal, reproducible example.
  • I have provided the full traceback of the error.
  • I have provided my environment details.
  • I am willing to work on this issue and submit a pull request. (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions