# Chat API SUMMARY: การแช็ตแบบ asynchronous ระหว่าง human และ LLM agent — poll, reply, history, นับข้อความที่ยังไม่ได้อ่าน, อัปโหลดไฟล์ KEY CONTEXT: Auth: Mind Key (agent side, ?role=agent) or JWT (human side, ?role=human) Poll: GET /chat/poll (returns unread messages, marks them as read) Reply: POST /chat/reply { content } History: GET /chat/history?limit=50 Unread count: GET /chat/unread?role=agent (or ?role=human) Upload: POST /chat/upload (multipart, file attachment) Pattern: poll between tool calls, reply when human asks questions Chat API Chat API เปิดใช้งานการส่งข้อความแบบ asynchronous ระหว่าง human และ LLM agent ต่างจากการแช็ตแบบ synchronous (สไตล์ ChatGPT) ตรงที่ human สามารถฝากข้อความไว้ขณะที่ agent กำลังทำงาน — agent จะ poll ระหว่างการเรียก tool วิธีการทำงาน [CODE BLOCK] 1. Human ส่งข้อความผ่าน web UI (ใช้ JWT) 2. ข้อความถูกเก็บไว้ และทำเครื่องหมายว่ายังไม่ได้อ่าน 3. Agent poll ระหว่างการเรียก tool 4. Poll ส่งกลับข้อความที่ยังไม่ได้อ่านทั้งหมดและทำเครื่องหมายว่าอ่านแล้ว 5. Agent ประมวลผลข้อความ และอาจตอบกลับผ่าน Endpoints GET /chat/poll Poll ข้อความใหม่จาก human ส่งกลับข้อความที่ยังไม่ได้อ่านและทำเครื่องหมายว่าอ่านแล้ว ใช้ระหว่างการเรียก tool [CODE BLOCK] Response: [CODE BLOCK] POST /chat/reply ส่งข้อความในฐานะ agent [CODE BLOCK] POST /chat/send ส่งข้อความในฐานะ human (ต้องใช้ JWT ไม่ใช่ Mind Key) [CODE BLOCK] GET /chat/history ดึงประวัติแช็ตล่าสุด (ทั้งสอง role) [CODE BLOCK] GET /chat/unread นับข้อความที่ยังไม่ได้อ่าน [CODE BLOCK] GET /chat/status ดึงสถานะของ chat session (timestamp ของข้อความล่าสุด, จำนวนที่ยังไม่ได้อ่าน) [CODE BLOCK] POST /chat/upload อัปโหลดไฟล์แนบสำหรับข้อความเฉพาะ (multipart form) [CODE BLOCK] GET /chat/files/:messageid รายการไฟล์แนบสำหรับข้อความ [CODE BLOCK] GET /chat/file/:fileid ดาวน์โหลดไฟล์แนบ [CODE BLOCK] รูปแบบการ Poll > [!TIP] > Poll ทุก 30-60 วินาทีระหว่างการเรียก tool อย่า poll ถี่กว่านี้ — จะเปลือง API quota โดยไม่ได้ประโยชน์ [CODE BLOCK] ขั้นตอนถัดไป - Tasks API - Chat Polling Pattern