Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFZ7JWdwCaQAwNYJErL8pP
NEGO_AGENT 서버
협상 에이전트 경량 서버 — 성능지표 측정용. KT 비종속 독립 프로젝트.
- 아키텍처: prism/backend 패턴 (router/services/common/config)
- 엔진 로직: 협상 카드 Q-Table 추론 + 스텝 기반 대화 (학습·DB 경로 없음)
- 평가환경: Python 3.10 / Ubuntu 20.04 (Dockerfile) — 로컬 개발은 상위 버전 무방
실행
# 로컬
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python web_main.py # → http://localhost:3300/docs
# 테스트
.venv/bin/python -m pytest tests/
# Docker (평가환경 재현: Ubuntu 20.04 + Python 3.10)
docker build -t nego-agent .
docker run -p 3300:3300 -e OPENAI_API_KEY=sk-... nego-agent
API
| 엔드포인트 | 설명 |
|---|---|
GET /health |
상태 확인 |
POST /v1/nego/chat |
협상 대화 (고정 스텝 + '가격협상' 동적 카드 선택) |
POST /v1/nego/session/invalidate |
세션 무효화 — UCB 에피소드 초기화 |
GET /v1/nego/config |
서버 설정 상태 (profiling on/off·카드 수 등) |
설정 — config.toml 하나 (환경 구분 없음)
[server]포트 3300[openai]모델·API 키 (비우면OPENAI_API_KEY환경변수)[profiling]N-profiling(LLM 톤 변환) on/off — 요청 body의profiling: true/false로 건별 override. 키가 없으면 자동 비활성으로 기동[instrument]계측 경로 — 비우면 끔tension_log: ⑩ 예측 긴장도 JSONL (가격협상 진입마다 기록)response_time_log: ⑥ 답변속도 JSONL (/chat 요청·응답 ms)
구조
server/
├── web_main.py # 진입점
├── config.toml # 단일 설정
├── config/ # 설정 모델·로더
├── common/ # paths·logger·enums·textutil(치환/Hidden 처리)
├── router/
│ ├── router.py # 앱 조립 + 응답시간 미들웨어
│ └── v1/nego/ # protocol(스키마)·chat·admin
├── services/
│ ├── negotiation/ # engine(ChatEngine)·orchestrator·formatting·indicator·steps·korean
│ ├── policy/ # state(162)·q_table·visit_table·ucb·selector·snapshot
│ ├── cards/ # repository(JSON)·mapper(action↔card)·completer
│ └── profiling/ # ScriptModifier(OpenAI)·ScriptVerifier — on/off
├── resources/ # cards/(협상·와일드 카드 정본), scripts/(스텝 스크립트), policy/(q_table·매핑)
├── data/ # 런타임 산출 (tension_log·response_time JSONL)
└── tests/ # 스모크 테스트
원본(chat_server) 대비 변경점
- DB(PostgreSQL/SQLAlchemy)·Q-학습 경로·관리 엔드포인트 제거 — JSON 파일이 유일한 저장소
- N-profiling 정상 패키지화(dynamic import 제거), langchain → openai SDK 직접 호출, 평문 입출력
- 세션 경계 자동 감지 → UCB 에피소드 초기화 (기존 reset_episode 미호출로 인한 카드 라운드로빈 수정)
- 긴장도(TENSION_LOG env)·응답시간 계측을 config 정식 설정으로 내장
- KT 지칭 제거 (스크립트 리소스의 브랜딩 문구 중립화 포함)