feat: Ollama qwen3:14b 기반 AI 뉴스 요약 + 텔레그램 통합 허브
- stock-lab: POST /api/stock/news/summarize 추가 (Ollama /api/generate 호출, 토큰/duration 추적)
- agent-office: telegram 패키지 분해 (client/formatter/messaging/webhook/router/agent_registry)
- send_agent_message 통합 API로 에이전트 중립 메시지 포맷 표준화
- 텔레그램 → 에이전트 명령 라우터 (/status, /stock news, /music credits 등)
- 토큰 사용량 집계 API 및 GET /agents/{id}/token-usage
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -138,10 +138,26 @@ async def approve(body: ApprovalRequest):
|
||||
|
||||
# --- Telegram Webhook ---
|
||||
|
||||
async def _agent_dispatcher(agent_id: str, command: str, params: dict) -> dict:
|
||||
"""텔레그램 라우터가 호출하는 에이전트 디스패처."""
|
||||
# 전역 상태 조회
|
||||
if agent_id == "__global__" and command == "status":
|
||||
result = {}
|
||||
for aid, agent in AGENT_REGISTRY.items():
|
||||
result[aid] = {"state": agent.state, "detail": agent.state_detail}
|
||||
return result
|
||||
|
||||
agent = AGENT_REGISTRY.get(agent_id)
|
||||
if agent is None:
|
||||
return {"ok": False, "message": f"Unknown agent: {agent_id}"}
|
||||
return await agent.on_command(command, params or {})
|
||||
|
||||
|
||||
@app.post("/api/agent-office/telegram/webhook")
|
||||
async def telegram_webhook(data: dict):
|
||||
result = await telegram_bot.handle_webhook(data)
|
||||
if result:
|
||||
result = await telegram_bot.handle_webhook(data, agent_dispatcher=_agent_dispatcher)
|
||||
# callback_query (승인/거절) → 기존 승인 흐름
|
||||
if result and "approved" in result:
|
||||
agent = get_agent(result["agent_id"])
|
||||
if agent:
|
||||
await agent.on_approval(result["task_id"], result["approved"])
|
||||
@@ -151,6 +167,11 @@ async def telegram_webhook(data: dict):
|
||||
def all_states():
|
||||
return {"agents": get_all_agent_states()}
|
||||
|
||||
@app.get("/api/agent-office/agents/{agent_id}/token-usage")
|
||||
def agent_token_usage(agent_id: str, days: int = 1):
|
||||
from .db import get_token_usage_stats
|
||||
return get_token_usage_stats(agent_id, days)
|
||||
|
||||
@app.get("/api/agent-office/activity")
|
||||
def activity_feed(limit: int = 50, offset: int = 0):
|
||||
return get_activity_feed(limit, offset)
|
||||
|
||||
Reference in New Issue
Block a user