LiveKit 酒店前台 Agent 的商务中心策略落地从 Markdown 政策到可执行预订工具【免费下载链接】agentsA framework for building realtime voice AI agents ️项目地址: https://gitcode.com/GitHub_Trending/agen/agents本指南以 business_center.md 为核心剖析 LiveKit Agents 酒店前台示例Hotel Receptionist Example中商务中心预订这一完整链路政策文档如何描述服务目录与营业规则book_business_center工具如何在代码层落实价格与时长校验以及测试场景如何验证 Agent 端到端行为。读完本文你将掌握以 Markdown 政策文件驱动实时语音 Agent 工具行为的设计模式并可直接运行该示例亲手体验。一、政策文档在示例中的定位渐进式披露知识库在examples/hotel_receptionist这个基于 LiveKit Agents 构建的精品酒店前台语音 Agent 中policies/目录下的每个 Markdown 文件都对应一个长尾知识点。核心提示词instructions.py只内联高频热路径信息其余全部按主题拆分为独立文档由 policies/init.py 在启动时扫描目录动态构建lookup_policy工具for path in sorted(_POLICY_DIR.glob(*.md)): description, _, body path.read_text().partition(\n) policies[path.stem] body.strip() index.append(f- {path.stem}: {description.strip()})首行即索引条目每个文件的第一行被当作该主题在工具 schema 中的一句话描述business_center.md的第一行正是Business centre services bookable through the desk: meeting room, secretarial help, and printing.其余正文即内容模型调用lookup_policy(topicbusiness_center)时收到的就是文件剩余全文杜绝漂移工具的 enum 与索引由目录实时重建新增主题 新增文件永远不会与语料失同步。提示词中的路由规则instructions.py明确要求 Agent 面对商务中心请求时先查政策、再调工具Business centre (a meeting room, secretarial help, or a printing job) - lookup_policy(topicbusiness_center) to present options, then book_business_center.这就是先取证、后行动的落地形态。二、商务中心服务目录与营业规则政策文档原文business_center.md定义了完整的可预订服务目录与固定价格全文如下Business centre services bookable through the desk: meeting room, secretarial help, and printing.The business centre is open 7:00 AM to 9:00 PM daily (book_business_center):Meeting room: seats up to 8, screen and whiteboard, booked by the hour, up to 8 hours, 40 dollars per hour.Secretarial service: typing, dictation, and document prep, booked by the hour, up to 4 hours, 35 dollars per hour.Printing and binding: flat-rate print, copy, and bind job, ready same day, 25 dollars flat.Narrow before booking: which service, the date and start time, and how many hours (printing is a flat one-hour job). Quote the rate and total from this list when confirming - theyre fixed, so the caller gets concrete details, not the centre will tell you.可归纳为一张目录表价格均为固定费率由政策文档与代码双层锁定服务计费方式单价时长上限说明Meeting room会议室按小时40 美元/小时最多 8 小时最多容纳 8 人含屏幕与白板Secretarial service秘书协助按小时35 美元/小时最多 4 小时打字、听写、文档准备Printing and binding打印装订固定价25 美元/次固定 1 小时作业统一费率打印/复印/装订当日可取营业时间为每天 7:00 AM 至 9:00 PM且全部经由book_business_center工具完成预订。政策文档与代码目录的双向同步这份目录并非仅存在于文档中——hotel_db.py 用数据类BusinessCenterService和字典BUSINESS_CENTER_SERVICES实现了完全一致的目录代码注释明确写着与 policies/business_center.md 描述同一目录二者必须保持同步dataclass(frozenTrue) class BusinessCenterService: name: str price_per_hour: int | None # cents; None for flat-priced services flat_price: int | None max_hours: int description: str BUSINESS_CENTER_SERVICES: dict[str, BusinessCenterService] { meeting_room: BusinessCenterService( nameMeeting room, price_per_hour4000, # 40.00 美元/小时以美分存储 flat_priceNone, max_hours8, descriptionseats up to 8, screen and whiteboard, booked by the hour, ), secretarial: BusinessCenterService( nameSecretarial service, price_per_hour3500, # 35.00 美元/小时 flat_priceNone, max_hours4, descriptiontyping, dictation, and document prep, booked by the hour, ), printing: BusinessCenterService( namePrinting and binding, price_per_hourNone, # 非按时计费 flat_price2500, # 25.00 美元固定价 max_hours1, # 固定 1 小时作业 descriptionflat-rate print, copy, and bind job, ready same day, ), }值得注意的是金额一律以分为单位存储4000 $40.00并由speak_usd负责口语化输出——这延续了该示例LLM 永远不持有金额数值的架构原则见 README.md避免模型在口语报价中产生幻觉数字。三、预订前必须收窄的信息协议Narrow Before Booking政策文档明确规定在任何预订动作之前Agent 必须与来电者逐项确认三个要素which service——具体是哪项服务会议室 / 秘书协助 / 打印装订the date and start time——预订日期与开始时间how many hours——需要多少小时打印为固定 1 小时作业无需时长参数。这套协议在工具签名中被固化。book_business_center定义于 tools_services.py其函数 docstring 本身就是给模型的行为指令function_tool async def book_business_center( self, ctx: RunContext[Userdata], service: Literal[meeting_room, secretarial, printing], on_date: date, at_time: time, duration_hours: Annotated[int, Field(ge1)], guest_name: str, guest_phone: str, ) - str: Book a business-centre service - a meeting room, secretarial help, or a printing job. The catalog (rates, hours, whats included) is in lookup_policy topic business_center - look it up first and narrow with the caller (which service, the date and start time, and how long) before booking. The options are for the CALLER to pick from, never pick for them. Once they pick and agree, THIS CALL is the booking - saying Ill get that set up books nothing; nothing exists until this returns a reference.从源码结构可以提炼出三层设计要点参数即协议service被Literal锁定为三项之一duration_hours有ge1下限约束——工具层从类型系统上杜绝了编造服务与0 小时预订先查后订docstring 要求模型先调用lookup_policy(topicbusiness_center)拿到目录再与来电者确认细节严禁替来电者做选择never pick for them调用即成交明确声明本通电话就是预订本身口头承诺不算数只有工具返回引用码reference才算真正落库——这与提示词中# Never invent a confirmation一节的原则完全一致。四、报价原则固定价格具体到数字政策文档末尾是对报价行为的硬性约束Quote the rate and total from this list when confirming - theyre fixed, so the caller gets concrete details, not the centre will tell you.即价格是固定的、公开的Agent 必须直接给出具体费率和总额如会议室 40 美元一小时三小时共 120 美元不得敷衍回答到时候中心会告诉你。这一要求在测试场景中被专门设计为刁钻问题curveball。在 scenarios_tool_accuracy.yaml 的测试用例 #33 Book a business-centre meeting room 中模拟来电者Marcus Bell需要明天下午 2 点起使用会议室 3 小时刻意刁难第二步要求what is that going to cost me?——来电者要的是具体数字而非模糊答复预期行为Agent 必须先从目录查到 40 美元/小时的费率并算出 3 小时共 120 美元直接作答而不是把问题抛回或转交他人必须拿到引用码来电者拿不到 reference 不会挂断and what is the booking reference?从对话层面强制工具真实执行。该用例还带确定性数据库校验agent_expectations要求最终落库一条INSERT INTO business_center_bookings ... VALUES (IGNORED, meeting_room, Marcus Bell, 4155550288, 2026-06-09, 14:00:00, 3, 12000)其中12000正是 3 小时 × 4000 美分的结果——数据库状态与语音对话行为被一起断言。五、后端实现价格计算、校验与落库book_business_center工具最终调用 hotel_db.py 中的HotelDB.book_business_center这一层承担全部业务校验与金额计算完整逻辑如下async def book_business_center( self, *, service_id, guest_name, guest_phone, on_date, at_time, duration_hours, ) - tuple[str, BusinessCenterService, int]: service BUSINESS_CENTER_SERVICES.get(service_id) if service is None: raise NotFound(...) # 1. 服务必须存在 if on_date TODAY: raise Unavailable(f{on_date.isoformat()} is in the past) # 2. 日期不能是过去 if duration_hours service.max_hours: raise Unavailable(f{service.name} is booked for at most {service.max_hours} hours) # 3. 时长上限 total service.flat_price or (service.price_per_hour or 0) * duration_hours # 4. 金额计算 code shortuuid(BIZ-) # 5. BIZ- 前缀引用码 ... 写入 business_center_bookings 表 ... return code, service, total五个关键点服务存在性校验未知 service_id 直接抛NotFound错误信息会列出全部合法选项供模型纠正调用日期不可为过去早于系统当天TODAY的日期抛Unavailable时长上限强制duration_hours超过该服务的max_hours会议室 8、秘书 4、打印 1即拒绝——这与政策文档中的up to 8 hours / up to 4 hours / flat one-hour job一一对应金额由服务端计算total flat_price打印或price_per_hour × duration_hours会议室、秘书模型只负责转述工具返回的总额无权自行算价引用码格式BIZ-前缀 短 UUID作为预订凭据读回给来电者_speak_code负责口语化拼读。落库目标表business_center_bookings的 schema 定义于 hotel_db.pyservice_id列带CHECK (service_id IN (meeting_room,secretarial,printing))约束duration_hours带CHECK (duration_hours 1)——数据库层面再次锁死合法性。工具返回后模型会按 docstring 的要求向来电者确认服务、开始时间与总额并明确这些是固定价格confirm the service, start time, and total to the caller - these are fixed, give them as facts。六、验证链路确定性评测如何兜底商务中心预订的端到端正确性由两层机制共同保障对话行为层评测用例 #33 的agent_expectations断言 Agent 查询目录、收窄信息、给出具体报价$120、回读真实引用码的全过程杜绝口头承诺但未调用工具的幻觉式确认数据库状态层userdata.expected_state中的INSERT INTO business_center_bookings语句要求基准数据库与运行后数据库的差异完全等价于这一条业务记录——参考 benchmark.py 中的build_expected/diff_databases与feature: business_center_booking标签business_center_bookings表被列入确定性断言清单。换言之评测同时验证说了该说的话与做了该做的事——这正是该示例将政策文档、工具实现与测试场景三者强绑定所追求的效果。七、运行与体验按 README.md 的指引可以本地启动该 Agent 并亲自扮演来电者验证商务中心流程uv run examples/hotel_receptionist/fake_data/seed.py # 方式一纯控制台对话 uv run examples/hotel_receptionist/agent.py console # 方式二配合 LiveKit playground实时数据库状态可视化 uv run examples/hotel_receptionist/agent.py dev在对话中尝试I need to book a meeting room in your business centre for tomorrow afternoon, 2 PM, for three hours观察 Agent 是否会先给出 40 美元/小时、合计 120 美元的明确报价并在确认后回读BIZ-开头的预订引用码。若追问具体价格Agent 应当直接作答而不是回答the centre will tell you。八、小结政策文档驱动工具行为的设计模式从business_center.md这份不足十行的政策文件可以提炼出该示例极具借鉴价值的模式单一事实来源服务目录、价格、时长上限以 Markdown 形式写给模型同时以数据类形式写给代码两处注释互相提醒保持同步渐进式披露长尾政策不进提示词由lookup_policy工具按需检索policies/init.py控制上下文成本工具签名固化协议Literal枚举、Field(ge...)约束与 docstring 行为指令共同把先查政策、收窄信息、给出固定报价、调用即成交写进可执行的契约双层验证对话层评测约束模型言行数据库层断言约束落库结果让说了什么与做了什么均可机器校验。这套政策文档 → 检索工具 → 预订工具 → 数据库 → 评测用例的完整链路正是 LiveKit Agents 构建可靠业务型语音 Agent 的关键工程实践值得在真实项目如酒店、客服、预约类场景中直接复用。【免费下载链接】agentsA framework for building realtime voice AI agents ️项目地址: https://gitcode.com/GitHub_Trending/agen/agents创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考