[问题/Issue] 章节4.2.2:代码错误

Author: a-yang-teaCreated Aug 27, 2026Updated Aug 27, 2026
Labelsdocumentation

1. 遇到问题的章节 / Affected Chapter

Chapter4.2.2 工具的定义与实现

2. 问题类型 / Issue Type

代码错误 / Code Error

3. 具体问题描述 / Problem Description

直接运行会抛异常

4. 问题重现材料 / Reproduction Materials

我们的第一个工具是 search 函数,它的作用是接收一个查询字符串,然后返回搜索结果。这里的代码有个问题: if "answer_box_list" in results: return "\n".join(results["answer_box_list"]) answer_box_list`里面元素是字典,不是字符串。 "\n".join(results["answer_box_list"]),join 只能拼接字符串,直接运行会抛异常。

5. 补充信息 / Additional Information

修改后: if "answer_box_list" in results: parts = [] for box in results["answer_box_list"]: ans = box.get("answer","") if ans: parts.append(ans) return "\n".join(parts)

确认事项 / Verification

  • 我已阅读过相关章节的文档 / I have read the relevant chapter documentation
  • 我已搜索过现有的Issues,确认此问题未被报告 / I have searched existing Issues and confirmed this hasn't been reported
  • 我已尝试过基本的故障排除(如重启、重新安装依赖等) / I have tried basic troubleshooting (restart, reinstall dependencies, etc.)

Source: datawhalechina/hello-agents