# ModuleNotFoundError: No module named 'transformers.agents'

**URL:** <https://discuss.huggingface.co/t/modulenotfounderror-no-module-named-transformers-agents/86151>\
**Category:** 🤗Transformers\
**Created:** [May 10, 2024, 3:55pm UTC](https://discuss.huggingface.co/t/modulenotfounderror-no-module-named-transformers-agents/86151 "2024-05-10T15:55:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugine5](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@eugine5](https://discuss.huggingface.co/u/eugine5)\
**Post date:** [May 10, 2024, 3:55pm UTC](https://discuss.huggingface.co/t/modulenotfounderror-no-module-named-transformers-agents/86151/1 "2024-05-10T15:55:23Z")

</div>

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](https://api-inference.huggingface.co/models/bigcode/starcoder2-15b)”, token=api\_token)  
print(“StarCoder is initialized 💪”)

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:

> **[Huggingface Installation on Apple Silicon 2022 (M1/Pro/Max/Ultra/M2)](https://medium.com/@faizififita1/huggingface-installation-on-apple-silicon-2022-m1-pro-max-ultra-m2-9c449b9b4c14)**
>
> The new MacBook’s, with their powerful processors, are spectacular machines with great potential as a portable Machines for on-the-go…

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!

---

<div class="post-metadata">

**Author:** ![jsemrau](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jsemrau/32/26919_2.png) [@jsemrau](https://discuss.huggingface.co/u/jsemrau)\
**Post date:** [May 13, 2024, 8:14pm UTC](https://discuss.huggingface.co/t/modulenotfounderror-no-module-named-transformers-agents/86151/2 "2024-05-13T20:14:14Z")

</div>

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]”

---

<div class="post-metadata">

**Author:** ![aesper](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@aesper](https://discuss.huggingface.co/u/aesper)\
**Post date:** [May 16, 2024, 1:02am UTC](https://discuss.huggingface.co/t/modulenotfounderror-no-module-named-transformers-agents/86151/3 "2024-05-16T01:02:47Z")

</div>

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:

> <https://github.com/huggingface/transformers/blob/main/docs/source/en/main_classes/agent.md>

> <https://github.com/huggingface/transformers/pull/30387>
>
> \# What does this PR do?
> 
> Reboot agents in transformers!
> 
> cc @LysandreJik

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