refactor: split websocket flows and add brain action decision pipeline

This commit is contained in:
2026-03-02 16:04:33 +08:00
parent 4022ed8f7a
commit b5153048c4
22 changed files with 2325 additions and 2426 deletions

View File

@@ -0,0 +1,64 @@
import asyncio
async def workflow_agent_notify_flow(client, customer_id: str, acc_id: str, acc_type: str, system_hint: str):
"""图片处理完成后,让客服 AI 生成自然话术发给客户。"""
if not client.enable_agent or not client.agent:
return
try:
from core.pydantic_ai_agent import CustomerMessage
notify_msg = CustomerMessage(
msg_id="workflow_notify",
acc_id=acc_id,
msg=system_hint,
from_id=customer_id,
from_name="",
cy_id=customer_id,
acc_type=acc_type,
msg_type=0,
cy_name="",
)
response = await client.agent.process_message(notify_msg)
if response.should_reply and response.reply:
nonsense_patterns = [
"无需", "流程已完成", "不需要回复", "无需额外", "已完成",
"无需回复", "不需要额外", "已经完成", "无需再", "操作已完成",
"任务完成", "流程完成", "记录完成", "报价已",
]
if not any(p in response.reply for p in nonsense_patterns):
fake_data = {
"acc_id": acc_id,
"from_id": customer_id,
"from_name": "",
"cy_id": customer_id,
"acc_type": acc_type,
}
await asyncio.sleep(0.5)
await client.send_reply(fake_data, response.reply)
client.logger.info(f"[Workflow] AI 通知已发送: {response.reply}")
except Exception as e:
client.logger.error(f"[Workflow] AI 通知生成失败: {e}")
async def workflow_send_flow(
client,
customer_id: str,
acc_id: str,
acc_type: str,
content: str,
msg_type: int = 0,
):
"""workflow 回调图片AI完成后用此方法推送消息给客户。"""
msg = {
"msg_id": "",
"acc_id": acc_id,
"msg": content,
"from_id": customer_id,
"from_name": customer_id,
"cy_id": customer_id,
"acc_type": acc_type,
"msg_type": msg_type,
"cy_name": customer_id,
}
await client.send_message(msg)