DirectoryReadTool

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

描述

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

安装

要在您的项目中使用DirectoryReadTool,请安装crewai_tools包。如果此包尚未成为您环境的一部分,您可以使用以下pip命令进行安装:

pip install 'crewai[tools]'

此命令安装最新版本的crewai_tools包,提供对DirectoryReadTool及其他实用工具的访问权限。

示例

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

Code
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的行为:

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

这个页面有帮助吗?