跳转到主要内容

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