材料题 1:智能体⼯具调⽤ JSON 校验器
在⼯具调⽤型智能体中,模型输出通常需要被解析为结构化 JSON,再根据⼯具 schema 校验⼯具名和参
数是否合法。下⾯的代码实现了⼀个简化版⼯具调⽤校验器:它读取模型输出字符串,检查⼯具名、参数
字段和参数类型,并返回标准化后的⼯具调⽤对象。
请阅读代码,并根据描述完成空缺部分。
python
1import json
2from typing import Any
3,[object Object],
4,[object Object],
5,[object Object],
python
1def normalize_tool_call(raw: str) -> dict[str, Any]:,[object Object],
2obj = load_tool_call(raw),[object Object],
3tool_name = obj["tool_name"],[object Object],
4arguments = obj["arguments"],[object Object],
5if not validate_arguments(tool_name, arguments):,[object Object],
6raise ValueError("bad arguments"),[object Object],
7return {"tool_name": tool_name, "arguments": arguments}