fix(agent-office): YouTubeResearchAgent 품질 개선 (동시실행 가드·에러 로깅·타입 수정)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 12:22:33 +09:00
parent 1d4354e402
commit 3b9dcfe0dd
3 changed files with 19 additions and 11 deletions

View File

@@ -1,15 +1,20 @@
# agent-office/app/agents/youtube.py
import asyncio
import logging
from datetime import date
import httpx
from .base import BaseAgent
from ..db import add_youtube_research_job, update_youtube_research_job
from ..db import add_youtube_research_job, update_youtube_research_job, add_log
from ..youtube_researcher import (
TARGET_COUNTRIES, TREND_KEYWORDS,
TARGET_COUNTRIES, TREND_KEYWORDS, MUSIC_LAB_URL,
fetch_youtube_trending, fetch_google_trends, fetch_billboard_top20,
push_to_music_lab,
)
logger = logging.getLogger(__name__)
class YouTubeResearchAgent(BaseAgent):
agent_id = "youtube"
@@ -20,6 +25,8 @@ class YouTubeResearchAgent(BaseAgent):
async def on_command(self, command: str, params: dict) -> dict:
if command == "research":
if self.state == "working":
return {"ok": False, "message": "이미 수집 중"}
countries = params.get("countries", TARGET_COUNTRIES)
asyncio.create_task(self._run_research(countries))
return {"ok": True, "message": f"리서치 시작: {countries}"}
@@ -59,15 +66,15 @@ class YouTubeResearchAgent(BaseAgent):
async def send_weekly_report(self) -> None:
"""매주 월요일 08:00 — 주간 인사이트 텔레그램 발송."""
import httpx
from ..youtube_researcher import MUSIC_LAB_URL
try:
async with httpx.AsyncClient(timeout=10.0) as client:
resp = await client.get(f"{MUSIC_LAB_URL}/api/music/market/report/latest")
if resp.status_code != 200:
return
report = resp.json()
except Exception:
except Exception as e:
add_log(self.agent_id, f"주간 리포트 조회 실패: {e}", level="error")
logger.error("send_weekly_report: music-lab 조회 실패: %s", e)
return
top = report.get("top_genres", [])[:3]
@@ -81,5 +88,6 @@ class YouTubeResearchAgent(BaseAgent):
try:
from ..telegram_bot import send_message
await send_message(text)
except (ImportError, Exception):
pass
except (ImportError, Exception) as e:
add_log(self.agent_id, f"주간 리포트 텔레그램 발송 실패: {e}", level="error")
logger.error("send_weekly_report: 텔레그램 발송 실패: %s", e)