Skip to content

[BUG] Cannot execute class method with LocalPythonExecutor #1165

@ZeusFSX

Description

@ZeusFSX

Describe the bug
My LLM write the code in OOP style, defined the class and class methods, when try to execute class method it fails

Code to reproduce the error

from smolagents import LocalPythonExecutor

agent_name = "Agent"
executor = LocalPythonExecutor(additional_authorized_imports=["json", "os", "urllib.parse", "bs4", "pprint"])
executor.send_variables({"agent_name": agent_name})

code = """
class Hello: 
    def greetings(self, name: str):
         return f"Hello {name}"

obj = Hello()
print(obj.greetings(agent_name))
"""
executor(code)

Error logs (if any)

InterpreterError: Code execution failed at line 'print(obj.greetings(agent_name))' 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 print).

Expected behavior
Successfully execute the code

Packages version:
smolagents==1.12.0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions