跳转到主要内容

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 的行为:
参数类型描述
目录字符串可选。一个参数,用于指定您希望列出其内容的目录路径。它接受绝对路径和相对路径,引导工具到所需目录进行内容列表。