Repository navigation
Something about agent.python_executor and additional_authorized_imports
#977
Replies: 1 comment
|
Yes, for the default local executor, those two lines serve different purposes:
For your tool question: a registered local Python tool executes its implementation as a normal Python callable. Its internal imports do not need to be added to the executor's import list solely because the tool uses them. Its dependencies still need to be installed in the host environment. This distinction is specifically about local tools; remote execution has its own environment requirements. There is also a version detail in the example: with smolagents 1.26.0, the call takes just the code string: # After constructing the agent with additional_authorized_imports=["helium"]:
agent.python_executor("from helium import *")The older Preloading is optional if the agent's generated code imports what it needs itself. In this particular example, the instructions tell the model that the import has already happened, so keeping that preload makes the instructions match the execution state. The executor's import handling shows the authorization check and the separate state assignments. Verification: six local checks passed on both the PyPI 1.26.0 package and a 1.27.0.dev0 checkout based on |
Uh oh!
There was an error while loading. Please reload this page.
I have a question about a code snippet from the smolagents web browser automation example:
In this code, there are two instances where the helium library is referenced:
1. The additional_authorized_imports=["helium"] parameter in the CodeAgent initialization.
2. The agent.python_executor("from helium import *", agent.state) command.
I understand that additional_authorized_imports is used to grant the agent permission to use specific packages in the code it generates. Does this mean that if a tool within the agent requires the helium library, it doesn’t need to be listed here, and this parameter is solely for imports in the agent’s own code?
Additionally, could someone clarify the purpose of the second reference, agent.python_executor("from helium import *", agent.state)? Is this command necessary to explicitly import the helium functions into the agent’s execution environment, allowing it to utilize them during its operations?
Thank you for your assistance in understanding these distinctions.
ref: https://huggingface.co/docs/smolagents/en/examples/web_browser
Git
All reactions