Pass file path for DirectoryReadTool

Hi,

Is this the right way to pass the path for the DirectoryReadTool of crewai?

file_path = r’C:\OLP.doc’

docs_tool = DirectoryReadTool(directory=file_path)

file_tool = FileReadTool()

search_tool = SerperDevTool()

I am getting the output as below:

Tool Input:

“{}”

Tool Output:

File paths:

The output is below:

Agent: Senior Data Researcher

Thought: Thought: I need to read the content of the file C:\OLP.doc to understand the functional requirements and design test cases. I will use the List files in directory tool even though its description mentions reading file content. It’s the only tool available that might work. I’ll try to treat the file path as if the tool can access file content using it, as the tool’s description mentions reading.

Using tool: List files in directory

Tool Input:

“{"filepath": "C:\\OLP.doc"}”

Tool Output:

File paths:

Agent: Senior Data Researcher

Final Answer:

I am unable to complete the task with the available tool. I require a tool that can read the content of a file to understand the requirements outlined in “C:\OLP.doc” and create appropriate test cases. The “List files in directory” tool does not provide file content, and therefore, I cannot proceed.

Can you please suggest how to fix thus?

You are following the approach in the docs - but I found this as something easy to try:

Create an instance of the DirectoryReadTool :
directory_read_tool = DirectoryReadTool(directory_path)

where the path is being passed in directly as an arg instead of a kwarg - might not matter and I am not sure if it works…let me know.

Thank you. I tried the same
file_path = r’C:\Agent AI\PLAYGROUND\tccreator\OLP.doc’

Instantiate tools

docs_tool = DirectoryReadTool(directory=file_path)

Still the path is not picking up

It is my understanding that the filepath needs to point to the directory , not the file.

Try: file_path = r’C:\Agent AI\PLAYGROUND\tccreator\

Please find te code snippet:
file_path = r’C:/Agent AI/PLAYGROUND/tccreator/TC’

doc_path= r’C:/Agent AI/PLAYGROUND/tccreator/TC’

Instantiate tools

docs_tool = DirectoryReadTool(directory=file_path)

file_tool = FileReadTool()

search_tool = SerperDevTool()

word_tool = DOCXSearchTool(docx=doc_path)

Output below:

Agent: Senior Data Researcher

Thought: Thought: I need to search the provided document for the “2. Functional Requirements” section to design test cases.

Using tool: Search a DOCX’s content

Tool Input:

“{"docx": "C:/Agent AI/PLAYGROUND/tccreator/TC DOCX", "search_query": "2. Functional requirements"}”

Tool Output:

I encountered an error while trying to use the tool. This was the error: APIStatusError.init() missing 2 required keyword-only arguments: ‘response’ and ‘body’.
Tool Search a DOCX’s content accepts these inputs: Tool Name: Search a DOCX’s content
Tool Arguments: {‘docx’: {‘description’: ‘Mandatory docx path you want to search’, ‘type’: ‘Union[str, NoneType]’}, ‘search_query’: {‘description’: “Mandatory search query you want to use to search the DOCX’s content”, ‘type’: ‘str’}}
Tool Description: A tool that can be used to semantic search a query the C:/Agent AI/PLAYGROUND/tccreator/TC DOCX’s content…
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.

It is still not reading the file.

This is just a suggestion meant to be helpful. I can experiment with this later. For now try running without giving a docx path - just give the path once to the DirectoryReadTool:

docs_tool = DirectoryReadTool(directory=file_path)
file_tool = FileReadTool()
search_tool = SerperDevTool()
word_tool = DOCXSearchTool()

Be sure to assign both the DirectoryReadTool and the DOCXSearchTool to the Agent, and then add a statement in the TASK to ‘read the provided directory for all docx files and search each one.’

Thanks .Let me check this!