crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
21.62k stars 3k forks source link

[BUG] CodeInterpreterTool Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.') #1555

Open hliuci opened 3 weeks ago

hliuci commented 3 weeks ago

Description

Hi, I am using Crew AI to set up an agent to convert JSON data to an Excel file and save it in the current directory. I used CodeInterpreterTool for the setup. When I run the agent, it showed (the same error exists even with unsafe mode):

I encountered an error while trying to use the tool. This was the error: Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.').
 Tool Code Interpreter accepts these inputs: Code Interpreter(code: 'string', libraries_used: 'array') - Interprets Python3 code strings with a final print statement. code: 'Python3 code used to be interpreted in the Docker container. ALWAYS PRINT the final result and the output of the code', libraries_used: 'List of libraries used in the code with proper installing names separated by commas. Example: numpy,pandas,beautifulsoup4'

And the final answer is:

Below is the Python script that would accomplish the task of converting the JSON data to an Excel file, given a functioning Python environment with pandas installed:

python
import pandas as pd
...

This script first flattens the JSON data into a list of dictionaries, each representing a row in the final dataframe. Then it uses pandas to convert this list into a dataframe. Finally, it writes this dataframe to an Excel file named 'output.xlsx' in the current working directory. To execute this script, one would need a Python interpreter and the pandas library installed on their system.

It seems that the codes were not executed to generate an Excel file.

Steps to Reproduce

The error occured when running the codes below.

Expected behavior

An Excel file is generated and saved in the current directory.

Screenshots/Code snippets

from crewai import Agent, Task, Crew
from crewai_tools import CodeInterpreterTool

code_interpreter_tool = CodeInterpreterTool(libraries_used = ['pandas', 'openpyxl', 'json', 'ast', 'os'])

coding_agent = Agent(
    role="Python software developer",
    goal="Analyze the input data {input} and do file conversion using Python",
    backstory="You are an experienced software developer with strong Python skills.",
    allow_code_execution=True,
    verbose=True,
    allow_delegation=False,
    llm="azure/gpt-4-1106-preview",
    tools = [code_interpreter_tool]
)

json_to_excel_task = Task(
    description="Write Python codes to convert the input JSON data {input} to Excel file and save to the current directory",
    expected_output="A saved Excel file with the data from the input JSON data {input}",
    agent=coding_agent
)

analysis_crew = Crew(
    agents=[coding_agent],
    tasks=[json_to_excel_task],
    verbose=True
)

nested_json = '''{
    "Kitchen": {
        "temperature": 30,
        "adjacent_room": {
            "Toilet": {
                "temperature": 24,
                "shared_wall_area": 13.48
            },
            "Living_Rm1": {
                "temperature": 27,
                "shared_wall_area": 21.6
            }
        }
    },
    "Toilet": {
        "temperature": 24,
        "adjacent_room": {
            "Kitchen": {
                "temperature": 30,
                "shared_wall_area": 42.6
            },
            "Living_Rm1": {
                "temperature": 27,
                "shared_wall_area": 21.6
            }
        }
    }
}'''

result = analysis_crew.kickoff(inputs={"input": nested_json})
print(result)

Operating System

Windows 11

Python Version

3.10

crewAI Version

0.70.1

crewAI Tools Version

0.12.1

Virtual Environment

Venv

Evidence

image

Possible Solution

None

Additional context

NA

blakkd commented 1 week ago

I don't know if it's related but I can't make the CodeInterpreterTool work either. That said, I don't want to hijack the OP, just maybe complete the debugging info.

For simplicity, I have everything in a single python file:

import os
from crewai import Agent, Task, Crew, Process, LLM
from crewai_tools import SerperDevTool, SeleniumScrapingTool, ScrapeWebsiteTool, FileReadTool, FileWriterTool, CodeInterpreterTool, ScrapeWebsiteTool

os.environ["SERPER_API_KEY"] = "XXXXX"

llm_researcher = LLM(model="ollama_chat/qwen2.5:32b-instruct-q4_K_M_11k", base_url="http://localhost:11434", temperature=0.05)
llm_journalist = LLM(model="ollama_chat/qwen2.5:32b-instruct-q4_K_M_11k", base_url="http://localhost:11434", temperature=0.05)

researcher = Agent(
  role='Web Researcher',
  goal='Find any information on the web.',
  backstory="""You work at a leading web monitoring company.
  You have a knack for dissecting complex data and presenting it.""",
  verbose=True,
  allow_delegation=False,
  llm=llm_researcher,
  tools=[SerperDevTool(), SeleniumScrapingTool(), FileWriterTool(), FileReadTool()]
)

