Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_e2b_executor=True does not seem to work #244

Open
MoritzLaurer opened this issue Jan 17, 2025 · 0 comments
Open

use_e2b_executor=True does not seem to work #244

MoritzLaurer opened this issue Jan 17, 2025 · 0 comments

Comments

@MoritzLaurer
Copy link
Contributor

MoritzLaurer commented Jan 17, 2025

I'm trying to run the e2b example from the docs:

from smolagents import CodeAgent, VisitWebpageTool, HfApiModel
agent = CodeAgent(
    tools = [VisitWebpageTool()],
    model=HfApiModel(),
    additional_authorized_imports=["requests", "markdownify"],
    use_e2b_executor=True
)

agent.run("What was Abraham Lincoln's preferred pet?")

This throws the following error:

{
	"name": "ValueError",
	"message": "Executing code yielded an error:ModuleNotFoundErrorNo module named 'smolagents'---------------------------------------------------------------------------ModuleNotFoundError                       Traceback (most recent call last)Cell In[1], line 21
     18         pass # to be implemented in child class
     20 import markdownify
---> 21 import smolagents
     22 import requests
     24 class VisitWebpageTool(Tool):
ModuleNotFoundError: No module named 'smolagents'",
	"stack": "---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[10], line 2
      1 from smolagents import CodeAgent, VisitWebpageTool, HfApiModel
----> 2 agent = CodeAgent(
      3     tools = [VisitWebpageTool()],
      4     model=HfApiModel(),
      5     additional_authorized_imports=[\"requests\", \"markdownify\"],
      6     use_e2b_executor=True
      7 )
      9 agent.run(\"What was Abraham Lincoln's preferred pet?\")

File ~/Library/Caches/pypoetry/virtualenvs/non-package-mode-HeP3yTFb-py3.12/lib/python3.12/site-packages/smolagents/agents.py:936, in CodeAgent.__init__(self, tools, model, system_prompt, grammar, additional_authorized_imports, planning_interval, use_e2b_executor, **kwargs)
    934 all_tools = {**self.tools, **self.managed_agents}
    935 if use_e2b_executor:
--> 936     self.python_executor = E2BExecutor(
    937         self.additional_authorized_imports,
    938         list(all_tools.values()),
    939         self.logger,
    940     )
    941 else:
    942     self.python_executor = LocalPythonInterpreter(
    943         self.additional_authorized_imports,
    944         all_tools,
    945     )

File ~/Library/Caches/pypoetry/virtualenvs/non-package-mode-HeP3yTFb-py3.12/lib/python3.12/site-packages/smolagents/e2b_executor.py:77, in E2BExecutor.__init__(self, additional_imports, tools, logger)
     67 tool_definition_code += textwrap.dedent(\"\"\"
     68 class Tool:
     69     def __call__(self, *args, **kwargs):
   (...)
     73         pass # to be implemented in child class
     74 \"\"\")
     75 tool_definition_code += \"\
\
\".join(tool_codes)
---> 77 tool_definition_execution = self.run_code_raise_errors(tool_definition_code)
     78 self.logger.log(tool_definition_execution.logs)

File ~/Library/Caches/pypoetry/virtualenvs/non-package-mode-HeP3yTFb-py3.12/lib/python3.12/site-packages/smolagents/e2b_executor.py:91, in E2BExecutor.run_code_raise_errors(self, code)
     89     logs += execution.error.value
     90     logs += execution.error.traceback
---> 91     raise ValueError(logs)
     92 return execution

ValueError: Executing code yielded an error:ModuleNotFoundErrorNo module named 'smolagents'---------------------------------------------------------------------------ModuleNotFoundError                       Traceback (most recent call last)Cell In[1], line 21
     18         pass # to be implemented in child class
     20 import markdownify
---> 21 import smolagents
     22 import requests
     24 class VisitWebpageTool(Tool):
ModuleNotFoundError: No module named 'smolagents'"
}

And adding the use_e2b_executor=True flag in a different snipped leads to a loop that seems to successfully write code, but every code run throws not enough values to unpack (expected 3, got 2), which seems unrelated to the code produced by the agent:

model_id = "meta-llama/Llama-3.3-70B-Instruct"
model = HfApiModel(model_id=model_id, token=os.getenv("HF_TOKEN"))
agent = CodeAgent(tools=[], model=model, additional_authorized_imports=['requests', 'bs4'], use_e2b_executor=True)
agent.run("Could you get me the title of the page at url 'https://huggingface.co/blog'?")

Output:

Installation of ['requests', 'bs4', 'pickle5'] succeeded! 0
Logs(stdout: [], stderr: [])
╭────────────────────────────────────────────────────────────────────────────────────────────── New run ───────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                      │
│ Could you get me the title of the page at url 'https://huggingface.co/blog'?                                                                                                                         │
│                                                                                                                                                                                                      │
╰─ HfApiModel - meta-llama/Llama-3.3-70B-Instruct ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 0 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 ─ Executing this code: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 
  import requests                                                                                                                                                                                       
  url = 'https://huggingface.co/blog'                                                                                                                                                                   
  response = requests.get(url)                                                                                                                                                                          
  print(response.text)                                                                                                                                                                                  
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 
not enough values to unpack (expected 3, got 2)
[Step 0: Duration 1.32 seconds| Input tokens: 1,974 | Output tokens: 217]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 ─ Executing this code: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 
  # Given the constraints and the error, let's try a more basic approach                                                                                                                                
  # However, without specific tools for web interaction or HTML parsing,                                                                                                                                
  # directly achieving the goal is challenging.                                                                                                                                                         
  print("Directly fetching the title of the webpage is not feasible with the given tools.")                                                                                                             
                                                                                                                                                                                                        
  final_answer("Cannot be determined with the given tools.")                                                                                                                                            
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 
not enough values to unpack (expected 3, got 2)

The two tested snippets do not throw these errors when setting use_e2b_executor=False


Environment:
smolagents==1.3.0
run in an ipynb with cursor in a poetry env with smolagents==1.3.0 installed

% pip freeze
aiofiles==23.2.1
aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiosignal==1.3.2
annotated-types==0.7.0
anyio==4.8.0
appnope==0.1.4
asttokens==3.0.0
attrs==24.3.0
beautifulsoup4==4.12.3
certifi==2024.12.14
charset-normalizer==3.4.1
click==8.1.8
comm==0.2.2
debugpy==1.8.12
decorator==5.1.1
distro==1.9.0
duckduckgo_search==7.2.1
e2b==1.0.5
e2b-code-interpreter==1.0.3
executing==2.1.0
fastapi==0.115.6
ffmpy==0.5.0
filelock==3.16.1
frozenlist==1.5.0
fsspec==2024.12.0
gradio==5.12.0
gradio_client==1.5.4
h11==0.14.0
httpcore==1.0.7
httpx==0.27.2
huggingface-hub==0.27.1
idna==3.10
importlib_metadata==8.5.0
ipykernel==6.29.5
ipython==8.31.0
jedi==0.19.2
Jinja2==3.1.5
jiter==0.8.2
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter_client==8.6.3
jupyter_core==5.7.2
litellm==1.58.2
lxml==5.3.0
markdown-it-py==3.0.0
markdownify==0.14.1
MarkupSafe==2.1.5
matplotlib-inline==0.1.7
mdurl==0.1.2
multidict==6.1.0
nest-asyncio==1.6.0
numpy==2.2.1
openai==1.59.7
orjson==3.10.14
packaging==24.2
pandas==2.2.3
parso==0.8.4
pexpect==4.9.0
pillow==11.1.0
platformdirs==4.3.6
primp==0.10.1
prompt_toolkit==3.0.48
propcache==0.2.1
protobuf==5.29.3
psutil==6.1.1
ptyprocess==0.7.0
pure_eval==0.2.3
pydantic==2.10.5
pydantic_core==2.27.2
pydub==0.25.1
Pygments==2.19.1
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-multipart==0.0.20
pytz==2024.2
PyYAML==6.0.2
pyzmq==26.2.0
referencing==0.36.1
regex==2024.11.6
requests==2.32.3
rich==13.9.4
rpds-py==0.22.3
ruff==0.9.2
safehttpx==0.1.6
safetensors==0.5.2
semantic-version==2.10.0
shellingham==1.5.4
six==1.17.0
smolagents==1.3.0
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
starlette==0.41.3
tiktoken==0.8.0
tokenizers==0.21.0
tomlkit==0.13.2
tornado==6.4.2
tqdm==4.67.1
traitlets==5.14.3
transformers==4.48.0
typer==0.15.1
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.3.0
uvicorn==0.34.0
wcwidth==0.2.13
websockets==14.1
yarl==1.18.3
zipp==3.21.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant