Google Drive 集成
让你的代理通过 Google Drive 管理文件和文件夹。上传、下载、整理和共享文件,创建文件夹,并借助 AI 驱动的自动化简化文档管理工作流。
在使用 Google Drive 集成前,请确保你已经具备:
- 一个拥有有效订阅的 CrewAI AMP 账号
- 一个可访问 Google Drive 的 Google 账号
- 已通过 集成页面 连接你的 Google 账号
配置 Google Drive 集成
Section titled “配置 Google Drive 集成”1. 连接你的 Google 账号
Section titled “1. 连接你的 Google 账号”- 进入 CrewAI AMP Integrations
- 在身份验证集成部分找到 Google Drive
- 点击 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_tokengoogle_drive/get_file
描述: 通过 ID 从 Google Drive 获取文件。
参数:
file_id(string, required): 要检索的文件 ID。
google_drive/list_files
描述: 列出 Google Drive 中的文件。
参数:
q(string, optional): 用于筛选文件的查询字符串(示例:"name contains 'report'")。page_size(integer, optional): 要返回的文件最大数量(默认:100,最大:1000)。page_token(string, optional): 用于检索下一页结果的令牌。order_by(string, optional): 排序方式(示例:"name","createdTime desc","modifiedTime")。spaces(string, optional): 要查询的空间的逗号分隔列表(drive, appDataFolder, photos)。
google_drive/upload_file
描述: 将文件上传到 Google Drive。
参数:
name(string, required): 要创建的文件名称。content(string, required): 要上传的文件内容。mime_type(string, optional): 文件的 MIME 类型(示例:"text/plain","application/pdf")。parent_folder_id(string, optional): 应创建文件的父文件夹 ID。description(string, optional): 文件描述。
google_drive/download_file
描述: 从 Google Drive 下载文件。
参数:
file_id(string, required): 要下载的文件 ID。mime_type(string, optional): 导出所用的 MIME 类型(Google Workspace 文档必需)。
google_drive/create_folder
描述: 在 Google Drive 中创建新文件夹。
参数:
name(string, required): 要创建的文件夹名称。parent_folder_id(string, optional): 应创建新文件夹的父文件夹 ID。description(string, optional): 文件夹描述。
google_drive/delete_file
描述: 从 Google Drive 删除文件。
参数:
file_id(string, required): 要删除的文件 ID。
google_drive/share_file
描述: 与特定用户共享 Google Drive 文件,或将其设为公开。
参数:
file_id(string, required): 要共享的文件 ID。role(string, required): 该权限授予的角色(reader, writer, commenter, owner)。type(string, required): 被授权对象的类型(user, group, domain, anyone)。email_address(string, optional): 要共享的用户或群组的电子邮件地址(user/group 类型必需)。domain(string, optional): 要共享的域名(domain 类型必需)。send_notification_email(boolean, optional): 是否发送通知邮件(默认:true)。email_message(string, optional): 将包含在通知邮件中的纯文本自定义消息。
google_drive/update_file
描述: 更新 Google Drive 中的现有文件。
参数:
file_id(string, required): 要更新的文件 ID。name(string, optional): 文件的新名称。content(string, optional): 文件的新内容。mime_type(string, optional): 文件的新 MIME 类型。description(string, optional): 文件的新描述。add_parents(string, optional): 要添加的父文件夹 ID 的逗号分隔列表。remove_parents(string, optional): 要移除的父文件夹 ID 的逗号分隔列表。
基础 Google Drive 代理设置
Section titled “基础 Google Drive 代理设置”from crewai import Agent, Task, Crew
# Create an agent with Google Drive capabilitiesdrive_agent = Agent( role="File Manager", goal="Manage files and folders in Google Drive efficiently", backstory="An AI assistant specialized in document and file management.", apps=['google_drive'] # All Google Drive actions will be available)
# Task to organize filesorganize_files_task = Task( description="List all files in the root directory and organize them into appropriate folders", agent=drive_agent, expected_output="Summary of files organized with folder structure")
# Run the taskcrew = Crew( agents=[drive_agent], tasks=[organize_files_task])
crew.kickoff()筛选特定 Google Drive 工具
Section titled “筛选特定 Google Drive 工具”from crewai import Agent, Task, Crew
# Create agent with specific Google Drive actions onlyfile_manager_agent = Agent( role="Document Manager", goal="Upload and manage documents efficiently", backstory="An AI assistant that focuses on document upload and organization.", apps=[ 'google_drive/upload_file', 'google_drive/create_folder', 'google_drive/share_file' ] # Specific Google Drive actions)
# Task to upload and share documentsdocument_task = Task( description="Upload the quarterly report and share it with the finance team", agent=file_manager_agent, expected_output="Document uploaded and sharing permissions configured")
crew = Crew( agents=[file_manager_agent], tasks=[document_task])
crew.kickoff()高级文件管理
Section titled “高级文件管理”from crewai import Agent, Task, Crew
file_organizer = Agent( role="File Organizer", goal="Maintain organized file structure and manage permissions", backstory="An experienced file manager who ensures proper organization and access control.", apps=['google_drive'])
# Complex task involving multiple Google Drive operationsorganization_task = Task( description=""" 1. List all files in the shared folder 2. Create folders for different document types (Reports, Presentations, Spreadsheets) 3. Move files to appropriate folders based on their type 4. Set appropriate sharing permissions for each folder 5. Create a summary document of the organization changes """, agent=file_organizer, expected_output="Files organized into categorized folders with proper permissions and summary report")
crew = Crew( agents=[file_organizer], tasks=[organization_task])
crew.kickoff()