[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
@@ -46,7 +46,7 @@ def _snapshot(**over) -> NegotiationSnapshot:
|
||||
|
||||
|
||||
def test_build_state_deterministic_and_in_range():
|
||||
cfg = _cfg("ktcommerce")
|
||||
cfg = _cfg("_base")
|
||||
snap = _snapshot()
|
||||
s1 = build_state(snap, cfg.state)
|
||||
s2 = build_state(snap, cfg.state)
|
||||
@@ -65,7 +65,7 @@ def test_encode_index_known_example():
|
||||
|
||||
|
||||
def test_mixed_radix_bijection_over_full_space():
|
||||
cfg = _cfg("ktcommerce")
|
||||
cfg = _cfg("_base")
|
||||
dims = state_dims(cfg.state)
|
||||
assert dims == [3, 3, 3, 3, 2]
|
||||
seen = set()
|
||||
@@ -77,17 +77,17 @@ def test_mixed_radix_bijection_over_full_space():
|
||||
|
||||
|
||||
def test_config_injection_changes_classification():
|
||||
# revenue=20,000,000 원: ktcommerce(th=[10M,50M]) → mid(1), imarketkorea(th=[30M,100M]) → low(0)
|
||||
# revenue=20,000,000 원: _base(th=[10M,50M]) → mid(1), imarketkorea(th=[30M,100M]) → low(0)
|
||||
snap = _snapshot(revenue_amount=20_000_000)
|
||||
kt = build_state(snap, _cfg("ktcommerce").state)
|
||||
base = build_state(snap, _cfg("_base").state)
|
||||
imk = build_state(snap, _cfg("imarketkorea").state)
|
||||
assert kt.revenue_idx == 1
|
||||
assert base.revenue_idx == 1
|
||||
assert imk.revenue_idx == 0
|
||||
assert kt != imk # 같은 입력이 테넌트 config 에 따라 다른 상태
|
||||
assert base != imk # 같은 입력이 테넌트 config 에 따라 다른 상태
|
||||
|
||||
|
||||
def test_distribution_unknown_code_raises():
|
||||
cfg = _cfg("ktcommerce")
|
||||
cfg = _cfg("_base")
|
||||
snap = _snapshot(distribution_code="Z") # code_map 에 없음
|
||||
try:
|
||||
build_state(snap, cfg.state)
|
||||
@@ -97,7 +97,7 @@ def test_distribution_unknown_code_raises():
|
||||
|
||||
|
||||
def test_price_zone_and_partner_buckets():
|
||||
cfg = _cfg("ktcommerce").state
|
||||
cfg = _cfg("_base").state
|
||||
# 제시가 ≤ 앵커가(9900) → 우선협상 구간(0)
|
||||
assert build_state(_snapshot(input_price=9800), cfg).price_zone_idx == 0
|
||||
# 제시가 > 앵커가 → 협상 지속 구간(1)
|
||||
@@ -110,28 +110,28 @@ def test_price_zone_and_partner_buckets():
|
||||
|
||||
def test_reward_deterministic_and_config_driven():
|
||||
snap = _snapshot(outcome=NegotiationOutcome.FAILURE, round_number=2)
|
||||
kt = _cfg("ktcommerce")
|
||||
base = _cfg("_base")
|
||||
imk = _cfg("imarketkorea")
|
||||
kt_rc = RewardCalculator(kt.reward, kt.state) # failure_penalty -0.5
|
||||
imk_rc = RewardCalculator(imk.reward, imk.state) # failure_penalty -0.7
|
||||
base_rc = RewardCalculator(base.reward, base.state) # failure_penalty -0.5
|
||||
imk_rc = RewardCalculator(imk.reward, imk.state) # failure_penalty -0.7
|
||||
|
||||
r1 = kt_rc.calculate(snap)
|
||||
r2 = kt_rc.calculate(snap)
|
||||
r1 = base_rc.calculate(snap)
|
||||
r2 = base_rc.calculate(snap)
|
||||
assert r1 == r2 # 결정론
|
||||
assert r1.end_reward == -0.5 # config 반영
|
||||
assert imk_rc.calculate(snap).end_reward == -0.7
|
||||
|
||||
# 성공 라운드 보상이 실패보다 크다 (방향성)
|
||||
success = _snapshot(outcome=NegotiationOutcome.SUCCESS, round_number=0)
|
||||
assert kt_rc.calculate(success).total > kt_rc.calculate(_snapshot(outcome=NegotiationOutcome.FAILURE, round_number=0)).total
|
||||
assert base_rc.calculate(success).total > base_rc.calculate(_snapshot(outcome=NegotiationOutcome.FAILURE, round_number=0)).total
|
||||
|
||||
|
||||
def test_action_card_mapper_roundtrip_and_mask():
|
||||
cfg = _cfg("ktcommerce")
|
||||
cfg = _cfg("_base")
|
||||
mapper = ActionCardMapper(cfg.action_mapping)
|
||||
assert mapper.action_space_size == 11
|
||||
assert mapper.get_card_id(0) == "NGC-A001"
|
||||
assert mapper.get_action_id("NGC-A001") == 0
|
||||
assert mapper.get_card_id(0) == "NGC-001"
|
||||
assert mapper.get_action_id("NGC-001") == 0
|
||||
assert mapper.get_card_id(99) is None
|
||||
|
||||
# 중복방지 마스킹: 사용한 action 제외
|
||||
|
||||
Reference in new issue
Block a user