crewAI: Issue with CodeInterpreterTool not executing code (Agent responds but does nothing)

Description

I am building a full machine learning pipeline using CrewAI, and one of the agents is supposed to execute preprocessing steps via the CodeInterpreterTool. However, the Feature Engineering Specialist agent does not execute any code and finishes the task with a general response, ignoring the prompt instructions.

Steps to Reproduce

  1. Set up a CodeInterpreterTool like this:

code_tool = CodeInterpreterTool( user_dockerfile_path=‘path_to_dockerfile’ ) 2. Define a feature_engineering_agent and assign it the code_tool as its only tool: feature_engineering_agent = Agent( role=‘Feature Engineering Specialist’, goal=‘Clean, encode, and split raw data for machine learning using reproducible code and best practices.’, backstory=‘A meticulous data engineer who transforms raw datasets into modeling-ready splits.’, tools=[code_tool], verbose=True )

  1. Create a Task instructing the agent: feature_engineering_task = Task( description=( “You are responsible for cleaning and preparing the dataset {dataset} for modeling. Your steps are:\n\n” “1. Load the CSV file.\n” “2. Handle missing values (mean/mode or drop rows).\n” “3. Encode categorical variables (OneHot or Ordinal).\n” “4. Split the data using train_test_split with stratification on {target_variable} (80/20).\n” “5. Apply SMOTE (on training set only) if necessary.\n” “6. Save these outputs:\n” “- X_train.csv\n- X_test.csv\n- y_train.csv\n- y_test.csv\n\n” “👉 YOU MUST USE the Code Interpreter Tool to actually run your code.\n\n” “Use the following exact syntax:\n” “python\n" "code_tool.run(\n" " code=\"\"\"\n" "# your Python code here\n" " \"\"\",\n" " libraries_used=['pandas', 'numpy', 'scikit-learn', 'imblearn']\n" ")\n" "\n\n” “✅ Your final answer MUST be the output of the tool.\n” “❌ Do NOT just summarize what you did. Actually call the tool.” ), expected_output=“The result from the CodeInterpreterTool confirming files were saved.”, agent=feature_engineering_agent )

  2. Run the Crew with process=Process.sequential and memory=True.

  3. Observe the output of the feature engineering task.

Expected behavior

I expected the agent to generate and execute Python code using the tool as defined in its task. The code should clean the dataset and save outputs like X_train.csv, etc.

Screenshots/Code snippets

None

Operating System

Windows 11

Python Version

3.10

crewAI Version

0.108.0

crewAI Tools Version

0.38.1

Virtual Environment

Venv

Evidence

Agent: Feature Engineering Specialist

Final Answer:

My best complete final answer to the task is as follows:

To clean and prepare the dataset ./upsell_train_corrected.csv for modeling, I will perform the following steps:

  1. Load the CSV file.
  2. Handle missing values by imputing the mean for numeric columns (income and engagement_score).
  3. Encode categorical variables using OneHot encoding.
  4. Split the data using train_test_split with stratification on the upsell column with an 80/20 ratio.
  5. Save the resulting datasets as X_train.csv, X_test.csv, y_train.csv, and y_test.csv.

Let’s proceed with these steps to prepare the dataset for modeling.

Possible Solution

I thought it could be some issue with memory, cache, or hallucination, but I am a beginner.

Additional context

Other agents that use CodeInterpreterTool work fine and in previous executions it runs well. Sometimes also happened with another agent that use a custom tool.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 39 (21 by maintainers)

Commits related to this issue

Most upvoted comments

@Vidit-Ostwal I don’t know how, but I solved it. Thank you for your patience.

I have done it. The image is created correctly and run in a container. Then I deleted both and run the tool. The problem still there.

This two images appear and the one that is run in a container is the one without name. Then the log of the container is “Error response from daemon: configured logging driver does not support reading”.

Image

I don’t know what I did because a week ago it worked every time I tried to do it.

@diegoo7am weird… It would be useful to have the LLM execution logs. You can enable them by setting LITELLM_LOG = "DEBUG" as env var. Could you add that and send you some logs to check what is happen with LLM under the wood