- 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>
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""에이전트 메시지 포맷팅."""
|
||
from typing import Literal, Optional
|
||
|
||
from .agent_registry import get_agent_meta
|
||
|
||
MessageKind = Literal["report", "alert", "approval", "error", "info"]
|
||
|
||
KIND_ICONS = {
|
||
"report": "📊",
|
||
"alert": "🔔",
|
||
"approval": "✋",
|
||
"error": "⚠️",
|
||
"info": "ℹ️",
|
||
}
|
||
|
||
|
||
def format_agent_message(
|
||
agent_id: str,
|
||
kind: MessageKind,
|
||
title: str,
|
||
body: str,
|
||
metadata: Optional[dict] = None,
|
||
) -> str:
|
||
meta = get_agent_meta(agent_id)
|
||
icon = KIND_ICONS.get(kind, "")
|
||
header = f"{icon} <b>[{meta['emoji']} {meta['display_name']}]</b> {title}"
|
||
|
||
lines = [header, "━" * 20, body]
|
||
|
||
if metadata:
|
||
footer_parts = []
|
||
if "tokens" in metadata:
|
||
footer_parts.append(f"🧮 {metadata['tokens']:,} tokens")
|
||
if "duration_ms" in metadata:
|
||
seconds = metadata["duration_ms"] / 1000
|
||
footer_parts.append(f"⏱ {seconds:.1f}s")
|
||
if "model" in metadata:
|
||
footer_parts.append(f"🤖 {metadata['model']}")
|
||
if footer_parts:
|
||
lines.append("")
|
||
lines.append(f"<i>{' · '.join(footer_parts)}</i>")
|
||
|
||
return "\n".join(lines)
|