Skip to content

Commit acba38a

Browse files
authored
docs: update toolkit guides (#24992)
1 parent 22c1a40 commit acba38a

File tree

2 files changed

+96
-229
lines changed

2 files changed

+96
-229
lines changed

docs/docs/integrations/toolkits/gmail.ipynb

Lines changed: 65 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,22 @@
122122
},
123123
{
124124
"cell_type": "code",
125-
"execution_count": 5,
125+
"execution_count": 2,
126126
"metadata": {
127127
"tags": []
128128
},
129129
"outputs": [
130130
{
131131
"data": {
132132
"text/plain": [
133-
"[GmailCreateDraft(name='create_gmail_draft', description='Use this tool to create a draft email with the provided message fields.', args_schema=<class 'langchain_community.tools.gmail.create_draft.CreateDraftSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, api_resource=<googleapiclient.discovery.Resource object at 0x10e5c6d10>),\n",
134-
" GmailSendMessage(name='send_gmail_message', description='Use this tool to send email messages. The input is the message, recipents', args_schema=None, return_direct=False, verbose=False, callbacks=None, callback_manager=None, api_resource=<googleapiclient.discovery.Resource object at 0x10e5c6d10>),\n",
135-
" GmailSearch(name='search_gmail', description=('Use this tool to search for email messages or threads. The input must be a valid Gmail query. The output is a JSON list of the requested resource.',), args_schema=<class 'langchain_community.tools.gmail.search.SearchArgsSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, api_resource=<googleapiclient.discovery.Resource object at 0x10e5c6d10>),\n",
136-
" GmailGetMessage(name='get_gmail_message', description='Use this tool to fetch an email by message ID. Returns the thread ID, snipet, body, subject, and sender.', args_schema=<class 'langchain_community.tools.gmail.get_message.SearchArgsSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, api_resource=<googleapiclient.discovery.Resource object at 0x10e5c6d10>),\n",
137-
" GmailGetThread(name='get_gmail_thread', description=('Use this tool to search for email messages. The input must be a valid Gmail query. The output is a JSON list of messages.',), args_schema=<class 'langchain_community.tools.gmail.get_thread.GetThreadSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, api_resource=<googleapiclient.discovery.Resource object at 0x10e5c6d10>)]"
133+
"[GmailCreateDraft(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),\n",
134+
" GmailSendMessage(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),\n",
135+
" GmailSearch(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),\n",
136+
" GmailGetMessage(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>),\n",
137+
" GmailGetThread(api_resource=<googleapiclient.discovery.Resource object at 0x1094509d0>)]"
138138
]
139139
},
140-
"execution_count": 5,
140+
"execution_count": 2,
141141
"metadata": {},
142142
"output_type": "execute_result"
143143
}
@@ -164,142 +164,96 @@
164164
"source": [
165165
"## Use within an agent\n",
166166
"\n",
167-
"We show here how to use it as part of an [agent](/docs/tutorials/agents). We use the OpenAI Functions Agent, so we will need to setup and install the required dependencies for that. We will also use [LangSmith Hub](https://smith.langchain.com/hub) to pull the prompt from, so we will need to install that.\n",
167+
"Below we show how to incorporate the toolkit into an [agent](/docs/tutorials/agents).\n",
168+
"\n",
169+
"We will need a LLM or chat model:\n",
168170
"\n",
169-
"```bash\n",
170-
"pip install -U langchain-openai langchainhub\n",
171+
"```{=mdx}\n",
172+
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
173+
"\n",
174+
"<ChatModelTabs customVarName=\"llm\" />\n",
171175
"```"
172176
]
173177
},
174178
{
175179
"cell_type": "code",
176-
"execution_count": null,
180+
"execution_count": 3,
177181
"metadata": {},
178182
"outputs": [],
179183
"source": [
180-
"import getpass\n",
181-
"import os\n",
184+
"# | output: false\n",
185+
"# | echo: false\n",
182186
"\n",
183-
"os.environ[\"OPENAI_API_KEY\"] = getpass.getpass()"
184-
]
185-
},
186-
{
187-
"cell_type": "code",
188-
"execution_count": 1,
189-
"metadata": {
190-
"tags": []
191-
},
192-
"outputs": [],
193-
"source": [
194-
"from langchain import hub\n",
195-
"from langchain.agents import AgentExecutor, create_openai_functions_agent\n",
196-
"from langchain_openai import ChatOpenAI"
197-
]
198-
},
199-
{
200-
"cell_type": "code",
201-
"execution_count": 2,
202-
"metadata": {},
203-
"outputs": [],
204-
"source": [
205-
"instructions = \"\"\"You are an assistant.\"\"\"\n",
206-
"base_prompt = hub.pull(\"langchain-ai/openai-functions-template\")\n",
207-
"prompt = base_prompt.partial(instructions=instructions)"
208-
]
209-
},
210-
{
211-
"cell_type": "code",
212-
"execution_count": 9,
213-
"metadata": {},
214-
"outputs": [],
215-
"source": [
216-
"llm = ChatOpenAI(temperature=0)"
187+
"from langchain_openai import ChatOpenAI\n",
188+
"\n",
189+
"llm = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", temperature=0)"
217190
]
218191
},
219192
{
220193
"cell_type": "code",
221-
"execution_count": 10,
194+
"execution_count": 4,
222195
"metadata": {},
223196
"outputs": [],
224197
"source": [
225-
"agent = create_openai_functions_agent(llm, toolkit.get_tools(), prompt)"
198+
"from langgraph.prebuilt import create_react_agent\n",
199+
"\n",
200+
"agent_executor = create_react_agent(llm, tools)"
226201
]
227202
},
228203
{
229204
"cell_type": "code",
230-
"execution_count": 18,
205+
"execution_count": 5,
231206
"metadata": {},
232-
"outputs": [],
233-
"source": [
234-
"agent_executor = AgentExecutor(\n",
235-
" agent=agent,\n",
236-
" tools=toolkit.get_tools(),\n",
237-
" # This is set to False to prevent information about my email showing up on the screen\n",
238-
" # Normally, it is helpful to have it set to True however.\n",
239-
" verbose=False,\n",
240-
")"
241-
]
242-
},
243-
{
244-
"cell_type": "code",
245-
"execution_count": 19,
246-
"metadata": {
247-
"tags": []
248-
},
249207
"outputs": [
250208
{
251-
"data": {
252-
"text/plain": [
253-
"{'input': 'Create a gmail draft for me to edit of a letter from the perspective of a sentient parrot who is looking to collaborate on some research with her estranged friend, a cat. Under no circumstances may you send the message, however.',\n",
254-
" 'output': 'I have created a draft email for you to edit. Please find the draft in your Gmail drafts folder. Remember, under no circumstances should you send the message.'}"
255-
]
256-
},
257-
"execution_count": 19,
258-
"metadata": {},
259-
"output_type": "execute_result"
209+
"name": "stdout",
210+
"output_type": "stream",
211+
"text": [
212+
"================================\u001b[1m Human Message \u001b[0m=================================\n",
213+
"\n",
214+
"Draft an email to fake@fake.com thanking them for coffee.\n",
215+
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
216+
"Tool Calls:\n",
217+
" create_gmail_draft (call_slGkYKZKA6h3Mf1CraUBzs6M)\n",
218+
" Call ID: call_slGkYKZKA6h3Mf1CraUBzs6M\n",
219+
" Args:\n",
220+
" message: Dear Fake,\n",
221+
"\n",
222+
"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!\n",
223+
"\n",
224+
"Best regards,\n",
225+
"[Your Name]\n",
226+
" to: ['fake@fake.com']\n",
227+
" subject: Thank You for the Coffee\n",
228+
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
229+
"Name: create_gmail_draft\n",
230+
"\n",
231+
"Draft created. Draft Id: r-7233782721440261513\n",
232+
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
233+
"\n",
234+
"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\".\n"
235+
]
260236
}
261237
],
262238
"source": [
263-
"agent_executor.invoke(\n",
264-
" {\n",
265-
" \"input\": \"Create a gmail draft for me to edit of a letter from the perspective of a sentient parrot\"\n",
266-
" \" who is looking to collaborate on some research with her\"\n",
267-
" \" estranged friend, a cat. Under no circumstances may you send the message, however.\"\n",
268-
" }\n",
269-
")"
239+
"example_query = \"Draft an email to fake@fake.com thanking them for coffee.\"\n",
240+
"\n",
241+
"events = agent_executor.stream(\n",
242+
" {\"messages\": [(\"user\", example_query)]},\n",
243+
" stream_mode=\"values\",\n",
244+
")\n",
245+
"for event in events:\n",
246+
" event[\"messages\"][-1].pretty_print()"
270247
]
271248
},
272249
{
273-
"cell_type": "code",
274-
"execution_count": 20,
275-
"metadata": {
276-
"tags": []
277-
},
278-
"outputs": [
279-
{
280-
"data": {
281-
"text/plain": [
282-
"{'input': 'Could you search in my drafts for the latest email? what is the title?',\n",
283-
" 'output': 'The latest email in your drafts is titled \"Collaborative Research Proposal\".'}"
284-
]
285-
},
286-
"execution_count": 20,
287-
"metadata": {},
288-
"output_type": "execute_result"
289-
}
290-
],
250+
"cell_type": "markdown",
251+
"metadata": {},
291252
"source": [
292-
"agent_executor.invoke(\n",
293-
" {\"input\": \"Could you search in my drafts for the latest email? what is the title?\"}\n",
294-
")"
253+
"## API reference\n",
254+
"\n",
255+
"For detailed documentation of all `GmailToolkit` features and configurations head to the [API reference](https://api.python.langchain.com/en/latest/agent_toolkits/langchain_community.agent_toolkits.slack.toolkit.SlackToolkit.html)."
295256
]
296-
},
297-
{
298-
"cell_type": "code",
299-
"execution_count": null,
300-
"metadata": {},
301-
"outputs": [],
302-
"source": []
303257
}
304258
],
305259
"metadata": {

0 commit comments

Comments
 (0)