主题
目录读取
DirectoryReadTool是一个强大的实用工具,旨在提供目录内容的全面列表。
DirectoryReadTool
NOTE
我们仍在改进这些工具,因此未来可能会出现意外行为或变更。
描述
DirectoryReadTool 是一个强大的实用工具,旨在提供目录内容的全面列表。 它可以递归遍历指定目录,为用户详细枚举所有文件,包括子目录中的文件。 对于需要全面清点目录结构或验证目录内文件组织情况的任务,此工具至关重要。
安装
要在项目中使用 DirectoryReadTool,请安装 crewai_tools 包。如果你的环境中尚未包含此包,可以使用 pip 通过以下命令安装:
shell
pip install 'crewai[tools]'此命令会安装 crewai_tools 包的最新版本,从而可以访问 DirectoryReadTool 及其他实用工具。
示例
使用 DirectoryReadTool 很简单。以下代码片段演示如何设置该工具,并使用它列出指定目录的内容:
python
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 | string | 可选。指定要列出其内容的目录路径的参数。它接受绝对路径和相对路径,引导工具前往目标目录以列出内容。 |