feat: 메모리 섹션 추가 및 상태 요약 개선

- `_append_memory_sections` 함수를 추가하여 압축 모드에서 기억된 광맥과 마지막 행동 정보를 상태 요약에 포함하도록 개선
- `main.py`에서 상태 요약 생성 시 메모리 섹션을 자동으로 추가하여 AI의 의사결정에 필요한 정보를 제공
- `README.md`에 새로운 메모리 기능 및 사용 방법에 대한 설명 추가
- `state_reader.py`에서 인벤토리 판독 로직을 개선하여 캐시 사용 조건을 명확히 하여 안정성 향상
This commit is contained in:
kswdev0
2026-03-26 10:45:30 +09:00
parent 3d118fe649
commit 153f02f5e9
4 changed files with 103 additions and 13 deletions

View File

@@ -184,21 +184,29 @@ local ok, err = pcall(function()
end
local contents = {}
meta.inv_has_get_contents = (inv.get_contents and true) or false
local used_get_contents = false
if inv.get_contents then
-- Factorio 2.0: get_contents()가 있으면 가장 안정적으로 읽음
local c = inv.get_contents()
-- 일부 환경에서 get_contents()가 nil/비테이블을 반환할 수 있음
meta.get_contents_type = type(c)
if c and type(c) == "table" then
contents = c
used_get_contents = true
local k = 0
for _ in pairs(c) do
k = k + 1
end
meta.get_contents_keys = k
contents = c
end
else
-- 호환용 폴백
end
-- 방어적 폴백:
-- get_contents()가 존재해도 빈/비정상 구조가 올 수 있어,
-- out이 완전히 비면 index 기반으로 한 번 더 시도한다.
if (not used_get_contents) or next(contents) == nil then
contents = {}
for i = 1, #inv do
local stack = inv[i]
if stack and stack.valid_for_read then
@@ -335,10 +343,13 @@ end
total = _count_total(inv)
print(f"[INV_DEBUG] main_parseOK | items={items} total={total} raw_snip={raw[:80]}")
# fallback only: RCON에서 읽어온 inv가 비어있으면 캐시 사용
# (inv가 {}인 원인이 "진짜 빈 인벤토리"든 "읽기 실패"든, 정책상 캐시 fallback을 한다)
if inv:
_save_inventory_cache(self.inventory_cache_path, inv)
# 캐시 fallback 정책:
# - 파싱이 성공(parsed_ok=True)했으면, inv가 {}여도 그대로 반환한다.
# (캐시를 덮어쓰면 실제 진행이 반영되지 않는 반복 루프가 생긴다.)
# - 파싱이 실패(parsed_ok=False)했을 때만 캐시를 사용한다.
if parsed_ok:
if inv:
_save_inventory_cache(self.inventory_cache_path, inv)
return inv
cached = _load_inventory_cache(self.inventory_cache_path)