coder = Agent(
  role='Coder',
  goal='Solve coding problems and automate tasks.',
  backstory="""You are an experienced coder working at a leading BigTech company.
  You have a knack for writing efficient code to solve complex data problems.""",
  verbose=True,
  allow_delegation=False,
  llm=llm_researcher,
  tools=[CodeInterpreterTool(), FileWriterTool(), FileReadTool()]
)

journalist = Agent(
  role='Journalist',
  goal="""Summarize any received text, regardless of what type it is.
  Go in depth, detail everything.
    Organize your summary using headings and subheadings, paragraphs, text styles, lists, quotes, or tables as needed to make the content easy to read.
    Adapt the vocabulary so that it is accessible to anyone.""",
    backstory="""You are a renowned rigorous journalist known for insightful and engaging articles. You excel at transforming complex concepts into compelling narratives.""",
  verbose=True,
  allow_delegation=False,
  llm=llm_journalist,
  tools=[FileWriterTool(), FileReadTool()]
)

task1 = Task(
  description="Get the current date/time by executing a minimal python script.",
  expected_output="""The current date.""",
  agent=coder
)

task2 = Task(
  description="Keeping in mind the current date obtained from task1, scrape the content from the second to most recent article on xxxx.",
  expected_output="""The raw text of the article.""",
  output_file="""article.txt""",
  agent=researcher
)

task3 = Task(
  description="""Provide a detailed summary of the article contained in article.md.""",
  expected_output="""A summary (formatted in Markdown), along with the sources links which it could eventually contain.""",
  output_file="""summary.md""",
  agent=journalist
)

crew = Crew(
  agents=[researcher, journalist],
  tasks=[task1, task2, task3],
  verbose=True,
  #process = Process.hierarchical,
  #manager_llm = LLM(model="ollama_chat/qwen2.5:32b-instruct-q4_K_M_11k, base_url="http://localhost:11434", temperature=0.05),
  process = Process.sequential
)
result = crew.kickoff()

print("######################")
print(result)

And here is the error I keep on getting:

# Agent: Coder
## Task: Get the current date/time by executing a minimal python script.

I encountered an error while trying to use the tool. This was the error: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).
 Tool Code Interpreter accepts these inputs: Tool Name: Code Interpreter
Tool Arguments: {'code': {'description': 'Python3 code used to be interpreted in the Docker container. ALWAYS PRINT the final result and the output of the code', 'type': 'str'}, 'libraries_used': {'description': 'List of libraries used in the code with proper installing names separated by commas. Example: numpy,pandas,beautifulsoup4', 'type': 'list[str]'}}
Tool Description: Interprets Python3 code strings with a final print statement.

# Agent: Coder
## Using tool: Code Interpreter
## Tool Input: 
"{\"code\": \"from datetime import datetime\\nprint(datetime.now())\", \"libraries_used\": []}"
## Tool Output: 

I encountered an error while trying to use the tool. This was the error: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).
 Tool Code Interpreter accepts these inputs: Tool Name: Code Interpreter
Tool Arguments: {'code': {'description': 'Python3 code used to be interpreted in the Docker container. ALWAYS PRINT the final result and the output of the code', 'type': 'str'}, 'libraries_used': {'description': 'List of libraries used in the code with proper installing names separated by commas. Example: numpy,pandas,beautifulsoup4', 'type': 'list[str]'}}
Tool Description: Interprets Python3 code strings with a final print statement..
Moving on then. I MUST either use a tool (use one at time) OR give my best final answer not both at the same time. To Use the following format:

Thought: you should always think about what to do
Action: the action to take, should be one of [Code Interpreter, File Writer Tool, Read a file's content]
Action Input: the input to the action, dictionary enclosed in curly braces
Observation: the result of the action
... (this Thought/Action/Action Input/Result can repeat N times)
Thought: I now can give a great answer
Final Answer: Your final answer must be the great and the most complete as possible, it must be outcome described

I encountered an error while trying to use the tool. This was the error: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).
 Tool Code Interpreter accepts these inputs: Tool Name: Code Interpreter
Tool Arguments: {'code': {'description': 'Python3 code used to be interpreted in the Docker container. ALWAYS PRINT the final result and the output of the code', 'type': 'str'}, 'libraries_used': {'description': 'List of libraries used in the code with proper installing names separated by commas. Example: numpy,pandas,beautifulsoup4', 'type': 'list[str]'}}
Tool Description: Interprets Python3 code strings with a final print statement.

I also tried qwen2.5-coder:32b-instruct-q4_K_M without any success. The other tools are working as intended.

blakkd commented 1 week ago

I tried with LLM(model="groq/llama-3.1-70b-versatile", temperature=0.05) but same result

paarttipaabhalaji commented 3 days ago

I also need this solution. any one please help to resolve this.