diff --git a/agent-office/app/agents/stock.py b/agent-office/app/agents/stock.py index f023e08..eaa1405 100644 --- a/agent-office/app/agents/stock.py +++ b/agent-office/app/agents/stock.py @@ -48,10 +48,19 @@ class StockAgent(BaseAgent): return task_id = create_task(self.agent_id, "news_summary", {"limit": 15}) - await self.transition("working", "AI 뉴스 요약 생성 중...", task_id) + await self.transition("working", "최신 뉴스 수집 중...", task_id) try: - # AI 요약 호출 (뉴스 수집 + LLM 처리는 stock-lab이 담당) + # stock-lab cron(매일 8:00)이 7:30 브리핑보다 늦게 돌아 어제 뉴스가 + # 요약되던 문제 방지 — 요약 직전에 동기 스크랩으로 DB를 갱신한다. + try: + await service_proxy.scrape_stock_news() + except Exception as e: + add_log(self.agent_id, f"뉴스 스크랩 실패 (이전 데이터로 진행): {e}", "warning", task_id) + + await self.transition("working", "AI 뉴스 요약 생성 중...") + + # AI 요약 호출 (LLM 처리는 stock-lab이 담당) result = await service_proxy.summarize_stock_news(limit=15) await self.transition("reporting", "뉴스 요약 전송 중...") diff --git a/agent-office/app/service_proxy.py b/agent-office/app/service_proxy.py index 1a372c3..194de97 100644 --- a/agent-office/app/service_proxy.py +++ b/agent-office/app/service_proxy.py @@ -31,6 +31,18 @@ async def summarize_stock_news(limit: int = 15) -> Dict[str, Any]: resp.raise_for_status() return resp.json() + +async def scrape_stock_news() -> Dict[str, Any]: + """stock-lab의 수동 뉴스 스크랩 트리거 — DB에 최신 뉴스 저장. + + 아침 브리핑 직전 호출하여 어제 데이터가 아닌 오늘 새벽 뉴스를 보장한다. + 네이버 금융 단일 요청이라 보통 수 초 내 완료, 여유있게 60s. + """ + async with httpx.AsyncClient(timeout=60.0) as client: + resp = await client.post(f"{STOCK_LAB_URL}/api/stock/scrap") + resp.raise_for_status() + return resp.json() + async def generate_music(payload: dict) -> Dict[str, Any]: resp = await _client.post(f"{MUSIC_LAB_URL}/api/music/generate", json=payload) resp.raise_for_status()