PON Module A — Luồng một câu hỏi @AI (chat-service → ai-service → client)

PON Module A — Luồng một câu hỏi @AI (chat-service → ai-service → client) A workflow diagram generated by Archify. 01 / Người dùng · Web / Flutter 02 / chat-service (Spring Boot :8080) 03 / RabbitMQ 04 / Dữ liệu: MongoDB · Voyage + Qdrant 05 / ai-service · pipeline (NestJS :3002) 06 / ai-service · agentic loop & tools 07 / API ngoài EX / Nhánh lỗi → AI_STREAM_ERROR Nhận & giao job Kiểm tra · gom context · chọn model Chạy model · tool · trả lời Gõ @AI · hoặc chat 1-1 với bot · Người dùng · Web / Flutter › Nhận & giao job · /app/chat.send Gõ @AI hoặc chat 1-1 với bot /app/chat.send Bubble AI · chunk → text · Sources · Người dùng · Web / Flutter › Chạy model · tool · trả lời · ghép theo replyId Bubble AI chunk → text · Sources ghép theo replyId ChatController · regex @AI, chỉ text · chat-service (Spring Boot :8080) › Nhận & giao job · isDirectAiConversation ChatController regex @AI, chỉ text isDirectAiConversation AiRedisPublisher · 20 tin + role/depts · chat-service (Spring Boot :8080) › Nhận & giao job · async AiRedisPublisher 20 tin + role/depts async AiResponseListener · relay STOMP · persist · chat-service (Spring Boot :8080) › Chạy model · tool · trả lời · claim replyId AiResponseListener relay STOMP · persist claim replyId RabbitMQ · queue ai.requests · RabbitMQ › Nhận & giao job · TTL 30s · DLQ RabbitMQ queue ai.requests TTL 30s · DLQ MongoDB · ai_sessions · usage · Dữ liệu: MongoDB · Voyage + Qdrant › Nhận & giao job · trí nhớ ngắn hạn MongoDB ai_sessions · usage trí nhớ ngắn hạn Voyage + Qdrant · ai_memory · knowledge · Dữ liệu: MongoDB · Voyage + Qdrant › Kiểm tra · gom context · chọn model · BM25 + vector Voyage + Qdrant ai_memory · knowledge BM25 + vector dispatch · 5 cửa kiểm tra · ai-service · pipeline (NestJS :3002) › Nhận & giao job · rồi mở session dispatch 5 cửa kiểm tra rồi mở session ContextBuilder · org · memory · RAG · group · ai-service · pipeline (NestJS :3002) › Kiểm tra · gom context · chọn model · + router 3 tier ContextBuilder org · memory · RAG · group + router 3 tier finish · DONE · session · usage · ai-service · pipeline (NestJS :3002) › Kiểm tra · gom context · chọn model · fact turn 3, mỗi 10 finish DONE · session · usage fact turn 3, mỗi 10 Redis pub/sub · ai:response:{conv} · ai-service · pipeline (NestJS :3002) › Chạy model · tool · trả lời · replyId mọi event Redis pub/sub ai:response:{conv} replyId mọi event AgenticLoop · stream → CHUNK tức thì · ai-service · agentic loop & tools › Kiểm tra · gom context · chọn model · ≤ 5 lượt AgenticLoop stream → CHUNK tức thì ≤ 5 lượt Tool thường · search_* · reminder · mcp · ai-service · agentic loop & tools › Chạy model · tool · trả lời · fence UNTRUSTED Tool thường search_* · reminder · mcp fence UNTRUSTED Tool nhạy cảm · card chờ xác nhận · ai-service · agentic loop & tools › Chạy model · tool · trả lời · Redis TTL 600s Tool nhạy cảm card chờ xác nhận Redis TTL 600s Claude / OpenRouter · Haiku · Sonnet · Opus · API ngoài › Kiểm tra · gom context · chọn model · stream Claude / OpenRouter Haiku · Sonnet · Opus stream connector-service · /internal/tools · API ngoài › Chạy model · tool · trả lời · Notion · Google · MCP connector-service /internal/tools Notion · Google · MCP Từ chối sớm · FORBIDDEN · QUOTA · RATE · Nhánh lỗi → AI_STREAM_ERROR › Nhận & giao job · không dead-letter Từ chối sớm FORBIDDEN · QUOTA · RATE không dead-letter Model lỗi · chưa chữ → Haiku tiếp · Nhánh lỗi → AI_STREAM_ERROR › Kiểm tra · gom context · chọn model · đã chữ → INTERRUPTED Model lỗi chưa chữ → Haiku tiếp đã chữ → INTERRUPTED prompt + tools memory + RAG khớp @AI DONE đạt · embed session không đạt STOMP topic mỗi lượt end_turn lỗi / 529 tool_use publish consume SUBSCRIBE mcp__* tool_result sensitive? tin nhắn text Legend User UI Agent logic Policy Tool action Context / trace Cloud service External system