From 657ffdc55f8303d81e415de9e1c9fce33379633e Mon Sep 17 00:00:00 2001 From: gahusb Date: Thu, 7 May 2026 15:31:55 +0900 Subject: [PATCH] =?UTF-8?q?fix(agent-office):=20=EC=95=84=EC=B9=A8=20?= =?UTF-8?q?=EB=B8=8C=EB=A6=AC=ED=95=91=20=EC=A7=81=EC=A0=84=20=EB=89=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=8A=A4=ED=81=AC=EB=9E=A9=20=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EA=B1=B0=20=E2=80=94=20=EC=96=B4=EC=A0=9C=20=EB=89=B4=EC=8A=A4?= =?UTF-8?q?=20=EC=86=A1=EC=B6=9C=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존: stock-lab cron 스크랩(08:00)이 stock 에이전트 브리핑(07:30)보다 늦어 어제 8시 스크랩 결과만 DB에 있어 어제 뉴스가 요약·전송되었음. 수정: 에이전트 on_schedule에서 summarize 직전 /api/stock/scrap을 호출해 DB를 오늘 새벽 뉴스로 갱신한 뒤 요약. 스크랩 실패 시 경고 로그만 남기고 이전 데이터로 진행(브리핑 자체가 무산되는 것은 방지). Co-Authored-By: Claude Opus 4.7 (1M context) --- agent-office/app/agents/stock.py | 13 +++++++++++-- agent-office/app/service_proxy.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) 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()