fix: handle null action_params from LLM response

LLM sometimes returns null instead of {} for action_params when an
action doesn't require parameters (e.g., ["Cultivate", null]). This
caused AttributeError when calling .items() on None.

Changes:
- Add defensive check in ai.py to convert null to {}
- Update prompt to explicitly require {} instead of null
This commit is contained in:
Zihao Xu
2026-01-05 01:25:52 -08:00
parent 8727a4f29a
commit 8c8e28264f
3 changed files with 8 additions and 3 deletions

View File

@@ -87,9 +87,10 @@ class LLMAI(AI):
for p in raw_pairs:
if isinstance(p, list) and len(p) == 2:
pairs.append((p[0], p[1]))
# LLM 可能返回 null 作为 params需要转为空字典。
pairs.append((p[0], p[1] or {}))
elif isinstance(p, dict) and "action_name" in p and "action_params" in p:
pairs.append((p["action_name"], p["action_params"]))
pairs.append((p["action_name"], p["action_params"] or {}))
else:
continue