DirectoryReadTool

我们仍在努力改进工具,未来可能会有意外行为或变化。

描述

DirectoryReadTool 是一个强大的工具,旨在提供目录内容的全面列表。它可以递归遍历指定的目录,为用户详细列举所有文件,包括子目录中的文件。此工具对于需要全面清点目录结构或验证目录中文件组织的任务至关重要。

安装

要在您的项目中使用 DirectoryReadTool,请安装 crewai_tools 包。如果您的环境中尚未包含此包,可以使用以下命令通过 pip 进行安装

pip install 'crewai[tools]'

此命令将安装 crewai_tools 包的最新版本,从而可以使用 DirectoryReadTool 及其他工具。

示例

使用 DirectoryReadTool 非常简单。以下代码片段演示了如何设置并使用该工具来列出指定目录的内容

代码
from crewai_tools import DirectoryReadTool

# Initialize the tool so the agent can read any directory's content 
# it learns about during execution
tool = DirectoryReadTool()

# OR

# Initialize the tool with a specific directory, 
# so the agent can only read the content of the specified directory
tool = DirectoryReadTool(directory='/path/to/your/directory')

参数

可以使用以下参数自定义 DirectoryReadTool 的行为

参数类型描述
directory字符串可选。一个参数,用于指定您希望列出内容的目录路径。它接受绝对路径和相对路径,引导工具找到所需目录以列出内容。