feat: AIPlanner에서 건설 전 이동 보장 로직 추가
- `_ensure_move_before_build_actions` 메서드를 추가하여, LLM이 "move" 후 "place_entity"/"insert_to_entity"/"set_recipe" 순서를 놓치는 경우를 방지 - 최근 이동 좌표와 비교하여 필요 시 자동으로 이동 액션을 삽입하는 로직 구현 - 관련 단위 테스트 추가 및 README.md에 변경 사항 반영
This commit is contained in:
30
tests/test_ai_planner_action_enforcement.py
Normal file
30
tests/test_ai_planner_action_enforcement.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from ai_planner import AIPlanner
|
||||
|
||||
|
||||
class TestAIPlannerActionEnforcement(unittest.TestCase):
|
||||
def setUp(self):
|
||||
os.environ.setdefault("ZAI_API_KEY", "dummy")
|
||||
|
||||
def test_insert_move_before_place_entity_if_last_move_differs(self):
|
||||
actions = [
|
||||
{"action": "craft_item", "params": {"item": "coal", "count": 1}},
|
||||
{"action": "place_entity", "params": {"name": "stone-furnace", "x": 1, "y": 2, "direction": "north"}},
|
||||
]
|
||||
out = AIPlanner._ensure_move_before_build_actions(actions)
|
||||
self.assertEqual(out[0]["action"], "craft_item")
|
||||
self.assertEqual(out[1]["action"], "move")
|
||||
self.assertEqual(out[1]["params"]["x"], 1)
|
||||
self.assertEqual(out[1]["params"]["y"], 2)
|
||||
self.assertEqual(out[2]["action"], "place_entity")
|
||||
|
||||
def test_do_not_insert_move_if_last_move_same_coords(self):
|
||||
actions = [
|
||||
{"action": "move", "params": {"x": 1, "y": 2}, "reason": "test"},
|
||||
{"action": "place_entity", "params": {"name": "stone-furnace", "x": 1, "y": 2, "direction": "north"}},
|
||||
]
|
||||
out = AIPlanner._ensure_move_before_build_actions(actions)
|
||||
self.assertEqual([a["action"] for a in out], ["move", "place_entity"])
|
||||
|
||||
Reference in New Issue
Block a user