一般公司网站的后台管理在哪,长尾关键词查询工具,网页设计与制作跟编程有关吗,手机如何创建公众号随着人工智能技术的不断进步#xff0c;越来越多的企业开始借助 AI 助手来提高工作效率#xff0c;尤其是在日常事务的自动化处理中。比如#xff0c;在许多公司里#xff0c;会议室的预定是一个常见且频繁的需求#xff0c;通常需要员工手动检查空闲时间并做出选择。而通…随着人工智能技术的不断进步越来越多的企业开始借助 AI 助手来提高工作效率尤其是在日常事务的自动化处理中。比如在许多公司里会议室的预定是一个常见且频繁的需求通常需要员工手动检查空闲时间并做出选择。而通过集成 AI 和自动化工具这个过程可以变得更加智能和高效。 
本文将展示如何利用 LangChain 和 LangGraph 两个强大的工具构建一个会议室预订系统。这一系统能够与用户进行自然语言交互帮助用户自动预订会议室并确保预订信息的准确性。我们会详细讲解如何实现从查询空闲会议室到确认预订的整个过程。 
关键代码 
下面是实现该系统的核心代码。在这个代码段中我们通过 LangChain 定义了几个重要的工具分别是获取所有会议室、查询指定时间段内可用的会议室和预订会议室。 
from config import *
from datetime import datetime
from langchain_core.tools import tool
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_openai import ChatOpenAI
from langgraph.types import Command, interrupt
from langgraph.prebuilt import create_react_agent
from IPython.display import Image, display
from langgraph.checkpoint.memory import InMemorySaver/Users/zhengjie/Documents/learn-langchain/venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1, currently the ssl module is compiled with LibreSSL 2.8.3. See: https://github.com/urllib3/urllib3/issues/3020warnings.warn(tool(parse_docstringTrue)
def get_all_rooms() - list:Get a list of all available meeting rooms.Returns:list: A list of all available meeting rooms.return [Room 1, Room 2, Room 3, 888 Multimedia Conference Room]tool(parse_docstringTrue)
def get_available_rooms(start_time: str, end_time: str) - list:Get a list of all available meeting rooms during the specified time period.Args:start_time (str): The start time of the booking (e.g., 2025-02-23 14:00).end_time (str): The end time of the booking (e.g., 2025-02-23 15:00).Returns:list: A list of all available meeting rooms during the specified time period.return [Room 1, Room 2]tool(parse_docstringTrue)
def book_room(name: str, start_time: str, end_time: str) - str:Book a specified meeting room for the user, only after the user confirms the details.Args:name (str): The name of the meeting room to be booked.start_time (str): The start time of the booking (e.g., 2025-02-23 14:00).end_time (str): The end time of the booking (e.g., 2025-02-23 15:00).Returns:str: A message indicating whether the booking was successful or failed.if name in [Room 1, Room 2, Room 3, 888 Multimedia Conference Room]:if name in [Room 1, Room 2]:return Booking successfulelse:return The room is not availableelse:return Invalid room nametools  [get_all_rooms, get_available_rooms, book_room]
llm  ChatOpenAI(modelqwen-max)
memory  InMemorySaver()
prompt  SystemMessage(fYou are an AI assistant. The current time is: {datetime.now().strftime(%Y-%m-%d %H:%M)}. fPlease assist the user in booking a meeting room by confirming the meeting time and room step by step. fKeep your language as concise as possible.\nfThe most important thing is that before using book_room, make sure to confirm the information with the user one last time. fOnly proceed with book_room if everything is correct. Do not skip this step.
)
agent  create_react_agent(llm, tools, checkpointermemory, promptprompt)prompt.pretty_print()[1m System Message [0mYou are an AI assistant. The current time is: 2025-02-23 21:58. Please assist the user in booking a meeting room by confirming the meeting time and room step by step. Keep your language as concise as possible.
The most important thing is that before using book_room, make sure to confirm the information with the user one last time. Only proceed with book_room if everything is correct. Do not skip this step.display(Image(agent.get_graph().draw_mermaid_png()))使用案例 
会议室预订案例1 
config  {configurable: {thread_id: abc123}}
result  agent.invoke({messages: [{role: user, content: 帮我预定一个会议室}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我预定一个会议室
[1m Ai Message [0m好的我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如14:00到16:00。config  {configurable: {thread_id: abc123}}
result  agent.invoke({messages: [{role: user, content: 明天上午10点到11点}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我预定一个会议室
[1m Ai Message [0m好的我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如14:00到16:00。
[1m Human Message [0m明天上午10点到11点
[1m Ai Message [0m
Tool Calls:get_available_rooms (call_a39d8e624ae845b6a1e02b)Call ID: call_a39d8e624ae845b6a1e02bArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
[1m Tool Message [0m
Name: get_available_rooms[Room 1, Room 2]
[1m Ai Message [0m明天上午10点到11点之间有以下会议室可供选择- Room 1
- Room 2您想要预定哪一个会议室呢请告诉我会议室的名称。config  {configurable: {thread_id: abc123}}
result  agent.invoke({messages: [{role: user, content: 第一个}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我预定一个会议室
[1m Ai Message [0m好的我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如14:00到16:00。
[1m Human Message [0m明天上午10点到11点
[1m Ai Message [0m
Tool Calls:get_available_rooms (call_a39d8e624ae845b6a1e02b)Call ID: call_a39d8e624ae845b6a1e02bArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
[1m Tool Message [0m
Name: get_available_rooms[Room 1, Room 2]
[1m Ai Message [0m明天上午10点到11点之间有以下会议室可供选择- Room 1
- Room 2您想要预定哪一个会议室呢请告诉我会议室的名称。
[1m Human Message [0m第一个
[1m Ai Message [0m好的您选择了Room 1。请确认您的预定信息会议室为Room 1时间是明天上午10点到11点。如果这些信息正确我将为您完成预定。信息正确吗请回复“正确”或“不正确”。config  {configurable: {thread_id: abc123}}
result  agent.invoke({messages: [{role: user, content: 确认}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我预定一个会议室
[1m Ai Message [0m好的我来帮您预定会议室。请告诉我您计划的会议开始时间和结束时间。例如14:00到16:00。
[1m Human Message [0m明天上午10点到11点
[1m Ai Message [0m
Tool Calls:get_available_rooms (call_a39d8e624ae845b6a1e02b)Call ID: call_a39d8e624ae845b6a1e02bArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
[1m Tool Message [0m
Name: get_available_rooms[Room 1, Room 2]
[1m Ai Message [0m明天上午10点到11点之间有以下会议室可供选择- Room 1
- Room 2您想要预定哪一个会议室呢请告诉我会议室的名称。
[1m Human Message [0m第一个
[1m Ai Message [0m好的您选择了Room 1。请确认您的预定信息会议室为Room 1时间是明天上午10点到11点。如果这些信息正确我将为您完成预定。信息正确吗请回复“正确”或“不正确”。
[1m Human Message [0m确认
[1m Ai Message [0m
Tool Calls:book_room (call_824c897caa2d40f98328a9)Call ID: call_824c897caa2d40f98328a9Args:name: Room 1start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
[1m Tool Message [0m
Name: book_room预定成功
[1m Ai Message [0m您的会议室预定已经成功。预定的是Room 1时间为明天上午10点到11点。如果有其他需要帮助的地方请随时告诉我。会议室预订案例2 
config  {configurable: {thread_id: abc1235}}
result  agent.invoke({messages: [{role: user, content: 帮我订明天上午10点到11点1号会议室}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我订明天上午10点到11点1号会议室
[1m Ai Message [0m
Tool Calls:get_available_rooms (call_fefded82be70420182322d)Call ID: call_fefded82be70420182322dArgs:start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
[1m Tool Message [0m
Name: get_available_rooms[Room 1, Room 2]
[1m Ai Message [0m明天上午10点到11点1号会议室是可用的。您想要预订1号会议室对吗
Tool Calls:book_room (call_4637776f50e644d0889c6d)Call ID: call_4637776f50e644d0889c6dArgs:name: Room 1start_time: 2025-02-24 10:00end_time: 2025-02-24 11:00
[1m Tool Message [0m
Name: book_roomBooking successful
[1m Ai Message [0m已成功为您预订了明天上午10点到11点的1号会议室。会议室预订案例3 
config  {configurable: {thread_id: abc12345}}
result  agent.invoke({messages: [{role: user, content: 帮我订1号会议室}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我订1号会议室
[1m Ai Message [0m好的我需要确认一下您希望预订1号会议室的具体时间段。请告诉我您打算从什么时候开始到什么时候结束config  {configurable: {thread_id: abc12345}}
result  agent.invoke({messages: [{role: user, content: 明天下午2点至4点}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我订1号会议室
[1m Ai Message [0m好的我需要确认一下您希望预订1号会议室的具体时间段。请告诉我您打算从什么时候开始到什么时候结束
[1m Human Message [0m明天下午2点至4点
[1m Ai Message [0m
Tool Calls:get_available_rooms (call_d817bfbe8e9d4eb49aa8e9)Call ID: call_d817bfbe8e9d4eb49aa8e9Args:start_time: 2025-02-24 14:00end_time: 2025-02-24 16:00
[1m Tool Message [0m
Name: get_available_rooms[Room 1, Room 2]
[1m Ai Message [0m明天下午2点到4点之间1号会议室是可用的。在继续预订前请确认以下信息是否正确- 会议室1号
- 开始时间明天下午2点2025年2月24日 14:00
- 结束时间明天下午4点2025年2月24日 16:00如果这些信息都正确我将为您预订1号会议室。请回复“正确”以确认或提供修改的信息。
正确config  {configurable: {thread_id: abc12345}}
result  agent.invoke({messages: [{role: user, content: 确认}]},configconfig
)
for m in result[messages]:m.pretty_print()[1m Human Message [0m帮我订1号会议室
[1m Ai Message [0m好的我需要确认一下您希望预订1号会议室的具体时间段。请告诉我您打算从什么时候开始到什么时候结束
[1m Human Message [0m明天下午2点至4点
[1m Ai Message [0m
Tool Calls:get_available_rooms (call_d817bfbe8e9d4eb49aa8e9)Call ID: call_d817bfbe8e9d4eb49aa8e9Args:start_time: 2025-02-24 14:00end_time: 2025-02-24 16:00
[1m Tool Message [0m
Name: get_available_rooms[Room 1, Room 2]
[1m Ai Message [0m明天下午2点到4点之间1号会议室是可用的。在继续预订前请确认以下信息是否正确- 会议室1号
- 开始时间明天下午2点2025年2月24日 14:00
- 结束时间明天下午4点2025年2月24日 16:00如果这些信息都正确我将为您预订1号会议室。请回复“正确”以确认或提供修改的信息。
正确
[1m Human Message [0m确认
[1m Ai Message [0m
Tool Calls:book_room (call_1772161999ae43edb35d66)Call ID: call_1772161999ae43edb35d66Args:name: Room 1start_time: 2025-02-24 14:00end_time: 2025-02-24 16:00
[1m Tool Message [0m
Name: book_roomBooking successful
[1m Ai Message [0m已成功为您预订1号会议室时间段为明天下午2点到4点。如果有任何其他需求请告诉我。
 文章转载自: http://www.morning.wljzr.cn.gov.cn.wljzr.cn http://www.morning.zlnmm.cn.gov.cn.zlnmm.cn http://www.morning.jjxxm.cn.gov.cn.jjxxm.cn http://www.morning.rkfgx.cn.gov.cn.rkfgx.cn http://www.morning.wqmyh.cn.gov.cn.wqmyh.cn http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.mtgnd.cn.gov.cn.mtgnd.cn http://www.morning.tyhfz.cn.gov.cn.tyhfz.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn http://www.morning.rstrc.cn.gov.cn.rstrc.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.bwdnx.cn.gov.cn.bwdnx.cn http://www.morning.xrnh.cn.gov.cn.xrnh.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.qnwyf.cn.gov.cn.qnwyf.cn http://www.morning.wnmdt.cn.gov.cn.wnmdt.cn http://www.morning.qbrdg.cn.gov.cn.qbrdg.cn http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn http://www.morning.nxwk.cn.gov.cn.nxwk.cn http://www.morning.jrhcp.cn.gov.cn.jrhcp.cn http://www.morning.rntgy.cn.gov.cn.rntgy.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.hcxhz.cn.gov.cn.hcxhz.cn http://www.morning.gchqy.cn.gov.cn.gchqy.cn http://www.morning.rbsxf.cn.gov.cn.rbsxf.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.xtlty.cn.gov.cn.xtlty.cn http://www.morning.jpydf.cn.gov.cn.jpydf.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.rhsr.cn.gov.cn.rhsr.cn http://www.morning.pjtnk.cn.gov.cn.pjtnk.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.cypln.cn.gov.cn.cypln.cn http://www.morning.bkylg.cn.gov.cn.bkylg.cn http://www.morning.ntnml.cn.gov.cn.ntnml.cn http://www.morning.qrwnj.cn.gov.cn.qrwnj.cn http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn http://www.morning.gjxr.cn.gov.cn.gjxr.cn http://www.morning.nlygm.cn.gov.cn.nlygm.cn http://www.morning.wdshp.cn.gov.cn.wdshp.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.gwsll.cn.gov.cn.gwsll.cn http://www.morning.xyyplp.cn.gov.cn.xyyplp.cn http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn http://www.morning.hgcz.cn.gov.cn.hgcz.cn http://www.morning.ygrdb.cn.gov.cn.ygrdb.cn http://www.morning.lsqxh.cn.gov.cn.lsqxh.cn http://www.morning.lhgkr.cn.gov.cn.lhgkr.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.kszkm.cn.gov.cn.kszkm.cn http://www.morning.tynqy.cn.gov.cn.tynqy.cn http://www.morning.fhghy.cn.gov.cn.fhghy.cn http://www.morning.gzzncl.cn.gov.cn.gzzncl.cn http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn http://www.morning.txtgy.cn.gov.cn.txtgy.cn http://www.morning.bkcnq.cn.gov.cn.bkcnq.cn http://www.morning.khxwp.cn.gov.cn.khxwp.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.lfpdc.cn.gov.cn.lfpdc.cn http://www.morning.gbfck.cn.gov.cn.gbfck.cn http://www.morning.nmyrg.cn.gov.cn.nmyrg.cn http://www.morning.gwdmj.cn.gov.cn.gwdmj.cn http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn http://www.morning.hrzhg.cn.gov.cn.hrzhg.cn http://www.morning.fsjcn.cn.gov.cn.fsjcn.cn http://www.morning.smfbw.cn.gov.cn.smfbw.cn http://www.morning.mmtjk.cn.gov.cn.mmtjk.cn http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com http://www.morning.cwrpd.cn.gov.cn.cwrpd.cn http://www.morning.fxzlg.cn.gov.cn.fxzlg.cn http://www.morning.tlnbg.cn.gov.cn.tlnbg.cn http://www.morning.rfqk.cn.gov.cn.rfqk.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.wmlby.cn.gov.cn.wmlby.cn http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn http://www.morning.yzsdp.cn.gov.cn.yzsdp.cn http://www.morning.gybnk.cn.gov.cn.gybnk.cn http://www.morning.fwqgy.cn.gov.cn.fwqgy.cn