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] Agents can create infinite loops using functions #871

Open
Bilokin opened this issue Mar 4, 2025 · 0 comments · May be fixed by #891
Open

[BUG] Agents can create infinite loops using functions #871

Bilokin opened this issue Mar 4, 2025 · 0 comments · May be fixed by #891
Labels
bug Something isn't working

Comments

@Bilokin
Copy link
Contributor

Bilokin commented Mar 4, 2025

Hello,

there is a nice protection against infinite loops in the local python interpreter, but unfortunately, it doesn't work if an agent creates a double loop with a second loop in a function.

Code to reproduce the error
Here is an example of a correct interruption at 10000000 operations:

inter = smolagents.LocalPythonExecutor(additional_authorized_imports=[])
inter.send_tools({})
code = """
a = 0
for i in range(10_000):
    for j in range(10_000):  
        a += i+j
"""
inter(code)

And the following code proceeds till the end:

inter = smolagents.LocalPythonExecutor(additional_authorized_imports=[])
inter.send_tools({})
code = """
a = 0
def foo(a,i):
    for j in range(10_000):  
        a += i+j
    return a
for i in range(10_000):
    a = foo(a,i)
"""
inter(code)

Expected behavior
Expected InterpreterError: Reached the max number of operations of 10000000. Maybe there is an infinite loop somewhere in the code, or you're just asking too many calculations. in the second case as well.

Packages version:
Affected main

@Bilokin Bilokin added the bug Something isn't working label Mar 4, 2025
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

Successfully merging a pull request may close this issue.

1 participant