griptape-ai / griptape

Modular Python framework for AI agents and workflows with chain-of-thought reasoning, tools, and memory.
https://www.griptape.ai
Apache License 2.0
2.02k stars 170 forks source link

`FileManagerTool` does not work with absolute paths on mac, but does on windows. #1351

Closed shhlife closed 21 hours ago

shhlife commented 1 day ago

Describe the bug When testing absolute paths on Mac, we found that the FileManagerTool apepars to append the given path after the current working directory. The exact same code works fine on windows.

To Reproduce

import os

from griptape.structures import Agent
from griptape.tools import FileManagerTool

file_tool = FileManagerTool()

# Replace with appropriate paths
windows_path = "C:\\Users\\jason\\OneDrive\\Desktop\\texts"
mac_path = "/Users/jason/Desktop/texts"

# check what os the user is on
if os.name == "posix":
    prompt = "What files exist in " + mac_path
else:
    prompt = "What files exist in " + windows_path

agent = Agent(tools=[file_tool], stream=True)
agent.run(f"What files exist in {prompt}")

When running on MacOS, I get the following:

[11/15/24 13:46:51] INFO     ToolkitTask d47389d6c2ff4ec2a4c6c8df3a0fc192                                                                          
                             Input: What files exist in What files exist in /Users/jason/Desktop/texts                                             
[11/15/24 13:46:53] INFO     Subtask 1a1beafdefb74ec98018ddb9b3e5b25b                                                                              
                             Actions: [                                                                                                            
                               {                                                                                                                   
                                 "tag": "call_bxMrBtHYvvhpz4g0wX7lmPJX",                                                                           
                                 "name": "FileManagerTool",                                                                                        
                                 "path": "list_files_from_disk",                                                                                   
                                 "input": {                                                                                                        
                                   "values": {                                                                                                     
                                     "path": "/Users/jason/Desktop/texts"                                                                          
                                   }                                                                                                               
                                 }                                                                                                                 
                               }                                                                                                                   
                             ]                                                                                                                     
                    INFO     Subtask 1a1beafdefb74ec98018ddb9b3e5b25b                                                                              
                             Response: [Errno 2] No such file or directory:                                                                        
                             '/Users/jason/Documents/GitHub/griptape-intro-demos/Users/jason/Desktop/texts'                                        
[11/15/24 13:46:54] INFO     ToolkitTask d47389d6c2ff4ec2a4c6c8df3a0fc192                                                                          
                             Output: It seems that the directory `/Users/jason/Desktop/texts` does not exist. Please check the path and try again.           

Expected behavior

The expected behavior (what I see in Windows) is:

[11/15/24 13:45:46] INFO     ToolkitTask 952989497a494e1a8f6a1730c1601816
                             Input: What files exist in What files exist in C:\Users\jason\OneDrive\Desktop\texts
[11/15/24 13:45:48] INFO     Subtask 7771ccc0ff914953a963e3bf2c956a5f
                             Actions: [
                               {
                                 "tag": "call_eAvZ04h24mVpt6kdTXfoXxU2",
                                 "name": "FileManagerTool",
                                 "path": "list_files_from_disk",
                                 "input": {
                                   "values": {
                                     "path": "C:/Users/jason/OneDrive/Desktop/texts"
                                   }
                                 }
                               }
                             ]
                    INFO     Subtask 7771ccc0ff914953a963e3bf2c956a5f
                             Response: one.txt
                             two.txt
[11/15/24 13:45:49] INFO     ToolkitTask 952989497a494e1a8f6a1730c1601816
                             Output: The files that exist in `C:\Users\jason\OneDrive\Desktop\texts` are:

                             - `one.txt`
                             - `two.txt`

Desktop (please complete the following information): Works:

Doesn't work:

Additional Information

If you pass the FileManagerTool a LocalFileManagerDriver and give it a workdir of None, it will work on Mac:

from griptape.drivers import LocalFileManagerDriver

file_tool = FileManagerTool(file_manager_driver = LocalFileManagerDriver(workdir=None)