[fix] 재협상 가격협상 흐름 정비 — 무한루프·카드 연출·요약카드
agent 가격협상 무한 루프 수정 + 선행 chat_server 의 가격협상 연출(카드 스크립트 + 협상지표 게이지) 복원, 버짓 확인 입력가 표시 버그, 요약카드 공급사 담당자/날짜 표시 정비. - agent: 가격협상 루프를 라운드 상한(MAX_ROUNDS)으로 종료(카드선택 실패해도 종료 보장 — 기존엔 카드소진에만 의존해 무한 입력). chat_server iteration>=3 동작 복원. - agent: 가격협상 턴에 선택 카드 스크립트(scripts_cards.json)를 script 로 렌더 + 협상지표(indicator.py, 1~99/PZ) 산출해 indicator_value/bot_chat_type 전달. Res_Chat 에 indicator/bot_chat_type, Req_Chat 에 item_price 추가. - agent: 가격협상_확인 멘트에 할인율(discount_rate) 표시, 가격협상_확인_버짓이 target 이 아니라 입력가(input_price)를 표시하도록 수정. - backend: item_price(기존 공급가) 를 agent 로 전달. 요약카드 공급사 담당자 정보를 supplier_users(빈 이메일) 대신 partner.suppliers.manager_* 에서 조회, ChatSummary.supplier_manager_phone 추가. - frontend: 요약카드 협상 개시/종료 시각을 "YYYY년 MM월 dd일 HH시 MM분 SS초"(KST) 로, 공급 계약 만료일(+1년) ISO 파싱, 우선협상 대상자에 공급사 연락처/이메일 표시. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1630b3d20c
commit
1d4e5816b2
12 files changed
+176
-41
No files matched your search
@@ -12,6 +12,7 @@ from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.logger import LOG
|
||||
from config.server_configs import agent_config
|
||||
from negotiation.chat.service.chat_engine import ChatEngine, ChatSession, StepView
|
||||
from negotiation.chat.service.indicator import compute_indicator
|
||||
from negotiation.chat.service.chat_session_repository import ChatSessionRepository
|
||||
from negotiation.chat.service.script_repository import ScriptRepository
|
||||
from negotiation.policies.base import EpisodeState, PolicyContext, Transition
|
||||
@@ -59,20 +60,15 @@ class ChatService:
|
||||
"partner_count": req.partner_count, "acceptance_ratio": req.acceptance_ratio,
|
||||
# 앵커링값은 갑(KT/iMK)이 직접 입력한 값을 사용 (UI 기본값 = target*(1-rate)).
|
||||
"anchor_price": req.anchor_price, "target_price": req.target_price, "round": 0,
|
||||
# 기존 공급가(품목 기준가) — 가격협상_확인 인하율 산출용.
|
||||
"item_price": req.item_price,
|
||||
},
|
||||
)
|
||||
view = chat_engine.start(session)
|
||||
else:
|
||||
view = chat_engine.advance(session, req.user_input)
|
||||
|
||||
# 2) 학습 결합 (가격협상 카드선택 / 종료 보상)
|
||||
if view.error is None and engine.action_space_size > 0:
|
||||
if view.needs_card_selection:
|
||||
await self._select_and_learn(engine, session, res)
|
||||
elif view.outcome is not None:
|
||||
await self._terminal_learn(engine, session, view.outcome, res)
|
||||
|
||||
# 3) 응답
|
||||
# 2) 응답 기본 채움 (학습 블록이 가격협상 턴에서 script/indicator 를 덮어쓸 수 있어 먼저 채운다)
|
||||
res.session_id = session.session_id
|
||||
res.step = view.step
|
||||
res.client_step = view.client_step
|
||||
@@ -82,6 +78,14 @@ class ChatService:
|
||||
res.chat_end = view.chat_end
|
||||
res.outcome = view.outcome
|
||||
res.desynced = desynced
|
||||
|
||||
# 3) 학습 결합 (가격협상 카드선택 → 카드 스크립트·협상지표 / 종료 보상)
|
||||
if view.error is None and engine.action_space_size > 0:
|
||||
if view.needs_card_selection:
|
||||
await self._select_and_learn(engine, chat_engine, repo, session, res)
|
||||
elif view.outcome is not None:
|
||||
await self._terminal_learn(engine, session, view.outcome, res)
|
||||
|
||||
if view.error:
|
||||
res.result.SetResult(ErrorType.NEGO_INVALID_STEP)
|
||||
res.msg = view.error
|
||||
@@ -117,7 +121,8 @@ class ChatService:
|
||||
target_price=c["target_price"], round_number=c.get("round", 0), outcome=outcome,
|
||||
)
|
||||
|
||||
async def _select_and_learn(self, engine: TenantEngine, session: ChatSession, res: Res_Chat):
|
||||
async def _select_and_learn(self, engine: TenantEngine, chat_engine: ChatEngine,
|
||||
scripts: ScriptRepository, session: ChatSession, res: Res_Chat):
|
||||
snap = self._snapshot(session, NegotiationOutcome.ONGOING)
|
||||
try:
|
||||
idx = state_index(snap, engine.config.state)
|
||||
@@ -144,6 +149,19 @@ class ChatService:
|
||||
res.visit_count = int(policy.qtable.visits[idx, decision.action_id])
|
||||
res.reward_total = reward.total
|
||||
|
||||
# 가격협상 턴 연출(선행 chat_server 의 dynamic step type=indicator 재현):
|
||||
# ① 선택된 카드의 스크립트를 봇 메시지(script)로 출력 ② 협상지표 게이지(indicator_value) 동봉.
|
||||
# backend/front 가 indicator/bot_chat_type 패스스루·게이지 렌더 준비 완료 → 값만 채우면 표시된다.
|
||||
card_script = scripts.card_script(decision.action_id, chat_engine.vars_for(session))
|
||||
if card_script:
|
||||
res.script = card_script
|
||||
c = session.context
|
||||
ind = compute_indicator(c.get("anchor_price", 0), c.get("input_price", 0), c.get("target_price", 0))
|
||||
if ind is not None:
|
||||
res.indicator_value = float(ind[0])
|
||||
res.indicator_range = ind[1]
|
||||
res.bot_chat_type = "indicator"
|
||||
|
||||
async def _terminal_learn(self, engine: TenantEngine, session: ChatSession, outcome: str, res: Res_Chat):
|
||||
oc = NegotiationOutcome.SUCCESS if outcome == "success" else NegotiationOutcome.FAILURE
|
||||
snap = self._snapshot(session, oc)
|
||||
|
||||
Reference in new issue
Block a user