Gmail工具包#

class langchain_community.agent_toolkits.gmail.toolkit.GmailToolkit[源代码]#

基础类:BaseToolkit

用于与Gmail交互的工具包。

Security Note: This toolkit contains tools that can read and modify

服务状态;例如,通过读取、创建、更新、删除与此服务相关的数据。

例如,这个工具包可以用来代表关联账户发送电子邮件。

查看 https://python.langchain.com/docs/security 获取更多信息。

Setup:

您需要一个Google的credentials.json文件来使用这个工具包。 请参阅这里的说明:https://python.langchain.com/docs/integrations/tools/gmail/#setup

Key init args:

api_resource: 可选的。Google API 资源。默认值为 None。

Instantiate:
from langchain_google_community import GmailToolkit

toolkit = GmailToolkit()
Tools:
toolkit.get_tools()
[GmailCreateDraft(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),
GmailSendMessage(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),
GmailSearch(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),
GmailGetMessage(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),
GmailGetThread(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>)]
Use within an agent:
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

llm = ChatOpenAI(model="gpt-4o-mini")

agent_executor = create_react_agent(llm, tools)

example_query = "Draft an email to fake@fake.com thanking them for coffee."

events = agent_executor.stream(
    {"messages": [("user", example_query)]},
    stream_mode="values",
)
for event in events:
    event["messages"][-1].pretty_print()
 ================================[1m Human Message [0m=================================

Draft an email to fake@fake.com thanking them for coffee.
==================================[1m Ai Message [0m==================================
Tool Calls:
create_gmail_draft (call_slGkYKZKA6h3Mf1CraUBzs6M)
Call ID: call_slGkYKZKA6h3Mf1CraUBzs6M
Args:
    message: Dear Fake,

I wanted to take a moment to thank you for the coffee yesterday. It was a pleasure catching up with you. Let's do it again soon!

Best regards,
[Your Name]
    to: ['fake@fake.com']
    subject: Thank You for the Coffee
=================================[1m Tool Message [0m=================================
Name: create_gmail_draft

Draft created. Draft Id: r-7233782721440261513
==================================[1m Ai Message [0m==================================

I have drafted an email to fake@fake.com thanking them for the coffee. You can review and send it from your email draft with the subject "Thank You for the Coffee".
Parameters:

api_resource – 可选。Google API 资源。默认值为 None。

通过解析和验证来自关键字参数的输入数据来创建一个新模型。

如果输入数据无法验证以形成有效模型,则引发 [ValidationError][pydantic_core.ValidationError]。

self 被显式地设为仅位置参数,以允许 self 作为字段名称。

param api_resource: Resource [Optional]#
get_tools() List[BaseTool][来源]#

获取工具包中的工具。

Return type:

列表[BaseTool]