fix(chapter13): repair trip planner health check - #824
Open
Ling-ye wants to merge 1 commit into
Open
Conversation
Ling-ye
marked this pull request as ready for review
August 20, 2026 03:51
linhongyu510
approved these changes
Aug 31, 2026
There was a problem hiding this comment.
验证通过,修复与当前 MultiAgentTripPlanner 的真实对象结构一致。
我在固定 head 07c6facd944893c69936a73a04e76c4712a3e5c9 上做了以下核查:
- 运行作者测试
python3 -m unittest discover -s tests -p '*_test.py' -v:2/2 通过。健康 planner 返回 4 个组件 Agent 暴露的 3 个唯一工具名;工厂初始化异常仍保持 HTTP 503。 - 使用真实 FastAPI
0.141.1/ Starlette1.3.1/ HTTPX0.28.1/ Pydantic2.13.4的TestClient做独立红绿对照,并构造与生产类相同的attraction_agent、weather_agent、hotel_agent、planner_agent四组件对象(刻意不提供不存在的统一.agent字段):- base
45dd84e626a91997294ac8d4d44f18b29a411c6e:GET /trip/health返回 503,错误为MultiAgentTripPlanner没有agent属性; - 本 PR:同一路由返回 200,响应为
status=healthy、agent_name=MultiAgentTripPlanner、tools_count=3; - 工厂抛出
RuntimeError("initialization failed")时,本 PR 仍返回 503,没有放宽失败语义。
- base
- 检查项目允许范围的最低
hello-agents==0.2.4与当前最高0.2.9wheel:两个版本中SimpleAgent.list_tools()都返回工具名称字符串列表,因此跨组件放入set去重的契约成立。 py_compile与git diff --check均通过。
验证边界:本次只覆盖健康检查路由、HTTP 状态/响应契约以及真实依赖版本中的工具列表接口;未初始化真实 LLM,也未连接 MCP 或地图服务,因此不把结果表述为完整旅行规划 E2E。
AI 辅助披露:使用 AI 辅助梳理差异与生成验证语料;上述命令、依赖版本、输出和 Review 结论均由我逐项复核。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
我在参考 hello-agents 第十三章实现旅行规划项目,并检查案例后端健康状态接口时,
发现
/trip/health在旅行规划器已经成功初始化的情况下仍会进入 503 异常路径。沿着健康检查的调用链排查后发现,端点访问了
MultiAgentTripPlanner.agent,但该类并不存在统一的agent属性。实际可用的是
attraction_agent、weather_agent、hotel_agent和planner_agent四个组件 Agent。问题原因
健康检查当前执行:
get_trip_planner_agent()返回的是MultiAgentTripPlanner。访问不存在的.agent会触发AttributeError,随后被端点统一转换为 HTTP 503。变更
agent_name字段。tools_count在本修复中表示“系统暴露的唯一工具名称数量”,而不是 Agent 与工具绑定关系的总次数。
验证
结果:2 个测试通过。
.agent。git diff --check通过。测试使用标准库替身隔离 FastAPI、LLM 和 MCP 初始化,因此这是路由核心逻辑的
离线回归测试,不代表完整服务端到端验证。
风险
status、service、agent_name和tools_count保持不变。agent_name从无法读取的内部属性改为旅行规划器的实际类型名。