Xây Dựng Tác Nhân Đầu Tiên

Xây Dựng Tác Nhân Đầu Tiên

Hướng dẫn này dẫn bạn qua quá trình xây dựng Tác Nhân Khôi Phục Giỏ Hàng, một tác nhân AI theo dõi giỏ hàng bỏ dở và điều phối chuỗi khôi phục được cá nhân hóa qua email, SMS và WhatsApp sử dụng công cụ MCP của Brevo.

Điều Kiện Tiên Quyết

  • Tài khoản Brevo với khóa API (lấy tại đây)
  • Máy chủ Brevo MCP đã cấu hình (hướng dẫn thiết lập)
  • Claude Desktop, Claude Code, hoặc bất kỳ client tương thích MCP
  • Mẫu email đã tạo trong Brevo cho khôi phục giỏ hàng

Tác Nhân Hoạt Động Như Thế Nào

Tác nhân là file markdown định nghĩa:

  1. Danh tính, tác nhân làm gì và các ràng buộc của nó
  2. Công cụ, công cụ MCP nào có thể truy cập
  3. Hướng dẫn, cách suy luận và hành động
  4. Rào cản, những gì không bao giờ nên làm

Bước 1: Định Nghĩa Tác Nhân

Tạo file cart-recovery-agent.md:

---
name: cart-recovery-agent
description: Recover abandoned carts with personalized multi-channel sequences
version: 1.0.0
temperature: 0.2
max_tokens: 4096
tools:
- brevo/list-contacts
- brevo/get-contact
- brevo/create-segment
- brevo/send-email
- brevo/send-sms
- brevo/track-event
- brevo/get-email-templates
- brevo/get-email-stats
triggers:
- event: cart_abandoned
conditions:
- cart_value: "> 50"
- time_since_activity: "> 30m"
- schedule: "0 */4 * * *"
permissions:
- contacts:read
- email:send
- sms:send
- events:write
---
# Cart Recovery Agent
You are an e-commerce cart recovery specialist working with Brevo's
engagement platform. Your goal is to recover abandoned carts through
personalized, well-timed multi-channel outreach.
## Strategy
When a cart is abandoned:
1. **Wait 1 hour**, then send a reminder email with cart contents
2. **Wait 24 hours**, if no open → send SMS with urgency message
3. **Wait 48 hours**, if still no recovery → send final email with
incentive (discount code if cart value > $100)
## Decision Framework
- Cart value < $50: Skip (not worth recovery cost)
- Cart value $50-$100: Email only (2 touches)
- Cart value $100-$250: Email + SMS (3 touches)
- Cart value > $250: Email + SMS + personal outreach flag
## Rules
- NEVER send more than 3 messages per abandoned cart
- NEVER contact customers who opted out of marketing
- ALWAYS check if cart was recovered before sending next step
- ALWAYS personalize with customer first name and cart items
- ALWAYS track recovery events for attribution
- Respect quiet hours: no SMS between 9pm-9am customer local time
## Email Templates
Use these Brevo template IDs:
- Reminder (step 1): template_id 101
- Urgency (step 2): template_id 102
- Incentive (step 3): template_id 103
## Metrics to Track
- `cart_recovery_email_sent`, recovery email dispatched
- `cart_recovery_sms_sent`, recovery SMS dispatched
- `cart_recovered`, customer completed purchase
- `cart_recovery_failed`, sequence completed without recovery

Bước 2: Đăng Ký Công Cụ

tools:
- brevo/list-contacts # Tìm khách hàng có giỏ hàng bỏ dở
- brevo/get-contact # Lấy thông tin khách hàng cụ thể
- brevo/create-segment # Phân khúc theo giá trị giỏ, thời gian, hành vi
- brevo/send-email # Email khôi phục giao dịch
- brevo/send-sms # SMS cho giỏ hàng giá trị cao
- brevo/track-event # Ghi lại các lần thử và kết quả khôi phục
- brevo/get-email-stats # Kiểm tra email có được mở không
- brevo/get-email-templates # Xác minh mẫu tồn tại

Bước 3: Kiểm Tra Tác Nhân

Với Claude Desktop

Sau khi cấu hình máy chủ Brevo MCP, hỏi Claude:

Chạy tác nhân khôi phục giỏ hàng của tôi. Kiểm tra giỏ hàng bỏ dở trên $50 trong 4 giờ qua và thực hiện chuỗi khôi phục.

Thực Thi Lập Trình

import { TajoAgent } from "@tajo/agent-sdk";
import { BrevoMCPServer } from "@tajo/brevo-mcp-server";
const brevo = new BrevoMCPServer({
apiKey: process.env.BREVO_API_KEY,
});
const agent = new TajoAgent({
specPath: "./cart-recovery-agent.md",
mcpServers: [brevo],
model: "claude-sonnet-4-6",
});
const result = await agent.run(
"Recover abandoned carts over $50 from the last 4 hours"
);
console.log(result.summary);

Bước 4: Lên Lịch Tác Nhân

triggers:
- schedule: "0 */4 * * *" # Mỗi 4 giờ
timezone: "America/New_York"

Các Bước Tiếp Theo

Subscribe to updates

developer-docs

Drop your email or phone number — we'll send you what matters next.

Trợ lý AI

Xin chào! Hãy hỏi tôi về tài liệu.

Bắt đầu miễn phí với Brevo