[feat] agent: Req_Chat 슬림화 — 협상 컨텍스트를 DB 조회로 전환 + CRUD 계층 도입

- Req_Chat 을 session_id/user_input/client_step 3필드로 축소 — rq_type·목표가·앵커·품목가·
  매출액·유통코드·파트너 유형·수용률 필드 전부 제거
- NegotiationContextLoader 신설: 세션 시작 시 공유 DB 1회 조회로 컨텍스트 확정
  · rq_type = sessions.qt_type ({1,3}→재협상 / {2,4}→재견적)
  · anchor = sessions.anchoring_price(박제) — NULL 이면 무할인 폴백 anchor=target (v1.2 정책 승계)
  · 매출액 = suppliers.total_revenue(KTC 미러), 유통코드 = quotations.supplier_type 매핑
  · 파트너 유형 = 상품별 distinct supplier 수 → PartnerType enum(0=NONE/1=SINGLE/2=MULTIPLE)
- 가격 수용률은 세션 내 동적 계산: max(0, (첫 제시가−현재가)/첫 제시가)
- DB 쿼리를 backend crud 패턴으로 분리: INegoContextCRUD(ABC)+NegoContextCRUD,
  IChatSessionRepository 인터페이스 추가 (테스트 더블 주입 가능)
- 와일드카드 1% 수락 시 합의가=offer_1pct 반영 + Res_Chat.settled_price 신설 —
  backend 요약/입찰가가 이를 최우선 사용 (19,800원 수락이 20,000원으로 기록되던 버그 수정)
- backend: agent 전송 바디 3필드로 축소, 앵커/파트너 조회 메서드 제거,
  test_anchoring_chat 을 새 구조로 재작업(박제 소비/폴백 검증은 agent 테스트로 이관)
- 데모 페이지(/demo·negotiation_demo.html) 제거 — 컨텍스트 주입 경로 폐지로 무의미
- 테스트: agent 83/83, backend 57/57 (컨텍스트 로더 실데이터 왕복 4종 + CRUD 더블 검증 포함)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Fable 5 committed 2026-07-07 09:44:21 +09:00
1 parent 1ac42ddc9c
commit ed175c5b65
18 files changed
+641 -267

No files matched your search

+5 -5
View File
@@ -27,19 +27,19 @@ async def test_session_persists_and_resumes_across_instances(db_engine):
reg = _eng()
eng = await reg.get_engine("ktcommerce")
# 인스턴스 1: 협상 시작 + 몇 턴 진행
# 인스턴스 1: 협상 시작 + 몇 턴 진행 (컨텍스트는 DB 조회 — 행이 없으므로 기본값 폴백)
svc1 = ChatService()
r = await svc1.chat(eng, Req_Chat(rq_type="재협상", target_price=10000, anchor_price=8000))
r = await svc1.chat(eng, Req_Chat())
sid = r.session_id
for ui in ["확인", "예", "확인", "11000"]:
r = await svc1.chat(eng, Req_Chat(session_id=sid, user_input=ui))
step_before = r.step
assert step_before == "가격협상_확인" # 11000 제시 후 확인 단계
# DB 에 저장됐는지 확인
# DB 에 저장됐는지 확인 (기본 컨텍스트: anchor=9900)
saved = await ChatSessionRepository(eng.company_id).get(sid)
assert saved is not None and saved.step == step_before
assert saved.context["anchor_price"] == 8000
assert saved.context["anchor_price"] == 9900
# 인스턴스 2 (재시작/다른 워커 모사): 같은 session_id 로 이어가기
svc2 = ChatService()
@@ -53,7 +53,7 @@ async def test_session_company_scoped(db_engine):
reg = _eng()
eng = await reg.get_engine("ktcommerce")
svc = ChatService()
r = await svc.chat(eng, Req_Chat(rq_type="재협상"))
r = await svc.chat(eng, Req_Chat())
sid = r.session_id
# 자사(ktcommerce)로는 조회됨