fix(agent-office): 아침 브리핑 직전 뉴스 스크랩 트리거 — 어제 뉴스 송출 방지
기존: 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) <noreply@anthropic.com>
This commit is contained in:
@@ -48,10 +48,19 @@ class StockAgent(BaseAgent):
|
|||||||
return
|
return
|
||||||
|
|
||||||
task_id = create_task(self.agent_id, "news_summary", {"limit": 15})
|
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:
|
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)
|
result = await service_proxy.summarize_stock_news(limit=15)
|
||||||
|
|
||||||
await self.transition("reporting", "뉴스 요약 전송 중...")
|
await self.transition("reporting", "뉴스 요약 전송 중...")
|
||||||
|
|||||||
@@ -31,6 +31,18 @@ async def summarize_stock_news(limit: int = 15) -> Dict[str, Any]:
|
|||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp.json()
|
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]:
|
async def generate_music(payload: dict) -> Dict[str, Any]:
|
||||||
resp = await _client.post(f"{MUSIC_LAB_URL}/api/music/generate", json=payload)
|
resp = await _client.post(f"{MUSIC_LAB_URL}/api/music/generate", json=payload)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|||||||
Reference in New Issue
Block a user