Skip to content

refactor(agent): extract RateLimiterControlMixin (955 → 865 LOC)#39

Merged
unohee merged 1 commit into
mainfrom
refactor/agent-rate-limiter-mixin
Jun 4, 2026
Merged

refactor(agent): extract RateLimiterControlMixin (955 → 865 LOC)#39
unohee merged 1 commit into
mainfrom
refactor/agent-rate-limiter-mixin

Conversation

@unohee

@unohee unohee commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

`kis_agent/core/agent.py` (955 LOC)의 Rate Limiter 제어 메서드 4개를 `RateLimiterControlMixin`으로 분리.

Changes

파일 변경
`kis_agent/core/rate_limiter_mixin.py` (NEW, 127 LOC) `get_rate_limiter_status`, `set_rate_limits`, `reset_rate_limiter`, `enable_adaptive_rate_limiting` 4개 메서드를 담은 Mixin
`kis_agent/core/agent.py` (955 → 865 LOC) `RateLimiterControlMixin` 상속 추가, 동일 4개 메서드 본체 제거

분리 근거

  • 4개 메서드 모두 `self.rate_limiter`에만 의존, 다른 도메인 API와 결합 0
  • 모두 단순 위임 layer (예외 처리·비활성 경고 외 로직 없음)
  • 기존 `TechnicalAnalysisMixin` / `MethodDiscoveryMixin`과 동일 컨벤션 — Agent의 인프라 제어 코드를 도메인 API 코드와 분리

다른 800+ LOC 파일 평가 (분리 보류)

파일 LOC 결정 사유
`websocket/ws_agent.py` 1557 단일 WS connection lifecycle — state passing 비용으로 분리 시 복잡도 ↑
`websocket/client.py` 1494 deprecated 모듈 — touch 시 호환성 리스크
`stock/price_api.py` 1343 시세 단일 도메인의 KIS API 1:1 매핑 (39개 메서드, 도크스트링 밀도 높음)
`cli/main.py` 1276 argparse 진입점 — cmd 함수 분리 시 dispatch 테이블/import 사이클 위험
`stock/api_facade.py` 817 완전 위임 파사드 — sub-facade 재분리는 사용자 검색성 손상
`responses/overseas.py` 840 TypedDict 정의 모음 — 본질적으로 데이터 정의

공개 API 영향

없음. `agent.get_rate_limiter_status()` 등 사용자 호출 방식 동일. Agent.__mro__에 Mixin 한 단계 추가.

Test plan

  • `pytest tests/unit/test_agent.py test_agent_unit_comprehensive.py test_rate_limiter.py` — 49 passed
  • `ruff check` — All checks passed
  • Agent.__mro__에 RateLimiterControlMixin 포함 확인
  • 4개 메서드 모두 agent.* 로 접근 가능 확인

…5 LOC)

agent.py에서 Rate Limiter 제어 메서드 4개를 별도 Mixin으로 분리.

분리 대상 (kis_agent/core/rate_limiter_mixin.py):
- get_rate_limiter_status() — 상태 조회
- set_rate_limits()           — 제한 값 동적 변경
- reset_rate_limiter()        — 통계/백오프 초기화
- enable_adaptive_rate_limiting() — 적응형 속도 조절 토글

분리 근거:
- 4개 메서드 모두 self.rate_limiter에만 의존, 다른 도메인 API와 결합 없음
- 모두 단순 위임 layer (예외 처리·비활성 경고 외 로직 없음)
- 기존 TechnicalAnalysisMixin / MethodDiscoveryMixin과 동일한 컨벤션
- Agent 클래스에서 도메인 API 코드와 인프라 제어 코드 분리

공개 API 영향 없음:
- agent.get_rate_limiter_status() 등 사용자 호출 방식 동일
- Agent.__mro__: [Agent, TechAnalysisMixin, MethodDiscoveryMixin,
  RateLimiterControlMixin, BaseExceptionHandler, object]

검증:
- pytest tests/unit/test_agent.py tests/unit/test_agent_unit_comprehensive.py
  tests/unit/test_rate_limiter.py: 49/49 passed
- ruff check: All checks passed
@unohee unohee merged commit f4ae370 into main Jun 4, 2026
6 checks passed
@unohee unohee deleted the refactor/agent-rate-limiter-mixin branch June 4, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant