Microsoft OneDrive 集成
让你的智能体在 Microsoft OneDrive 中上传、下载和管理文件与文件夹。借助 AI 自动化,你可以自动执行文件操作、组织内容、创建共享链接,并简化云存储工作流。
在使用 Microsoft OneDrive 集成之前,请确保你已具备:
- 一个拥有有效订阅的 CrewAI AMP 账户
- 一个拥有 OneDrive 访问权限的 Microsoft 账户
- 通过 集成页面 连接了你的 Microsoft 账户
设置 Microsoft OneDrive 集成
Section titled “设置 Microsoft OneDrive 集成”1. 连接你的 Microsoft 账户
Section titled “1. 连接你的 Microsoft 账户”- 访问 CrewAI AMP Integrations
- 在 Authentication Integrations 部分找到 Microsoft OneDrive
- 点击 Connect 并完成 OAuth 流程
- 授予文件访问所需权限
- 从 Integration Settings 复制你的 Enterprise Token
2. 安装所需包
Section titled “2. 安装所需包”uv add crewai-tools3. 环境变量设置
Section titled “3. 环境变量设置”export CREWAI_PLATFORM_INTEGRATION_TOKEN="your_enterprise_token"或者将其添加到你的 .env 文件中:
CREWAI_PLATFORM_INTEGRATION_TOKEN=your_enterprise_tokenmicrosoft_onedrive/list_files
说明: 列出 OneDrive 中的文件和文件夹。
参数:
top(integer, optional): 要检索的项目数(最大 1000)。默认值为50。orderby(string, optional): 排序字段(例如:name asc、lastModifiedDateTime desc)。默认值为name asc。filter(string, optional): OData 过滤表达式。
microsoft_onedrive/get_file_info
说明: 获取某个特定文件或文件夹的信息。
参数:
item_id(string, required): 文件或文件夹的 ID。
microsoft_onedrive/download_file
说明: 从 OneDrive 下载文件。
参数:
item_id(string, required): 要下载的文件 ID。
microsoft_onedrive/upload_file
说明: 向 OneDrive 上传文件。
参数:
file_name(string, required): 要上传的文件名。content(string, required): 经过 Base64 编码的文件内容。
microsoft_onedrive/create_folder
说明: 在 OneDrive 中创建一个新文件夹。
参数:
folder_name(string, required): 要创建的文件夹名称。
microsoft_onedrive/delete_item
说明: 从 OneDrive 删除文件或文件夹。
参数:
item_id(string, required): 要删除的文件或文件夹的 ID。
microsoft_onedrive/copy_item
说明: 在 OneDrive 中复制文件或文件夹。
参数:
item_id(string, required): 要复制的文件或文件夹的 ID。parent_id(string, optional): 目标文件夹的 ID(可选,默认是根目录)。new_name(string, optional): 复制项目的新名称(可选)。
microsoft_onedrive/move_item
说明: 在 OneDrive 中移动文件或文件夹。
参数:
item_id(string, required): 要移动的文件或文件夹的 ID。parent_id(string, required): 目标文件夹的 ID。new_name(string, optional): 项目的新名称(可选)。
microsoft_onedrive/search_files
说明: 在 OneDrive 中搜索文件和文件夹。
参数:
query(string, required): 搜索查询字符串。top(integer, optional): 要返回的结果数(最大 1000)。默认值为50。
microsoft_onedrive/share_item
说明: 为文件或文件夹创建共享链接。
参数:
item_id(string, required): 要共享的文件或文件夹的 ID。type(string, optional): 共享链接类型。枚举值:view、edit、embed。默认值为view。scope(string, optional): 共享链接范围。枚举值:anonymous、organization。默认值为anonymous。
microsoft_onedrive/get_thumbnails
说明: 获取文件缩略图。
参数:
item_id(string, required): 文件的 ID。
microsoft_onedrive/list_files_by_path
说明: 列出 OneDrive 指定路径中的文件和文件夹。
参数:
folder_path(string, required): 文件夹路径(例如:Documents/Reports)。top(integer, optional): 要检索的项目数(最大 1000)。默认值为50。orderby(string, optional): 排序字段(例如:name asc、lastModifiedDateTime desc)。默认值为name asc。
microsoft_onedrive/get_recent_files
说明: 获取 OneDrive 中最近访问的文件。
参数:
top(integer, optional): 要检索的项目数(最大 200)。默认值为25。
microsoft_onedrive/get_shared_with_me
说明: 获取与当前用户共享的文件和文件夹。
参数:
top(integer, optional): 要检索的项目数(最大 200)。默认值为50。orderby(string, optional): 排序字段。默认值为name asc。
microsoft_onedrive/get_file_by_path
说明: 通过路径获取某个特定文件或文件夹的信息。
参数:
file_path(string, required): 文件或文件夹路径(例如:Documents/report.docx)。
microsoft_onedrive/download_file_by_path
说明: 按路径从 OneDrive 下载文件。
参数:
file_path(string, required): 文件路径(例如:Documents/report.docx)。
OneDrive 基础智能体设置
Section titled “OneDrive 基础智能体设置”from crewai import Agent, Task, Crew
# 创建一个具备 Microsoft OneDrive 能力的智能体onedrive_agent = Agent( role="文件管理员", goal="高效管理 OneDrive 中的文件和文件夹", backstory="一位专门处理 Microsoft OneDrive 文件操作与整理的 AI 助手。", apps=['microsoft_onedrive'] # 将可用所有 OneDrive 操作)
# 列出文件并创建文件夹的任务organize_files_task = Task( description="列出我 OneDrive 根目录中的所有文件,并创建一个名为 'Project Documents' 的新文件夹。", agent=onedrive_agent, expected_output="文件列表已显示,并已创建新文件夹 'Project Documents'。")
# 运行任务crew = Crew( agents=[onedrive_agent], tasks=[organize_files_task])
crew.kickoff()文件上传与管理
Section titled “文件上传与管理”from crewai import Agent, Task, Crew
# 创建一个专注于文件操作的智能体file_operator = Agent( role="文件操作员", goal="精确上传、下载和管理文件", backstory="一位擅长文件处理和内容管理的 AI 助手。", apps=['microsoft_onedrive/upload_file', 'microsoft_onedrive/download_file', 'microsoft_onedrive/get_file_info'])
# 上传并管理文件的任务file_management_task = Task( description="上传一个名为 'report.txt' 的文本文件,内容为 'This is a sample report for the project.',然后获取已上传文件的信息。", agent=file_operator, expected_output="文件已成功上传,并已检索文件信息。")
crew = Crew( agents=[file_operator], tasks=[file_management_task])
crew.kickoff()