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
19.54k stars 2.7k forks source link

[BUG]FileWriterTool fails when Agent passes Input Arguments #1263

Open gulla0 opened 4 weeks ago

gulla0 commented 4 weeks ago

Description

Tested the FileWriterTool separately and it worked, but when passed to the agent, it fails for some reason.

Steps to Reproduce

  1. Import tool: from crewai_tools import FileWriterTool
  2. Pass it to the agent in tools parameter: tools=[FileWriterTool]
  3. Run crew

Expected behavior

A file is created and modified based on user input.

Screenshots/Code snippets

FileWriterTest:

from crewai_tools import FileWriterTool

# Initialize the tool
file_writer_tool = FileWriterTool()

# Define the arguments as a dictionary
arguments = {
    'filename': 'example.md',
    'content':  'This is an example content',
    'directory': '/Users/xxx/Desktop/developerCrew/ODIN_1',
    'overwrite': True  
}

# Call the tool with the dictionary of arguments
result = file_writer_tool.run(**arguments)
print(result)

Tool Import and Use in Agent:

from textwrap import dedent
from crewai import Agent
# Importing crewAI tools
from crewai_tools import (
    DirectoryReadTool,
    DirectorySearchTool,
    FileReadTool,
    TXTSearchTool,
    VisionTool,
    FileWriterTool
)

# Agents
class QstarLeader():
    def requirements_creator(self):
        return Agent(
            role='Requirement Creator',
            goal=dedent("""\
                Generate a comprehensive, modular requirements document 
                that accurately reflects user needs based on the task."""),
            backstory=dedent("""\
                As the primary liaison between the client needs and the development team, 
                you excel at understanding user needs and translating them into actionable requirements. 
                You ensure that each requirement is detailed enough for individual development and testing. 
                Additionally, you can reference the existing codebase to align new requirements 
                with the current implementation, ensuring consistency and avoiding conflicts."""),
             tools=[
                VisionTool(),  # Instantiate the tool
                DirectoryReadTool(),
                DirectorySearchTool(),
                FileReadTool(),
                TXTSearchTool(),
                FileWriterTool()
            ],
            verbose=True,  # Optional
        )

    def prompt_engineer(self):
        return Agent(
            role='Analytical Intermedeiary and prompt engineer',
            goal=dedent("""\
                    Understand user needs and translate them into well formatted outputs"""),
            backstory=dedent("""\
                    As the primary liaison between the client and the requirements creator agent, 
                    you excel at understanding user needs and formatting them as 
                    per the best prompting practices."""),
            tools=[
                VisionTool(),  # Instantiate the tool
                FileReadTool()
            ],
            verbose=True,  # Optional
        )

Operating System

macOS Sonoma

Python Version

3.11

crewAI Version

0.51.1

crewAI Tools Version

0.8.3

Virtual Environment

Venv

Evidence

Crew Response:

#### Minimal Content Test

### Thought Process
I will ensure the dictionary keys and values are accurately formatted and attempt to write minimal content to the `requirements.md` file again.

### Action
**Action:** File Writer Tool  
**Action Input:** {"filename": "requirements.md", "content": "Minimal content test", "directory": "/Users/xxx/Desktop/developerCrew/ODIN_1", "overwrite": True}

### Observation
Error: the Action Input is not a valid key, value dictionary.

### Thought Process
It appears that I continually encountered issues with formatting the content correctly for the `File Writer Tool`. Given these persistent issues, I will now proceed to create the necessary module folders in the directory `/Users/xxx/Desktop/developerCrew/ODIN_1/code`.

Possible Solution

I'm not sure about the solution. I was wondering if anyone else has this problem.

Additional context

My assumption is that the issue is with how the Agent is passing arguments to the FileWriterTool.

peebles commented 2 days ago

I am encountering this as well. The problem is that "overwrite" is being passed true, not True, or false instead of False, as in this example:

...
## Tool Input: 
{
  "filename": "data/companies/lanasdance/emails/Julia_Brown.txt",
  "content": "Subject: 🎄 New Hip-Hop Class for the Holidays! Get Your Groove On at Lana's Dance Studio! 🎄\n\nDear Julia Brown,\n\nHo ho ho! 🎅\n\nThe festive season is upon us, and we're thrilled to bring some holiday cheer with our brand-new Hip-Hop class during the Christmas holidays! While we know Contemporary dance is your favorite, we believe you’ll love the fresh beats and dynamic moves of Hip-Hop too. Why not try something new at Lana's Dance Studio this season?\n\nHere's why you should join us:\n\n🔥 **Experienced Instructors:** Learn from the best! Our Hip-Hop classes are led by Jessica Rodriguez and Michael Patel, both seasoned professionals with impressive backgrounds in dance and choreography.\n\n🎶 **Age-Specific Sessions:** We have tailored sessions for every age group, and our Teen Dance classes are designed especially for dancers like you, ensuring a supportive and fun environment.\n\n🌟 **Holistic Benefits:** Dancing is a fantastic way to stay active, improve cardiovascular health, build muscle strength, and reduce stress. Plus, it's a great way to make new friends and be part of a vibrant community!\n\n🏆 **Top-Notch Facilities:** Enjoy spacious dance studios equipped with professional sound systems and sprung flooring, ensuring a safe and comfortable experience every time you hit the dance floor.\n\nJoin us for a groove-filled holiday season and make unforgettable memories at Lana's Dance Studio. Spaces are limited, so make sure to **[register now](#)** and secure your spot!\n\nFor more details on class schedules, pricing, and our studio policies, visit our [website](#) or contact us at (408) 778-1178.\n\nDance into the holidays with style at Lana's Dance Studio!\n\nBest wishes,\nLana Afanasiev\nOwner & Director\nLana's Dance Studio\n\nP.S. Don’t forget to check out our holiday discounts for multiple classes and sibling registrations! Ask our staff for more details. 🎁\n\n---\n\nPhone: 408.778.1178  \nAddress: 330 Tennant Ave., Suite 150, Morgan Hill, CA 95037  \n[Visit our website](#) for more information.\n\n---\n\nFollow Us on Social Media:  \n**Facebook** | **Instagram** | **Twitter**\n\nNote: If you no longer wish to receive these emails, please [unsubscribe](#).\n\n---\n\nThe holiday season is the perfect time to try something new. We can't wait to see you on the dance floor, spreading joy and rhythm!\n\nHappy Holidays,\nThe Lana's Dance Studio Team",
  "overwrite": true
}
## Tool Output: 
Error: the Action Input is not a valid key, value dictionary.

If I say something like "never overwrite files" in my task directions, then "overwrite" is passed false instead of False.