feat: 추가된 메모리 기능으로 광맥 및 마지막 행동 저장
- 에이전트가 발견한 광맥 좌표를 `ore_patch_memory.json`에 저장하여 재시작 시 활용 가능 - 마지막 실행한 행동과 결과를 `agent_last_action_memory.json`에 저장하여 다음 상태 요약에서 참고 가능 - `state_reader.py`에서 메모리 로드 및 상태 요약에 포함 - `ai_planner.py`에서 시스템 프롬프트에 기억된 광맥 및 마지막 행동 관련 가이드 추가 - `README.md`에 새로운 메모리 기능 설명 추가
This commit is contained in:
46
agent_last_action_memory.py
Normal file
46
agent_last_action_memory.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
agent_last_action_memory.py
|
||||
|
||||
에이전트를 재시작하더라도 직전에 실행했던 action 및 결과를 기억하기 위한 간단 파일 메모리.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
|
||||
LAST_ACTION_CACHE_FILE = "agent_last_action_memory.json"
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def _cache_path() -> str:
|
||||
return os.path.join(BASE_DIR, LAST_ACTION_CACHE_FILE)
|
||||
|
||||
|
||||
def load_last_action_memory() -> dict[str, Any]:
|
||||
path = _cache_path()
|
||||
try:
|
||||
if not os.path.exists(path):
|
||||
return {}
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
raw = f.read().strip()
|
||||
if not raw:
|
||||
return {}
|
||||
data = json.loads(raw)
|
||||
return data if isinstance(data, dict) else {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def save_last_action_memory(memory: dict[str, Any]) -> None:
|
||||
try:
|
||||
if not isinstance(memory, dict):
|
||||
return
|
||||
with open(_cache_path(), "w", encoding="utf-8") as f:
|
||||
json.dump(memory, f, ensure_ascii=False)
|
||||
except Exception:
|
||||
# 메모리는 부가 기능이므로 저장 실패는 전체 동작에 영향 주지 않음
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user