ModuleNotFoundError: No module named 'transformers.agents'

Hi,

I am testing Transformer Agents but it seems like the agent is not working.

Code
###################################################################
from transformers import HfAgent

api_token = “my personal api token”
agent = HfAgent(“https://api-inference.huggingface.co/models/bigcode/starcoder2-15b”, token=api_token)
print(“StarCoder is initialized :muscle:”)

boat = agent.run(“Generate an image of a boat in the water”)
print(boat)

###################################################################
Error Code:
Traceback (most recent call last):
File “main.py”, line 13, in
boat = agent.run(“Generate an image of a boat in the water”)
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/site-packages/transformers/tools/agents.py”, line 349, in run
self.cached_tools = resolve_tools(code, self.toolbox, remote=remote, cached_tools=self.cached_tools)
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/site-packages/transformers/tools/agents.py”, line 141, in resolve_tools
resolved_tools[name] = load_tool(task_or_repo_id, remote=_remote)
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/site-packages/transformers/tools/base.py”, line 690, in load_tool
return Tool.from_hub(task_or_repo_id, model_repo_id=model_repo_id, token=token, remote=remote, **kwargs)
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/site-packages/transformers/tools/base.py”, line 262, in from_hub
tool_class = get_class_from_dynamic_module(tool_class, repo_id, use_auth_token=token, **hub_kwargs)
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/site-packages/transformers/dynamic_module_utils.py”, line 497, in get_class_from_dynamic_module
return get_class_in_module(class_name, final_module.replace(“.py”, “”))
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/site-packages/transformers/dynamic_module_utils.py”, line 199, in get_class_in_module
module = importlib.import_module(module_path)
File “/Users/yoojinchoi/miniforge3/envs/agent/lib/python3.8/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 975, in _find_and_load_unlocked
File “”, line 671, in _load_unlocked
File “”, line 843, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/Users/yoojinchoi/.cache/huggingface/modules/transformers_modules/huggingface-tools/text-to-image/5109976614257b9fb49408d8cc5364e77bb57894/text_to_image.py”, line 1, in
from transformers.agents.tools import Tool
ModuleNotFoundError: No module named ‘transformers.agents’

###################################################################

I did install transformer by following this steps:

I made sure the arch is i386.

Could you please help me ? I really want to build open-sourced agents without OpanAI’s tool and I thought Transformer Agent would be a great tool to give it a try.
Thank you!

The 2.0 agent is not main branch yet.
You can get early access like this : pip install “git+https://github.com/huggingface/transformers.git#egg=transformers[agents]”

Hey there!

I was in the same boat with the error ModuleNotFoundError: No module named ‘transformers.agents’

The reason is because there has been a refactor of agents! See here:

Looks like we are going need to refactor along with these changes or use an old version. Hope this helped you!