Gmail 集成
让你的代理通过 Gmail 管理电子邮件、联系人和草稿。借助 AI 驱动的自动化,发送邮件、搜索消息、管理联系人、创建草稿,并简化你的邮件沟通流程。
在使用 Gmail 集成前,请确保你已经具备:
- 一个拥有有效订阅的 CrewAI AMP 账号
- 一个具有相应权限的 Gmail 账号
- 已通过 集成页面 连接你的 Gmail 账号
配置 Gmail 集成
Section titled “配置 Gmail 集成”1. 连接你的 Gmail 账号
Section titled “1. 连接你的 Gmail 账号”- 进入 CrewAI AMP Integrations
- 在身份验证集成部分找到 Gmail
- 点击 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_tokengmail/fetch_emails
描述: 获取一组消息。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")q(string, optional): 用于筛选消息的搜索查询(例如:'from:[email protected] is:unread')。maxResults(integer, optional): 要返回的最大消息数(1-500)。(默认:100)pageToken(string, optional): 用于检索特定结果页的页令牌。labelIds(array, optional): 仅返回带有与所指定标签 ID 全部匹配的标签的消息。includeSpamTrash(boolean, optional): 在结果中包含来自 SPAM 和 TRASH 的消息。(默认:false)
gmail/send_email
描述: 发送电子邮件。
参数:
to(string, required): 收件人电子邮件地址。subject(string, required): 邮件主题。body(string, required): 邮件正文内容。userId(string, optional): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")cc(string, optional): 抄送电子邮件地址(逗号分隔)。bcc(string, optional): 密送电子邮件地址(逗号分隔)。from(string, optional): 发件人电子邮件地址(如果与已认证用户不同)。replyTo(string, optional): 回复地址。threadId(string, optional): 如果是在回复现有对话,则为线程 ID。
gmail/delete_email
描述: 通过 ID 删除电子邮件。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。id(string, required): 要删除的消息 ID。
gmail/create_draft
描述: 创建一封新的草稿邮件。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。message(object, required): 包含草稿内容的消息对象。raw(string, required): 经过 Base64url 编码的邮件消息。
gmail/get_message
描述: 通过 ID 获取特定消息。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")id(string, required): 要获取的消息 ID。format(string, optional): 返回消息的格式。可选项:"full","metadata","minimal","raw"。(默认:"full")metadataHeaders(array, optional): 当提供且 format 为 METADATA 时,仅包含指定的标头。
gmail/get_attachment
描述: 获取消息附件。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")messageId(string, required): 包含该附件的消息 ID。id(string, required): 要获取的附件 ID。
gmail/fetch_thread
描述: 通过 ID 获取特定电子邮件线程。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")id(string, required): 要获取的线程 ID。format(string, optional): 返回消息的格式。可选项:"full","metadata","minimal"。(默认:"full")metadataHeaders(array, optional): 当提供且 format 为 METADATA 时,仅包含指定的标头。
gmail/modify_thread
描述: 修改应用于线程的标签。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")id(string, required): 要修改的线程 ID。addLabelIds(array, optional): 要添加到该线程的标签 ID 列表。removeLabelIds(array, optional): 要从该线程移除的标签 ID 列表。
gmail/trash_thread
描述: 将线程移至垃圾箱。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")id(string, required): 要移至垃圾箱的线程 ID。
gmail/untrash_thread
描述: 将线程从垃圾箱中移除。
参数:
userId(string, required): 用户的电子邮件地址,或对已认证用户使用'me'。(默认:"me")id(string, required): 要从垃圾箱恢复的线程 ID。
基础 Gmail 代理设置
Section titled “基础 Gmail 代理设置”from crewai import Agent, Task, Crew
# Create an agent with Gmail capabilitiesgmail_agent = Agent( role="Email Manager", goal="Manage email communications and messages efficiently", backstory="An AI assistant specialized in email management and communication.", apps=['gmail'] # All Gmail actions will be available)
# Task to send a follow-up emailsend_email_task = Task( agent=gmail_agent, expected_output="Email sent successfully with confirmation")
# Run the taskcrew = Crew( agents=[gmail_agent], tasks=[send_email_task])
crew.kickoff()筛选特定 Gmail 工具
Section titled “筛选特定 Gmail 工具”from crewai import Agent, Task, Crew
# Create agent with specific Gmail actions onlyemail_coordinator = Agent( role="Email Coordinator", goal="Coordinate email communications and manage drafts", backstory="An AI assistant that focuses on email coordination and draft management.", apps=[ 'gmail/send_email', 'gmail/fetch_emails', 'gmail/create_draft' ])
# Task to prepare and send emailsemail_coordination = Task( description="Search for emails from the marketing team, create a summary draft, and send it to stakeholders", agent=email_coordinator, expected_output="Summary email sent to stakeholders")
crew = Crew( agents=[email_coordinator], tasks=[email_coordination])
crew.kickoff()电子邮件搜索与分析
Section titled “电子邮件搜索与分析”from crewai import Agent, Task, Crew
# Create agent with Gmail search and analysis capabilitiesemail_analyst = Agent( role="Email Analyst", goal="Analyze email patterns and provide insights", backstory="An AI assistant that analyzes email data to provide actionable insights.", apps=['gmail/fetch_emails', 'gmail/get_message'] # Specific actions for email analysis)
# Task to analyze email patternsanalysis_task = Task( description=""" Search for all unread emails from the last 7 days, categorize them by sender domain, and create a summary report of communication patterns """, agent=email_analyst, expected_output="Email analysis report with communication patterns and recommendations")
crew = Crew( agents=[email_analyst], tasks=[analysis_task])
crew.kickoff()from crewai import Agent, Task, Crew
# Create agent with Gmail thread management capabilitiesthread_manager = Agent( role="Thread Manager", goal="Organize and manage email threads efficiently", backstory="An AI assistant that specializes in email thread organization and management.", apps=[ 'gmail/fetch_thread', 'gmail/modify_thread', 'gmail/trash_thread' ])
# Task to organize email threadsthread_task = Task( description=""" 1. Fetch all threads from the last month 2. Apply appropriate labels to organize threads by project 3. Archive or trash threads that are no longer relevant """, agent=thread_manager, expected_output="Email threads organized with appropriate labels and cleanup completed")
crew = Crew( agents=[thread_manager], tasks=[thread_task])
crew.kickoff()需要帮助?
如需 Gmail 集成设置或故障排查方面的帮助,请联系我们的支持团队。