CodeInterpreterTool - No result variable found

Hello community. I am creating a crew to perform data analysis and deep learning.
For this, I have a data analyst agent and a developer. In the tasks, both aim to generate Python code, run it, and return the code without errors. The code generation and execution are working, however, since the goal is to return the code, the CodeInterpreterTool returns “No result variable found.” and it’s looping. Is there any mistake, or am I doing it wrong?

@GuilhermeHenriqueBil Please edit your question above and add the code.

Hi @rokbenko , Bellow, the code!

    @agent
    def analista_dados(self) -> Agent:
        return Agent(
            config=self.agents_config['analista_dados'],
            tools=[run_codes],
            # allow_code_execution=True,
            verbose=True,
        )

    @agent
    def desenvolvedor(self) -> Agent:
        return Agent(
            config=self.agents_config['desenvolvedor'],
            backstory=dedent(
                f"Data Atual: {str(date.today().strftime('%d/%m/%Y'))}"
                f"{self.agents_config['desenvolvedor']['backstory']}"
            ),
            tools=[run_codes],
            # allow_code_execution=True,
            verbose=True,

Tasks:
@task
def desenvolver_analise_dados_task(self) → Task:
return Task(
config=self.tasks_config[‘desenvolver_analise_dados_task’],
)

    @task
    def desenvolvedor_task(self) -> Task:
        return Task(
            config=self.tasks_config['desenvolvedor_task'],
        )

tools:
run_codes = CodeInterpreterTool(unsafe_mode=True)

Hi -
Any update on this issue , how you resolved it?

could you please look into the below code and advice how to resolve the “No result variable issue”

Hi!

I have a similar problem. When I prompt the code executor agent to put the results in to a “result” variable, it works. But the problem remains when there is an error, because upon trying to correct it, the code executor agent ignores the prompt and does not use “result” variable. And then the looping begins…

The behaviour is defined in code_interpreter_tool.py:

def run_code_unsafe(self, code: str, libraries_used: List[str]) → str:
“”"
Run the code directly on the host machine (unsafe mode).
“”"
# Install libraries on the host machine
for library in libraries_used:
os.system(f"pip install {library}")

# Execute the code
try:
    exec_locals = {}
    exec(code, {}, exec_locals)
    return exec_locals.get("result", "No result variable found.")
except Exception as e:
    return f"An error occurred: {str(e)}"