Files
tw/core/engine.py
2026-03-06 13:23:32 +08:00

39 lines
1.3 KiB
Python

import logging
from typing import Optional, Any
from core.schema import StandardMessage, StandardResponse
from core.events.event_bus import bus
logger = logging.getLogger("cs_agent")
class BusinessEngine:
"""
业务逻辑中枢(备用引擎,主流程由 Orchestrator + Brain 处理)。
仅在 Orchestrator 不可用时作为降级方案。
"""
def __init__(self, agent_instance: Any = None):
self.agent = agent_instance
async def handle_message(self, msg: StandardMessage) -> StandardResponse:
content = (msg.content or "")
logger.info(f"[Engine] 收到来自 {msg.platform} 的消息: {msg.user_id} -> {content[:50]}")
return StandardResponse(
reply_content="稍等哈,设计师马上来。",
metadata={"acc_id": msg.acc_id, "acc_type": msg.acc_type}
)
async def emit_image_result(self, user_id: str, platform: str, url: str, acc_id: str):
"""
这是一个业务触发器示例:当图片处理完成时,由 Engine 主动发广播。
"""
await bus.emit(
"MESSAGE_OUTBOUND",
user_id=user_id,
platform=platform,
response=StandardResponse(
reply_content=url,
msg_type=1, # 图片
metadata={"acc_id": acc_id}
)
)