Gmail 允许 Agent 与 Gmail 进行交互,从而读取、搜索、发送和管理电子邮件。

前提条件

Gmail 工具包需要 Google API 客户端库和正确的身份验证设置。安装所需的依赖项:

pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib

您还需要设置 Google Cloud 凭据:

  1. 前往 Google Cloud Console
  2. 创建一个项目或选择一个现有项目
  3. 启用 Gmail API
  4. 创建 OAuth 2.0 凭据
  5. 设置环境变量:
export GOOGLE_CLIENT_ID=your_client_id_here
export GOOGLE_CLIENT_SECRET=your_client_secret_here
export GOOGLE_PROJECT_ID=your_project_id_here
export GOOGLE_REDIRECT_URI=http://localhost  # 默认值

示例

cookbook/tools/gmail_tools.py
from agno.agent import Agent
from agno.tools.gmail import GmailTools

agent = Agent(tools=[GmailTools()], show_tool_calls=True)
agent.print_response("Show me my latest 5 unread emails", markdown=True)

工具包参数

参数类型默认值描述
get_latest_emailsboolTrue启用从收件箱检索最新电子邮件
get_emails_from_userboolTrue启用从特定发件人获取电子邮件
get_unread_emailsboolTrue启用获取未读电子邮件
get_starred_emailsboolTrue启用检索已加星标的电子邮件
get_emails_by_contextboolTrue启用通过上下文搜索电子邮件
get_emails_by_dateboolTrue启用在日期范围内检索电子邮件
create_draft_emailboolTrue启用创建电子邮件草稿
send_emailboolTrue启用立即发送电子邮件
search_emailsboolTrue启用搜索电子邮件

工具包函数

函数描述
get_latest_emails从用户收件箱获取最新的 X 封邮件
get_emails_from_user从特定发件人获取 X 封邮件
get_unread_emails获取最新的 X 封未读邮件
get_starred_emails获取 X 封已加星标的邮件
get_emails_by_context获取匹配特定上下文的 X 封邮件
get_emails_by_date在特定日期范围内获取邮件
create_draft_email创建并保存电子邮件草稿
send_email立即发送电子邮件
search_emails使用自然语言查询搜索电子邮件

开发者资源