[feat] agent: 협상 고도화 — LLM 표현/이해층 + 카드 전술 실행계층 + ktcommerce 정리
카드 재설계("멘트 카드 → 전술 카드"):
- tactics.py 신설: 카드번호→전술(카운터 산식) 레지스트리, min(counter,target) 클램프
- 카운터 수락=즉시 타결(pending_counter_price 일반화, 구 offer_1pct 흡수)
- 목표가 초과 타결 금지(성공스텝 진입 가드) + "카드 소진=실패" 폐지→종결 국면
- 선택형 와일드카드(WC-*) 발동 + card.wild_cards 멘트 DB 어댑터
LLM 계층:
- Phase 2 표현층 ScriptNaturalizer(카드 멘트 자연화, 마커·치환자·숫자 보존 검증)
- Phase 3 이해층 InputInterpreter(자유발화 NLU→기대입력, 한국어 가격 파서)
- OPENAI_API_KEY env override(server_configs) + 전역 자격증명 게이트
결정 스택(Phase 1):
- 협상 규칙 데이터화(negotiation.wildcard_*_ratio/max_counter_rounds)
- 선택카드 우선순위 prior(UCB 방문수 감쇠, Q-table 오염 없음)
버그픽스:
- 인하율 음수 표기 제거 + 인상/동일/인하 구분(discount_phrase)
- 자연화 강조마커 보존(볼드/색 소실 시 원본 폴백)
- 카드 시드 가격변수(prev_partner_price·target_mid_price·middle_price 등) 치환
정리:
- ktcommerce 테넌트 삭제 + 테스트 21파일 imarketkorea/_base 로 마이그레이션
- 실 LLM 호출 차단 conftest 가드
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b368a19f79
commit
1682481b01
46 files changed
+2091
-240
No files matched your search
@@ -20,7 +20,7 @@ _TENANTS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__fi
|
||||
_FORBIDDEN = re.compile(r"kt\s*commerce|케이티|커머스|nego-?wiz", re.IGNORECASE)
|
||||
|
||||
|
||||
def _repo(tenant_id="ktcommerce"):
|
||||
def _repo(tenant_id="imarketkorea"):
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load(tenant_id)
|
||||
return ScriptRepository(cfg, _TENANTS_DIR)
|
||||
|
||||
@@ -65,11 +65,9 @@ def test_cleanroom_no_proprietary_brand_in_any_resource():
|
||||
|
||||
|
||||
def test_brand_substitution_per_tenant():
|
||||
kt = _repo("ktcommerce").get_step("서비스안내", "재협상")
|
||||
im = _repo("imarketkorea").get_step("서비스안내", "재협상")
|
||||
assert "데모상사 A" in kt["script"] and "Negosium" in kt["script"]
|
||||
assert "데모상사 B" in im["script"]
|
||||
assert "{company_name}" not in kt["script"] # 치환 완료
|
||||
assert "데모상사 B" in im["script"] and "Negosium" in im["script"]
|
||||
assert "{company_name}" not in im["script"] # 치환 완료
|
||||
|
||||
|
||||
def test_variable_substitution_and_missing_kept():
|
||||
@@ -103,12 +101,16 @@ async def test_resolve_card_script_file_mode_default():
|
||||
repo = _repo()
|
||||
assert repo._config.cards.source_type == "file"
|
||||
# action 0 파일 멘트가 변수 치환되어 나온다 (DB 무접근)
|
||||
out = await repo.resolve_card_script(0, "NGC-A001", {"input_price": 9800})
|
||||
out = await repo.resolve_card_script(0, "NGC-B001", {"input_price": 9800})
|
||||
assert out and "9800" in out
|
||||
|
||||
|
||||
class _FakeCardRepo:
|
||||
"""ICardScriptRepository 더블 — DB 없이 카드코드→멘트 매핑만 흉내(세션 인자 무시)."""
|
||||
from negotiation.cards.ports.card_script_port import ICardScriptRepository
|
||||
|
||||
|
||||
class _FakeCardRepo(ICardScriptRepository):
|
||||
"""ICardScriptRepository 더블 — DB 없이 카드코드→멘트 매핑만 흉내(세션 인자 무시).
|
||||
포트 상속으로 get_card_by_number 기본 구현(메타 None)을 물려받는다."""
|
||||
|
||||
def __init__(self, by_number: dict):
|
||||
self._by = by_number
|
||||
@@ -121,9 +123,9 @@ class _FakeCardRepo:
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_card_script_db_mode_prefers_db(monkeypatch):
|
||||
"""source_type='backoffice_db': card.nego_cards.script(정본)를 파일보다 우선 사용 + 마커 보존."""
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load("ktcommerce")
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load("imarketkorea")
|
||||
cfg.cards.source_type = "backoffice_db"
|
||||
fake = _FakeCardRepo({"NGC-A001": "DB 편집 멘트 **{input_price}원** 검토 중입니다."})
|
||||
fake = _FakeCardRepo({"NGC-B001": "DB 편집 멘트 **{input_price}원** 검토 중입니다."})
|
||||
repo = ScriptRepository(cfg, _TENANTS_DIR, card_repo=fake)
|
||||
|
||||
# execute_lambda 를 세션 없이 콜백만 실행하도록 대체(순수 단위검증)
|
||||
@@ -132,14 +134,14 @@ async def test_resolve_card_script_db_mode_prefers_db(monkeypatch):
|
||||
from negotiation.chat.service import script_repository as _sr
|
||||
monkeypatch.setattr(_sr.DB_SESSION_MNG, "execute_lambda", _fake_lambda)
|
||||
|
||||
out = await repo.resolve_card_script(0, "NGC-A001", {"input_price": 9800})
|
||||
out = await repo.resolve_card_script(0, "NGC-B001", {"input_price": 9800})
|
||||
assert out == "DB 편집 멘트 **9800원** 검토 중입니다." # DB 우선 + 마커(**) 불투명 보존 + 변수 치환
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_card_script_db_mode_falls_back_to_file(monkeypatch):
|
||||
"""DB 에 해당 카드 멘트가 없으면 파일(scripts_cards.json)로 폴백."""
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load("ktcommerce")
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load("imarketkorea")
|
||||
cfg.cards.source_type = "backoffice_db"
|
||||
fake = _FakeCardRepo({}) # DB 미보유
|
||||
repo = ScriptRepository(cfg, _TENANTS_DIR, card_repo=fake)
|
||||
@@ -149,14 +151,14 @@ async def test_resolve_card_script_db_mode_falls_back_to_file(monkeypatch):
|
||||
from negotiation.chat.service import script_repository as _sr
|
||||
monkeypatch.setattr(_sr.DB_SESSION_MNG, "execute_lambda", _fake_lambda)
|
||||
|
||||
out = await repo.resolve_card_script(0, "NGC-A001", {"input_price": 9800})
|
||||
out = await repo.resolve_card_script(0, "NGC-B001", {"input_price": 9800})
|
||||
assert out and "9800" in out # 파일 폴백 멘트
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_card_script_prefer_db_for_selected_cards(monkeypatch):
|
||||
"""견적에서 선택된 백오피스 카드 번호는 file 모드여도 DB 멘트를 우선한다."""
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load("ktcommerce")
|
||||
cfg = TenantConfigLoader(tenants_dir=_TENANTS_DIR, cache_ttl_seconds=0).load("imarketkorea")
|
||||
assert cfg.cards.source_type == "file"
|
||||
fake = _FakeCardRepo({"2": "선택 카드 DB 멘트 **{input_price}원**"})
|
||||
repo = ScriptRepository(cfg, _TENANTS_DIR, card_repo=fake)
|
||||
|
||||
Reference in new issue
Block a user