"Running the graph until the first interrupt...\n",
"{'agent': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_5kiEF7KNC5d2uzF5vWxJZJJM', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow\\'s Meeting\",\"content\":\"Dear [Boss\\'s Name],\\\\n\\\\nThank you for the reminder about tomorrow\\'s meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\\\n\\\\nBest regards,\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 91, 'prompt_tokens': 75, 'total_tokens': 166, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZixGJrtdvoltumannmwngZr1ohFj', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--8b3a1554-65f8-4e7a-9cad-f05d44422856-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting\", 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards,\\n[Your Name]\"}, 'id': 'call_5kiEF7KNC5d2uzF5vWxJZJJM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 75, 'output_tokens': 91, 'total_tokens': 166, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"\n",
"INTERRUPT OBJECT:\n",
"Action Request: {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting\", 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards,\\n[Your Name]\"}}\n"
]
}
],
"source": [
"msg = [{\"role\": \"user\", \"content\": \"Draft an email response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference\"}]\n",
"Simulating user accepting the {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting\", 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards,\\n[Your Name]\"}} tool call...\n",
"{'post_model_hook': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_5kiEF7KNC5d2uzF5vWxJZJJM', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow\\'s Meeting\",\"content\":\"Dear [Boss\\'s Name],\\\\n\\\\nThank you for the reminder about tomorrow\\'s meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\\\n\\\\nBest regards,\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 91, 'prompt_tokens': 75, 'total_tokens': 166, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZixGJrtdvoltumannmwngZr1ohFj', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--8b3a1554-65f8-4e7a-9cad-f05d44422856-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting\", 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards,\\n[Your Name]\"}, 'id': 'call_5kiEF7KNC5d2uzF5vWxJZJJM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 75, 'output_tokens': 91, 'total_tokens': 166, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'tools': {'messages': [ToolMessage(content=\"Email sent to boss@company.ai with subject 'Re: Tomorrow's Meeting' and content: Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards,\\n[Your Name]\", name='write_email', id='5e704cf6-087c-46c3-a56d-25d8b76eceaf', tool_call_id='call_5kiEF7KNC5d2uzF5vWxJZJJM')]}}\n",
"{'agent': {'messages': [AIMessage(content=\"Here's a draft for your response:\\n\\nSubject: Re: Tomorrow's Meeting\\n\\nDear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards, \\n[Your Name]\\n\\nLet me know if you'd like to personalize or adjust this message further!\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 88, 'prompt_tokens': 250, 'total_tokens': 338, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZixKstGdPPIiiJo7gmBRv8gfatkF', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--39edb4bc-e81f-47f8-abdf-d0b2f31c2be1-0', usage_metadata={'input_tokens': 250, 'output_tokens': 88, 'total_tokens': 338, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'post_model_hook': {'messages': [AIMessage(content=\"Here's a draft for your response:\\n\\nSubject: Re: Tomorrow's Meeting\\n\\nDear [Boss's Name],\\n\\nThank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\\n\\nBest regards, \\n[Your Name]\\n\\nLet me know if you'd like to personalize or adjust this message further!\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 88, 'prompt_tokens': 250, 'total_tokens': 338, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZixKstGdPPIiiJo7gmBRv8gfatkF', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--39edb4bc-e81f-47f8-abdf-d0b2f31c2be1-0', usage_metadata={'input_tokens': 250, 'output_tokens': 88, 'total_tokens': 338, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n"
]
}
],
"source": [
"from langgraph.types import Command\n",
"\n",
"print(f\"\\nSimulating user accepting the {Interrupt_Object.value[0]['action_request']} tool call...\")\n",
"for chunk in agent.stream(Command(resume=[{\"type\": \"accept\"}]), config=thread_config_2):\n",
" print(chunk)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================\u001b[1m Human Message \u001b[0m=================================\n",
"\n",
"Draft a response to my boss (boss@company.ai) about tomorrow's meeting.\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" write_email (call_5kiEF7KNC5d2uzF5vWxJZJJM)\n",
" Call ID: call_5kiEF7KNC5d2uzF5vWxJZJJM\n",
" Args:\n",
" to: boss@company.ai\n",
" subject: Re: Tomorrow's Meeting\n",
" content: Dear [Boss's Name],\n",
"\n",
"Thank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\n",
"Email sent to boss@company.ai with subject 'Re: Tomorrow's Meeting' and content: Dear [Boss's Name],\n",
"\n",
"Thank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\n",
"\n",
"Best regards,\n",
"[Your Name]\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
"Here's a draft for your response:\n",
"\n",
"Subject: Re: Tomorrow's Meeting\n",
"\n",
"Dear [Boss's Name],\n",
"\n",
"Thank you for the reminder about tomorrow's meeting. I confirm my attendance and look forward to discussing the agenda items. Please let me know if there is anything specific you would like me to prepare or bring to the meeting.\n",
"\n",
"Best regards, \n",
"[Your Name]\n",
"\n",
"Let me know if you'd like to personalize or adjust this message further!\n"
]
}
],
"source": [
"state = agent.get_state(thread_config_2)\n",
"for m in state.values['messages']:\n",
" m.pretty_print()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Responding to the tool call"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running the graph until the first interrupt...\n",
"{'agent': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_IByJungo4tOleyF4lDEcBu7R', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow’s Meeting on the Interrupt Conference\",\"content\":\"Dear [Boss\\'s Name],\\\\n\\\\nThank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\\\\n\\\\nLooking forward to our discussion.\\\\n\\\\nBest regards,\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 112, 'prompt_tokens': 80, 'total_tokens': 192, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZiyEpGskLW9SAlSUSitxGWghl52E', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--4d4b1ce5-5358-4e6e-a433-07e4b413c043-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\\n\\nLooking forward to our discussion.\\n\\nBest regards,\\n[Your Name]\"}, 'id': 'call_IByJungo4tOleyF4lDEcBu7R', 'type': 'tool_call'}], usage_metadata={'input_tokens': 80, 'output_tokens': 112, 'total_tokens': 192, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"\n",
"INTERRUPT OBJECT:\n",
"Action Request: {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\\n\\nLooking forward to our discussion.\\n\\nBest regards,\\n[Your Name]\"}}\n"
]
}
],
"source": [
"# Create a new thread for testing the respond action\n",
"# Run the graph until a tool call that we choose to interrupt\n",
"msg = [{\"role\": \"user\", \"content\": \"Draft an email response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference.\"}]\n",
"print(\"Running the graph until the first interrupt...\")\n",
"for chunk in agent.stream({\"messages\": msg}, config=thread_config_3):\n",
"Simulating user responding to the tool call with feedback...\n",
"{'post_model_hook': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_IByJungo4tOleyF4lDEcBu7R', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow’s Meeting on the Interrupt Conference\",\"content\":\"Dear [Boss\\'s Name],\\\\n\\\\nThank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\\\\n\\\\nLooking forward to our discussion.\\\\n\\\\nBest regards,\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 112, 'prompt_tokens': 80, 'total_tokens': 192, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZiyEpGskLW9SAlSUSitxGWghl52E', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--4d4b1ce5-5358-4e6e-a433-07e4b413c043-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\\n\\nLooking forward to our discussion.\\n\\nBest regards,\\n[Your Name]\"}, 'id': 'call_IByJungo4tOleyF4lDEcBu7R', 'type': 'tool_call'}], usage_metadata={'input_tokens': 80, 'output_tokens': 112, 'total_tokens': 192, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}), ToolMessage(content='Shorter and less formal.', name='write_email', id='5eb49891-0d42-40ec-aa6b-a428853ee7f8', tool_call_id='call_IByJungo4tOleyF4lDEcBu7R', status='error')]}}\n",
"{'agent': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_1MensMD3ArJUJqgBXv1AQAvQ', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow’s Meeting on the Interrupt Conference\",\"content\":\"Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\\\n\\\\nThanks,\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 74, 'prompt_tokens': 206, 'total_tokens': 280, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZiybdSZYy4AdPZqlnxNuRNqMpKOP', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--e87c93af-ca42-404a-b0ea-6fbce50d99c3-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': 'Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\n\\nThanks,\\n[Your Name]'}, 'id': 'call_1MensMD3ArJUJqgBXv1AQAvQ', 'type': 'tool_call'}], usage_metadata={'input_tokens': 206, 'output_tokens': 74, 'total_tokens': 280, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'__interrupt__': (Interrupt(value=[{'action_request': {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': 'Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\n\\nThanks,\\n[Your Name]'}}, 'config': {'allow_accept': True, 'allow_edit': True, 'allow_ignore': True, 'allow_respond': True}, 'description': 'Please review tool call for `write_email` before execution.'}], resumable=True, ns=['post_model_hook:fe1a666b-0873-992f-01ba-a5ba1849aac6']),)}\n"
]
}
],
"source": [
"# Now simulate user responding to the tool call with feedback\n",
"print(\"\\nSimulating user responding to the tool call with feedback...\")\n",
"for chunk in agent.stream(Command(resume={\"type\": \"response\", \"args\": \"Shorter and less formal.\"}), config=thread_config_3):\n",
" print(chunk)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Simulating user accepting the {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': \"Dear [Boss's Name],\\n\\nThank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\\n\\nLooking forward to our discussion.\\n\\nBest regards,\\n[Your Name]\"}} tool call...\n",
"{'post_model_hook': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_1MensMD3ArJUJqgBXv1AQAvQ', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow’s Meeting on the Interrupt Conference\",\"content\":\"Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\\\n\\\\nThanks,\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 74, 'prompt_tokens': 206, 'total_tokens': 280, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZiybdSZYy4AdPZqlnxNuRNqMpKOP', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--e87c93af-ca42-404a-b0ea-6fbce50d99c3-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': 'Re: Tomorrow’s Meeting on the Interrupt Conference', 'content': 'Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\n\\nThanks,\\n[Your Name]'}, 'id': 'call_1MensMD3ArJUJqgBXv1AQAvQ', 'type': 'tool_call'}], usage_metadata={'input_tokens': 206, 'output_tokens': 74, 'total_tokens': 280, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'tools': {'messages': [ToolMessage(content=\"Email sent to boss@company.ai with subject 'Re: Tomorrow’s Meeting on the Interrupt Conference' and content: Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\n\\nThanks,\\n[Your Name]\", name='write_email', id='95919d1e-4318-47d3-bf01-d5022dbf6463', tool_call_id='call_1MensMD3ArJUJqgBXv1AQAvQ')]}}\n",
"{'agent': {'messages': [AIMessage(content=\"Here's a shorter and less formal response you can use:\\n\\nThanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\n\\nThanks,\\n[Your Name]\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 51, 'prompt_tokens': 350, 'total_tokens': 401, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZiz56f01zrr2kttIeXyHbYQ1XPRR', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--86ad576a-65a5-4575-8d76-dc3cfd5fe378-0', usage_metadata={'input_tokens': 350, 'output_tokens': 51, 'total_tokens': 401, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'post_model_hook': {'messages': [AIMessage(content=\"Here's a shorter and less formal response you can use:\\n\\nThanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\\n\\nThanks,\\n[Your Name]\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 51, 'prompt_tokens': 350, 'total_tokens': 401, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZiz56f01zrr2kttIeXyHbYQ1XPRR', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--86ad576a-65a5-4575-8d76-dc3cfd5fe378-0', usage_metadata={'input_tokens': 350, 'output_tokens': 51, 'total_tokens': 401, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n"
]
}
],
"source": [
"print(f\"\\nSimulating user accepting the {Interrupt_Object.value[0]['action_request']} tool call...\")\n",
"for chunk in agent.stream(Command(resume=[{\"type\": \"accept\"}]), config=thread_config_3):\n",
" print(chunk)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================\u001b[1m Human Message \u001b[0m=================================\n",
"\n",
"Draft an email response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference.\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" write_email (call_IByJungo4tOleyF4lDEcBu7R)\n",
" Call ID: call_IByJungo4tOleyF4lDEcBu7R\n",
" Args:\n",
" to: boss@company.ai\n",
" subject: Re: Tomorrow’s Meeting on the Interrupt Conference\n",
" content: Dear [Boss's Name],\n",
"\n",
"Thank you for the reminder about tomorrow’s meeting regarding the Interrupt Conference. I have reviewed the agenda and am prepared to discuss the key points. Please let me know if there are any specific topics or materials you would like me to focus on or bring to the meeting.\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" write_email (call_1MensMD3ArJUJqgBXv1AQAvQ)\n",
" Call ID: call_1MensMD3ArJUJqgBXv1AQAvQ\n",
" Args:\n",
" to: boss@company.ai\n",
" subject: Re: Tomorrow’s Meeting on the Interrupt Conference\n",
" content: Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\n",
"Email sent to boss@company.ai with subject 'Re: Tomorrow’s Meeting on the Interrupt Conference' and content: Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\n",
"\n",
"Thanks,\n",
"[Your Name]\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
"Here's a shorter and less formal response you can use:\n",
"\n",
"Thanks for the heads up about tomorrow’s meeting on the Interrupt Conference. I’ll be ready! Let me know if there’s anything specific you want me to cover.\n",
"\n",
"Thanks,\n",
"[Your Name]\n"
]
}
],
"source": [
"# Let's check the state after responding\n",
"state = agent.get_state(thread_config_3)\n",
"for m in state.values['messages']:\n",
" m.pretty_print()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Editing the tool call"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running the graph until the first interrupt...\n",
"{'agent': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_nm339QV5eqaBLC1WU5xFmiQM', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow\\'s Meeting on the Interrupt Conference\",\"content\":\"Hi,\\\\n\\\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials I should review beforehand.\\\\n\\\\nBest regards,\\\\n\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 89, 'prompt_tokens': 85, 'total_tokens': 174, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj22DO010whYnbgcVhicrNAsKxrs', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--d7568673-1fb8-40ec-b72e-f838bfd767e8-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting on the Interrupt Conference\", 'content': 'Hi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials I should review beforehand.\\n\\nBest regards,\\n\\n[Your Name]'}, 'id': 'call_nm339QV5eqaBLC1WU5xFmiQM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 85, 'output_tokens': 89, 'total_tokens': 174, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"\n",
"INTERRUPT OBJECT:\n",
"Action Request: {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting on the Interrupt Conference\", 'content': 'Hi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials I should review beforehand.\\n\\nBest regards,\\n\\n[Your Name]'}}\n"
]
}
],
"source": [
"# Create a new thread for testing the edit action\n",
"# Run the graph until a tool call that we choose to interrupt\n",
"msg = [{\"role\": \"user\", \"content\": \"Draft a response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference. Call the tool write_email.\"}]\n",
"print(\"Running the graph until the first interrupt...\")\n",
"for chunk in agent.stream({\"messages\": msg}, config=thread_config_4):\n",
"Simulating user editing the write_email tool call...\n",
"{'post_model_hook': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_nm339QV5eqaBLC1WU5xFmiQM', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow\\'s Meeting on the Interrupt Conference\",\"content\":\"Hi,\\\\n\\\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials I should review beforehand.\\\\n\\\\nBest regards,\\\\n\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 89, 'prompt_tokens': 85, 'total_tokens': 174, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj22DO010whYnbgcVhicrNAsKxrs', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--d7568673-1fb8-40ec-b72e-f838bfd767e8-0', tool_calls=[{'args': {'to': 'boss@company.ai', 'subject': 'Meeting tomorrow', 'content': \"Hi boss,\\n\\nI'll be at the Interrupt Conference meeting tomorrow and will bring my notes. Looking forward to discussing our plans!\\n\\nThanks,\\nMe\"}, 'name': 'write_email', 'id': 'call_nm339QV5eqaBLC1WU5xFmiQM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 85, 'output_tokens': 89, 'total_tokens': 174, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'tools': {'messages': [ToolMessage(content=\"Email sent to boss@company.ai with subject 'Meeting tomorrow' and content: Hi boss,\\n\\nI'll be at the Interrupt Conference meeting tomorrow and will bring my notes. Looking forward to discussing our plans!\\n\\nThanks,\\nMe\", name='write_email', id='bbef207d-f2ed-4977-ada8-188da0eae26d', tool_call_id='call_nm339QV5eqaBLC1WU5xFmiQM')]}}\n",
"{'agent': {'messages': [AIMessage(content=\"I've drafted and sent a response to your boss confirming your attendance at tomorrow's Interrupt Conference meeting and mentioning you'll bring your notes. If you'd like to adjust the message or add more details, let me know!\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 42, 'prompt_tokens': 193, 'total_tokens': 235, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj286vw8MFss1KNWXIEYU65oyGuZ', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--31b1861b-a69b-41fd-b2b4-42b15846a91b-0', usage_metadata={'input_tokens': 193, 'output_tokens': 42, 'total_tokens': 235, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'post_model_hook': {'messages': [AIMessage(content=\"I've drafted and sent a response to your boss confirming your attendance at tomorrow's Interrupt Conference meeting and mentioning you'll bring your notes. If you'd like to adjust the message or add more details, let me know!\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 42, 'prompt_tokens': 193, 'total_tokens': 235, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj286vw8MFss1KNWXIEYU65oyGuZ', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--31b1861b-a69b-41fd-b2b4-42b15846a91b-0', usage_metadata={'input_tokens': 193, 'output_tokens': 42, 'total_tokens': 235, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n"
]
}
],
"source": [
"# Now simulate user editing the write_email tool call\n",
"print(\"\\nSimulating user editing the write_email tool call...\")\n",
"edited_email_args = {\n",
" \"action\": \"write_email\",\n",
" \"args\": {\n",
" \"to\": \"boss@company.ai\",\n",
" \"subject\": \"Meeting tomorrow\",\n",
" \"content\": \"Hi boss,\\n\\nI'll be at the Interrupt Conference meeting tomorrow and will bring my notes. Looking forward to discussing our plans!\\n\\nThanks,\\nMe\"\n",
" }\n",
"}\n",
"\n",
"for chunk in agent.stream(Command(resume={\"type\": \"edit\", \"args\": edited_email_args}), config=thread_config_4):\n",
" print(chunk)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================\u001b[1m Human Message \u001b[0m=================================\n",
"\n",
"Draft a response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference. Call the tool write_email.\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" write_email (call_nm339QV5eqaBLC1WU5xFmiQM)\n",
" Call ID: call_nm339QV5eqaBLC1WU5xFmiQM\n",
" Args:\n",
" to: boss@company.ai\n",
" subject: Meeting tomorrow\n",
" content: Hi boss,\n",
"\n",
"I'll be at the Interrupt Conference meeting tomorrow and will bring my notes. Looking forward to discussing our plans!\n",
"Email sent to boss@company.ai with subject 'Meeting tomorrow' and content: Hi boss,\n",
"\n",
"I'll be at the Interrupt Conference meeting tomorrow and will bring my notes. Looking forward to discussing our plans!\n",
"\n",
"Thanks,\n",
"Me\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
"I've drafted and sent a response to your boss confirming your attendance at tomorrow's Interrupt Conference meeting and mentioning you'll bring your notes. If you'd like to adjust the message or add more details, let me know!\n"
]
}
],
"source": [
"# Let's check the state after editing\n",
"state = agent.get_state(thread_config_4)\n",
"for m in state.values['messages']:\n",
" m.pretty_print()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Ignoring the tool call\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running the graph until the first interrupt...\n",
"{'agent': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_kqtyP1N3Hxe0Eovxfuh7xWIl', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow\\'s Meeting on the Interrupt Conference\",\"content\":\"Hi,\\\\n\\\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\\\n\\\\nBest regards,\\\\n\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 92, 'prompt_tokens': 85, 'total_tokens': 177, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj6oHQAIqdXr2SXd5HMkDx9S6DvQ', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--0dbe8a85-7032-403c-a7b5-edd5bcb1e21d-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting on the Interrupt Conference\", 'content': 'Hi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\n\\nBest regards,\\n\\n[Your Name]'}, 'id': 'call_kqtyP1N3Hxe0Eovxfuh7xWIl', 'type': 'tool_call'}], usage_metadata={'input_tokens': 85, 'output_tokens': 92, 'total_tokens': 177, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"\n",
"INTERRUPT OBJECT:\n",
"Action Request: {'action': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting on the Interrupt Conference\", 'content': 'Hi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\n\\nBest regards,\\n\\n[Your Name]'}}\n"
]
}
],
"source": [
"# Create a new thread for testing the ignore action\n",
"# Run the graph until a tool call that we choose to interrupt\n",
"msg = [{\"role\": \"user\", \"content\": \"Draft a response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference. Call the tool write_email.\"}]\n",
"print(\"Running the graph until the first interrupt...\")\n",
"for chunk in agent.stream({\"messages\": msg}, config=thread_config_5):\n",
"{'post_model_hook': {'messages': [AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_kqtyP1N3Hxe0Eovxfuh7xWIl', 'function': {'arguments': '{\"to\":\"boss@company.ai\",\"subject\":\"Re: Tomorrow\\'s Meeting on the Interrupt Conference\",\"content\":\"Hi,\\\\n\\\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\\\n\\\\nBest regards,\\\\n\\\\n[Your Name]\"}', 'name': 'write_email'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 92, 'prompt_tokens': 85, 'total_tokens': 177, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj6oHQAIqdXr2SXd5HMkDx9S6DvQ', 'service_tier': 'default', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run--0dbe8a85-7032-403c-a7b5-edd5bcb1e21d-0', tool_calls=[{'name': 'write_email', 'args': {'to': 'boss@company.ai', 'subject': \"Re: Tomorrow's Meeting on the Interrupt Conference\", 'content': 'Hi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\n\\nBest regards,\\n\\n[Your Name]'}, 'id': 'call_kqtyP1N3Hxe0Eovxfuh7xWIl', 'type': 'tool_call'}], usage_metadata={'input_tokens': 85, 'output_tokens': 92, 'total_tokens': 177, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}), ToolMessage(content='User ignored the tool call for `write_email` with id call_kqtyP1N3Hxe0Eovxfuh7xWIl', name='write_email', id='4112bec6-47dd-4258-8d12-5b35de5181b5', tool_call_id='call_kqtyP1N3Hxe0Eovxfuh7xWIl')]}}\n",
"{'agent': {'messages': [AIMessage(content=\"Here’s a draft response you can send to your boss about tomorrow’s meeting on the Interrupt Conference:\\n\\nSubject: Re: Tomorrow's Meeting on the Interrupt Conference\\n\\nHi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\n\\nBest regards,\\n\\n[Your Name]\\n\\nLet me know if you’d like to make any changes or if you want me to send it for you!\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 109, 'prompt_tokens': 215, 'total_tokens': 324, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj6vq2l3vylQd8mCSx5PYmSJYj0F', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--e77e7082-9015-4534-b0e8-0cac49e5c9e6-0', usage_metadata={'input_tokens': 215, 'output_tokens': 109, 'total_tokens': 324, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n",
"{'post_model_hook': {'messages': [AIMessage(content=\"Here’s a draft response you can send to your boss about tomorrow’s meeting on the Interrupt Conference:\\n\\nSubject: Re: Tomorrow's Meeting on the Interrupt Conference\\n\\nHi,\\n\\nThank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\\n\\nBest regards,\\n\\n[Your Name]\\n\\nLet me know if you’d like to make any changes or if you want me to send it for you!\", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 109, 'prompt_tokens': 215, 'total_tokens': 324, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4.1-2025-04-14', 'system_fingerprint': 'fp_2d9626f3cf', 'id': 'chatcmpl-BZj6vq2l3vylQd8mCSx5PYmSJYj0F', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None}, id='run--e77e7082-9015-4534-b0e8-0cac49e5c9e6-0', usage_metadata={'input_tokens': 215, 'output_tokens': 109, 'total_tokens': 324, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}})]}}\n"
]
}
],
"source": [
"# Now simulate user ignoring the tool call\n",
"print(\"\\nSimulating user ignoring the tool call...\")\n",
"for chunk in agent.stream(Command(resume={\"type\": \"ignore\"}), config=thread_config_5):\n",
" print(chunk)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Final state after ignore action:\n",
"================================\u001b[1m Human Message \u001b[0m=================================\n",
"\n",
"Draft a response to my boss (boss@company.ai) about tomorrow's meeting on the Interrupt Conference. Call the tool write_email.\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
" write_email (call_kqtyP1N3Hxe0Eovxfuh7xWIl)\n",
" Call ID: call_kqtyP1N3Hxe0Eovxfuh7xWIl\n",
" Args:\n",
" to: boss@company.ai\n",
" subject: Re: Tomorrow's Meeting on the Interrupt Conference\n",
" content: Hi,\n",
"\n",
"Thank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\n",
"User ignored the tool call for `write_email` with id call_kqtyP1N3Hxe0Eovxfuh7xWIl\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
"Here’s a draft response you can send to your boss about tomorrow’s meeting on the Interrupt Conference:\n",
"\n",
"Subject: Re: Tomorrow's Meeting on the Interrupt Conference\n",
"\n",
"Hi,\n",
"\n",
"Thank you for scheduling the meeting regarding the Interrupt Conference. I look forward to discussing the agenda and any preparations needed for the event. Please let me know if there are specific topics or materials you’d like me to review beforehand.\n",
"\n",
"Best regards,\n",
"\n",
"[Your Name]\n",
"\n",
"Let me know if you’d like to make any changes or if you want me to send it for you!\n"
]
}
],
"source": [
"# Let's check the state after ignoring\n",
"state = agent.get_state(thread_config_5)\n",
"print(\"\\nFinal state after ignore action:\")\n",
"for m in state.values['messages']:\n",
" m.pretty_print()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "langgraph-env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.