초기 커밋 — 협상 AI 에이전트 정본: 엔진·데모 콘솔·측정 인프라·증빙

- server/: FastAPI 협상 엔진 (5라운드, Q-Table/UCB, 페르소나 계측, :53117)
- frontend/: 데모 콘솔 (React+Tailwind → nginx, /api 프록시)
- eval/·testdata/: 지표 8종 측정 하네스 + 재현 가능 테스트셋
- results/: 측정 증빙 (지표별 result+provenance, raw 원본 동결+SHA256)
  ① 86.0 · ② 76.0 · ③ 5.99% · ⑥ p95 3.61ms · ⑦ 611만/년 · ⑧ 91/100 · ⑨ 99.71 · ⑩ 97.99
- docker-compose.yml + run.sh: backend+frontend 일괄 기동

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0112XUWF4bc3gGrEt8vsYCzy
This commit is contained in:
민헌andClaude Fable 5 committed 2026-08-31 13:09:52 +09:00
commit dfb9ad6e66
268 files changed
+164241

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
# NEGO_AGENT 서버
협상 에이전트 경량 서버 — 성능지표 측정용. KT 비종속 독립 프로젝트.
- 아키텍처: prism/backend 패턴 (router/services/common/config)
- 엔진 로직: 협상 카드 Q-Table 추론 + 스텝 기반 대화 (학습·DB 경로 없음)
- 평가환경: Python 3.10 / Ubuntu 20.04 (Dockerfile) — 로컬 개발은 상위 버전 무방
## 실행
```bash
# 로컬
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/python web_main.py # → http://localhost:53117/docs
# 테스트
.venv/bin/python -m pytest tests/
# Docker (평가환경 재현: Ubuntu 20.04 + Python 3.10)
docker build -t nego-agent .
docker run -p 53117:53117 -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]` 포트 53117
- `[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 지칭 제거 (스크립트 리소스의 브랜딩 문구 중립화 포함)