Luồng thực thi toàn hệ thống: Web App & Voice AI Agent (Modal / Qwen)
React Router render ShopPage component
GET /wp-json/wc/v3/products → parse JSON
category / price / sort → filteredProducts state → re-render
CartItem[] → AppContext → localStorage persist
Load cart items từ AppContext
firstName / lastName / phone / address / city...
COD / SePay QR / Chuyển khoản
/wp-json/wc/v3/orders → nhận Order ID
username + password → WordPress JWT
OTP (email) hoặc Voice ID
OTP 6 chữ số / Voice biometrics matching
userProfile set → Dashboard access
{ message, history[-20], context }
page / cart / user / selectedProduct
10 turns / 50 000 tokens max
2 tools: search_products, search_knowledge
max_tokens: 512 → fast response
"tool_calls" → execute tools
"stop" → skip to synthesis
Max 2 tools per iteration
E5-large embed → ChromaDB query
Top 5 products / Top 3 knowledge docs
Build synthesis prompt với context từ tools
thinking: OFF, max_tokens: 1024
Stop streaming khi gặp <json> tag
text_chunk → action → sources → done
Extract từ <json>…</json> trong LLM text
30+ valid actions → fallback "chat" nếu unknown
"actions": [] → sequential execution plan
data: {"type":"action","action":"search",...}
VAD phát hiện giọng trong 85–3400 Hz band
transcript = "Tìm thuốc ho" → isFinal = true
3 ký tự unicode, không phải filler → OK
VoiceAgentContext kích hoạt pipeline
{ message: "Tìm thuốc ho", history, context }
Qwen → finish_reason: "tool_calls"
→ search_products(query="thuốc ho")
E5 embed → top 5 products, similarity ≥ 0.3
Inject kết quả → tạo câu trả lời + action JSON
payload: { query: "thuốc ho" } về Frontend
→ AgentIntent { type: "search", entities: {...} }
setSearchQuery("thuốc ho") → filteredProducts update → ShopPage re-render
"Tôi đã tìm thấy X sản phẩm thuốc ho..."
→ resume listening sau 500ms