🕷

OpenClaw AI Agent

Agent AI tự chủ — DeepSeek R1 — Quản lý tasks, lập lịch và thực thi pipeline phân tích phức tạp

192.168.1.248:18789 DeepSeek R1 MySQL tasks table Auth-protected
OpenClaw Chat Dashboard

Tổng quan

OpenClaw là một AI Agent tự chủ chạy tại máy chủ 192.168.1.248, sử dụng DeepSeek R1 (model suy luận) để xử lý các tác vụ phức tạp. Agent này có khả năng tạo và quản lý tasks, lập lịch chạy tự động, thực thi pipeline phân tích, và hỗ trợ các quyết định y tế phức tạp.

Trang web tại pnt.badt.vn giao tiếp với OpenClaw thông qua PHP proxy tại api/openclaw_proxy.php — trình duyệt không trực tiếp kết nối đến OpenClaw.

Browser
pnt.badt.vn/openclaw.php
api/openclaw_proxy.php
192.168.1.248:18789
DeepSeek R1
Graceful fallback: Khi OpenClaw offline, proxy tự động trả dữ liệu từ MySQL (tasks, task_logs, task_runs) cho Dashboard. Tính năng chat chỉ hoạt động khi OpenClaw online.

PHP Proxy API — api/openclaw_proxy.php

Tất cả requests gửi qua POST api/openclaw_proxy.php với tham số action.

Action Mô tả Tham số thêm Response
status Kiểm tra trạng thái kết nối OpenClaw {"status":"online"|"offline"}
chat Gửi tin nhắn / giao việc cho OpenClaw message, session_id (tuỳ chọn) {"response":"...","model":"...","session_id":"..."}
list_tasks Lấy danh sách tasks limit (mặc định 50), status (filter) {"tasks":[...]}
get_task Lấy chi tiết một task kèm logs và runs task_id {"task":{...},"logs":[...],"runs":[...]}
create_task Tạo task mới trong OpenClaw title, description, priority {"id":123,"status":"pending"}
cancel_task Huỷ task đang pending/running task_id {"cancelled":true}
get_task_logs Lấy logs của task (hoặc tất cả) task_id (tuỳ chọn), limit {"logs":[...]}
get_runs Lấy danh sách task_runs gần nhất task_id (tuỳ chọn), limit {"runs":[...]}
get_stats Thống kê số lượng task theo trạng thái {"stats":{"total":N,"pending":N,...}}
get_skills Lấy danh sách skills của OpenClaw (nếu có) {"skills":[...]}
get_schedules Lấy lịch chạy định kỳ (nếu có) {"schedules":[...]}
clear_history Xoá lịch sử hội thoại theo session_id session_id {"cleared":true}

Trạng thái Tasks

pending / queued / waiting
Task đã tạo, chờ worker nhận
running / in_progress / active
OpenClaw đang thực thi task
done / completed / success
Task hoàn thành thành công
failed / error
Task gặp lỗi không thể phục hồi
cancelled / canceled
Task đã bị người dùng huỷ

Ví dụ sử dụng

// Chat với OpenClaw const fd = new FormData(); fd.append('action', 'chat'); fd.append('message', 'Phân tích các task chưa xử lý và đề xuất ưu tiên'); const r = await fetch('api/openclaw_proxy.php', { method: 'POST', body: fd }); const d = await r.json(); console.log(d.response); // Phản hồi từ DeepSeek R1 // Tạo task mới const fd2 = new FormData(); fd2.append('action', 'create_task'); fd2.append('title', 'Tổng hợp báo cáo y tế tháng 6'); fd2.append('description', 'Lấy dữ liệu từ medical_transcribe và phân tích xu hướng'); fd2.append('priority', '7'); const r2 = await fetch('api/openclaw_proxy.php', { method: 'POST', body: fd2 }); const d2 = await r2.json(); console.log('Task ID:', d2.id); // → 123 // Lấy danh sách tasks đang chạy const fd3 = new FormData(); fd3.append('action', 'list_tasks'); fd3.append('status', 'running'); fd3.append('limit', '10'); const d3 = await (await fetch('api/openclaw_proxy.php', { method: 'POST', body: fd3 })).json(); d3.tasks.forEach(t => console.log(t.id, t.status));
// PHP cURL — Chat với OpenClaw function openclaw_chat(string $message): array { $ch = curl_init('https://pnt.badt.vn/api/openclaw_proxy.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query([ 'action' => 'chat', 'message' => $message, ]), CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Cookie: PHPSESSID=...'], // cần session hợp lệ CURLOPT_TIMEOUT => 120, ]); $raw = curl_exec($ch); curl_close($ch); return json_decode($raw, true) ?? []; } $result = openclaw_chat('Tạo báo cáo tổng hợp tasks tuần này'); echo $result['response']; // Kết quả từ DeepSeek R1
# Kiểm tra trạng thái OpenClaw curl -s -X POST https://pnt.badt.vn/api/openclaw_proxy.php \ -b "PHPSESSID=<session_cookie>" \ -d "action=status" # Chat curl -s -X POST https://pnt.badt.vn/api/openclaw_proxy.php \ -b "PHPSESSID=<session_cookie>" \ -d "action=chat&message=Có+bao+nhiêu+task+đang+chạy" # Tạo task mới curl -s -X POST https://pnt.badt.vn/api/openclaw_proxy.php \ -b "PHPSESSID=<session_cookie>" \ -d "action=create_task&title=Phân+tích+log+dịch+vụ&priority=5" # Lấy stats curl -s -X POST https://pnt.badt.vn/api/openclaw_proxy.php \ -b "PHPSESSID=<session_cookie>" \ -d "action=get_stats"
⚠️ Yêu cầu xác thực: Tất cả requests đến api/openclaw_proxy.php yêu cầu PHP session hợp lệ ($_SESSION['authenticated'] === true). Đăng nhập tại login.php trước khi gọi API.

Cơ sở dữ liệu

OpenClaw lưu dữ liệu vào MySQL tại 192.168.1.244:3306, database api_ai_main.

tasks
Bảng chính lưu các tasks. Các cột phổ biến:
  • id, title / name
  • status, priority
  • description, result
  • created_at, updated_at
task_logs
Log chi tiết của từng task theo thời gian.
  • id, task_id
  • level (info/warn/error)
  • message / content
  • created_at
task_runs
Mỗi lần thực thi một task (có thể chạy lại).
  • id, task_id
  • status, started_at
  • finished_at, output
  • error / error_message

Cấu hình

OpenClaw Host
192.168.1.248:18789
LLM Model
deepseek-reasoner (R1)
Config file (trên máy OpenClaw)
/home/liem/.openclaw/openclaw.json
Proxy file (trên web server)
api/openclaw_proxy.php
API tương thích
OpenAI Chat Completions
Chat endpoint
:18789/v1/chat/completions

Liên kết nhanh

OpenClaw Chat Dashboard quản lý Trang chủ