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

[BUG] Standard function pow cannot be executed by an agent #546

Open
Bilokin opened this issue Feb 7, 2025 · 4 comments
Open

[BUG] Standard function pow cannot be executed by an agent #546

Bilokin opened this issue Feb 7, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Bilokin
Copy link

Bilokin commented Feb 7, 2025

Hello,

my steps are failing when the agent tries to invoke the standard pow function with the third argument

Code to reproduce the error

import smolagents
inter = smolagents.LocalPythonInterpreter(additional_authorized_imports=[], tools={})
inter('pow(2,2,2)', {})

Error logs (if any)

InterpreterError: Code execution failed at line 'pow(2,2,2)' due to: TypeError:pow expected 2 arguments, got 3

Expected behavior
A clear and concise description of what you expected to happen.

Packages version:
version 0.1.7 and main

Perhaps there are other standard functions that are affected by this error, a unit test would be nice

@Bilokin Bilokin added the bug Something isn't working label Feb 7, 2025
@albertvillanova
Copy link
Member

The LocalPythonInterpreter uses pow as an alias of math.pow, which only accepts 2 arguments.

Any reason for this choice? @aymeric-roucher

@sysradium
Copy link
Contributor

sysradium commented Feb 7, 2025

@Bilokin

But if you want it can be hacked around 🙃:

import smolagents

inter = smolagents.LocalPythonInterpreter(additional_authorized_imports=[], tools={"bpow": pow})
inter("bpow(2,2,2)", {})

The name has to be different as BASE takes precedence here: https://github.com/sysradium/smolagents/blob/main/src/smolagents/local_python_executor.py#L1332

@albertvillanova original math.pow accepts 2 arguments. So to me everything looks good, not a bug 🤔 It is in line with math.sqrt and the rest ...

@Bilokin
Copy link
Author

Bilokin commented Feb 8, 2025

Thanks for the fast reply!
The code I provided is just to reproduce the error, and the real-life error happens when the agent is trying to compute an expression with power operation with 3 arguments in an execution step.

I checked the other functions here and I think only pow is affected, so the fix should be just using the built-in pow instead of math.pow on line 88 as pointed out by @sysradium.

Also, I am curious, why are there math functions in BASE_PYTHON_TOOLS if math needs to be imported like any other package?

@sysradium
Copy link
Contributor

Probably we need to hear from the big man himself, since those "renames" appear to be there from the very inception :) sysradium@f3dcf1f#diff-fee74ba77e514d876543376ff66d78c26eae4ce359b9f3073e3be10fba6e4950R61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants