fix(agent): reject argless action in normalization; add boundary test
核心算法 #10(Agent Loop):修复 Codex 质量审查 Critical——
_normalize_action 仅在除 tool 外至少存在一个平铺参数键时才收拢,
{"tool": "x"} 无参结构不再被静默升级为空 args 合法结构,照旧
返回 None 走 retry 追问路径。补边界测试 + 测试辅助方法类型注解
与中文 docstring。
This commit is contained in:
+6
-3
@@ -310,17 +310,20 @@ class AgentLoop:
|
||||
|
||||
deepseek 等模型稳定输出变体: 工具参数平铺在 action 下(缺 args
|
||||
嵌套),确定性收拢为标准 {"tool": ..., "args": {...}} 结构。
|
||||
标准嵌套结构与非法结构均原样返回,由调用方校验。
|
||||
仅当除 tool 外至少存在一个平铺参数键时才收拢;无参结构
|
||||
(如 {"tool": "x"})原样返回交由调用方校验拒绝,避免把缺参
|
||||
错误静默升级为空 args 合法结构。标准嵌套与非法结构同样原样返回。
|
||||
|
||||
参数:
|
||||
action: 从 LLM 输出解析出的 action 字段(任意类型)。
|
||||
|
||||
返回:
|
||||
归一化后的 action(仅平铺变体被改写,其余原样返回)。
|
||||
归一化后的 action(仅带平铺参数的变体被改写,其余原样返回)。
|
||||
"""
|
||||
if isinstance(action, dict) and "tool" in action and "args" not in action:
|
||||
flat_args = {k: v for k, v in action.items() if k != "tool"}
|
||||
return {"tool": action["tool"], "args": flat_args}
|
||||
if flat_args:
|
||||
return {"tool": action["tool"], "args": flat_args}
|
||||
return action
|
||||
|
||||
async def _execute_tool(
|
||||
|
||||
Reference in New Issue
Block a user