I’m trying to run this piece of code that i have found in the docs Agents - Guided tour
from smolagents import CodeAgent, TransformersModel
model_id = “meta-llama/Llama-3.2-3B-Instruct”
model = TransformersModel(model_id=model_id)
agent = CodeAgent(tools= , model=model, add_base_tools=True)
agent.run(
“Could you give me the 118th number in the Fibonacci sequence?”,
)
At step 1, it gives me this output:
*Executing parsed code: ────────────────────────────────────────────────────────────────────────────────────────
Generate the Fibonacci sequence up to the 120th number (since indexing starts at 0)
fibonacci_sequence = fibonacci(n=120)
Find the index of the 118th number in the sequence
index = index(fibonacci_sequence, 118)
Use the index to get the 118th number
answer = fibonacci_sequence[index]
print(f"The 118th number in the Fibonacci sequence is {answer}")
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Code execution failed at line ‘fibonacci_sequence = fibonacci(n=120)’ due to: InterpreterError: Forbidden function
evaluation: ‘fibonacci’ is not among the explicitly allowed tools or defined/imported in the preceding code*
I’m really stucked into this problem sice i would like to continue the agent course without using HfAPI
Is anyone able to tell me which is the problem?
1 Like
There are quite a few changes to the library, so I’m not sure what the exact cause is. It would be easy to work around it with code like this, but I’m not sure if it will work.
#agent = CodeAgent(tools=[], model=model, add_base_tools=True)
agent = CodeAgent(tools=, model=model, add_base_tools=True, additional_authorized_imports=["*"])
if func_name in state:
func = state[func_name]
elif func_name in static_tools:
func = static_tools[func_name]
elif func_name in custom_tools:
func = custom_tools[func_name]
elif func_name in ERRORS:
func = ERRORS[func_name]
else:
raise InterpreterError(
f"Forbidden function evaluation: '{call.func.id}' is not among the explicitly allowed tools or defined/imported in the preceding code"
)
elif isinstance(call.func, ast.Subscript):
func = evaluate_ast(call.func, state, static_tools, custom_tools, authorized_imports)
if not callable(func):
raise InterpreterError(f"This is not a correct function: {call.func}).")
func_name = None
args = []
for arg in call.args:
if isinstance(arg, ast.Starred):
opened 11:50PM - 04 Feb 25 UTC
closed 07:22AM - 06 Feb 25 UTC
bug
**Describe the bug**
Unable to execute function defined in the same Python inter… preter. See example below:
**Code to reproduce the error**
```python
from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
import applescript
def tell_siri(command_text: str):
"""Execute a Siri command."""
result = applescript.run(f"""
tell application "System Events" to tell the front menu bar of process "SystemUIServer"
tell (first menu bar item whose description is "Siri")
perform action "AXPress"
end tell
end tell
delay 2
tell application "System Events"
set textToType to "{command_text}"
keystroke textToType
key code 36
end tell
""")
task = """
0. Always check syntax on every step before code execution.
1. use tell_siri function to "turn off master bedroom light", wait 2 seconds, and turn on "master bedroom light" again.
"""
qwen_coder_model = LiteLLMModel(model_id="ollama/qwen2.5-coder:32b")
agent8 = CodeAgent(
tools=[DuckDuckGoSearchTool()],
additional_authorized_imports=["*"],
model=qwen_coder_model
)
agent8.run(task8)
```
**Error logs (if any)**
```
─ Executing parsed code: ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
import time
tell_siri("turn off master bedroom light")
time.sleep(2)
tell_siri("master bedroom light on")
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Code execution failed at line 'tell_siri("turn off master bedroom light")' due to: InterpreterError:It is not permitted to evaluate other functions than the provided tools or functions defined/imported in previous code (tried
to execute tell_siri).
```
**Expected behavior**
The function is local to the CodeAgent environment, I expect it to have access to the local functions.
**Packages version:**
Run `pip freeze | grep smolagents` and paste it here.
`smolagents==1.7.0`
**Additional context**
Add any other context about the problem here.
opened 03:37PM - 13 Feb 25 UTC
closed 02:19PM - 24 Feb 25 UTC
Hey,
I'm getting this error all the time:
**InterpreterError:It is not permitte… d to evaluate other functions than the provided tools or functions
defined/imported in previous code**
In manager.run I'm trying to pass additional_args=dict(source_file="file.csv").
Example of agent:
```
agent_core = CodeAgent(
model = model,
tools = [tool_1, tool_2],
additional_authorized_imports=["pandas", "matplotlib", "seaborn"],
name="Data Analyst",
description="""Analysis agent with a set of ready-to-use tools that parse, cleanse, and process the data provided."""
)
```
```
manager_agent = CodeAgent(
model=model,
tools=[],
managed_agents=[agent_core],
additional_authorized_imports=["pandas", "matplotlib", "seaborn"],
)
```
It works normally when I try to call agent_core.run directly, without manager_agent.
Does anyone have a similar problem?
I have modified the code line for the agent as suggested but i still get the problem. I attach a screenshot so that the output is clearer.
1 Like
This is probably a library bug…
The ideal solution in this case is to fix the library. Alternatively, you can wait for it to be fixed or try to find a workaround yourself. However, in some cases, it may be quicker to try downgrading the library first.
pip install smalagents==1.13.0
pip install smalagents==1.12.0
pip install git+https://github.com/huggingface/smolagents
1 Like