feat: implement action aliasing and parameter normalization in AIPlanner to enhance compatibility with LM Studio responses

This commit is contained in:
21in7
2026-03-27 20:19:53 +09:00
parent 66f3a327e8
commit d9801ee457
3 changed files with 47 additions and 1 deletions

View File

@@ -37,6 +37,12 @@ ALLOWED_ACTIONS = {
"start_research",
"wait",
}
ACTION_ALIASES = {
"place_building": "place_entity",
"build_entity": "place_entity",
"mine": "mine_resource",
"research": "start_research",
}
SYSTEM_PROMPT = """당신은 팩토리오 게임을 순수하게 플레이하는 AI 에이전트입니다.
@@ -466,11 +472,15 @@ class AIPlanner:
if not isinstance(a, dict):
continue
act = a.get("action")
if not isinstance(act, str) or act not in ALLOWED_ACTIONS:
if not isinstance(act, str):
continue
act = ACTION_ALIASES.get(act, act)
if act not in ALLOWED_ACTIONS:
continue
params = a.get("params")
if not isinstance(params, dict):
params = {}
params = AIPlanner._normalize_params(act, params)
reason = a.get("reason")
if not isinstance(reason, str):
reason = ""
@@ -482,6 +492,23 @@ class AIPlanner:
"after_this": str(plan.get("after_this", "")),
}
@staticmethod
def _normalize_params(action: str, params: dict) -> dict:
p = dict(params)
if action == "move":
if "x" not in p and "target_x" in p:
p["x"] = p.get("target_x")
if "y" not in p and "target_y" in p:
p["y"] = p.get("target_y")
elif action == "place_entity":
if "name" not in p and "item" in p:
p["name"] = p.get("item")
if "x" not in p and "position_x" in p:
p["x"] = p.get("position_x")
if "y" not in p and "position_y" in p:
p["y"] = p.get("position_y")
return p
@staticmethod
def _ensure_move_before_build_actions(actions: list[dict]) -> list[dict]:
"""