AI AI AI Trung cấp Intermediate កម្រិតមធ្យម ~9 phút đọc · ~691 từ ~9 min read · ~599 words

AI Agents trên Cloudflare: hơn một lần gọi chatbot AI Agents on Cloudflare: more than one chatbot call AI Agents on Cloudflare: more than one chatbot call

Chatbot một lần hỏi–đáp khác agent: agent nhớ ngữ cảnh, gọi API, chạy nhiều bước. Cloudflare gom Workers AI, Durable Objects và SDK để bạn build trên edge. A one-shot Q&A chatbot differs from an agent: agents remember context, call APIs, and run multi-step flows. Cloudflare combines Workers AI, Durable Objects, and an SDK to build at the edge. A one-shot Q&A chatbot differs from an agent: agents remember context, call APIs, and run multi-step flows. Cloudflare combines Workers AI, Durable Objects, and an SDK to build at the edge.

Hình 1: Kiến trúc AI kết hợp

Kiến trúc AI kết hợp (composable) Composable AI architecture Composable AI architecture

Ứng dụng AI có thể dựng end-to-end trên Cloudflare, hoặc gắn từng dịch vụ vào hạ tầng và dịch vụ bên ngoài. The architecture diagram illustrates how AI applications can be built end-to-end on Cloudflare, or single services can be integrated with external infrastructure and services. The architecture diagram illustrates how AI applications can be built end-to-end on Cloudflare, or single services can be integrated with external infrastructure and services.

Thuật ngữ: Concepts: Concepts: Workers AI · AI Gateway · External LLM · Composable stack

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · AI Artificial Intelligence (AI) Artificial Intelligence (AI)

Agent khác chatbot “một câu một đáp” thế nào? How is an agent different from a one-shot chatbot? How is an agent different from a one-shot chatbot?

Chatbot đơn giản: người dùng gửi prompt → mô hình trả lời → hết phiên. Agent: cùng một “nhân vật” có thể nhớ vài lượt trước, quyết định gọi công cụ (tìm kiếm nội bộ, tạo ticket, đọc D1), và lặp “suy nghĩ → hành động → quan sát” cho đến khi hoàn thành nhiệm vụ. A simple chatbot: user sends a prompt → model replies → session ends. An agent: the same “persona” may remember prior turns, decide to call tools (internal search, create a ticket, read D1), and loop “think → act → observe” until the task is done. A simple chatbot: user sends a prompt → model replies → session ends. An agent: the same “persona” may remember prior turns, decide to call tools (internal search, create a ticket, read D1), and loop “think → act → observe” until the task is done.

Các bài trên blog.cloudflare.com về agents nhấn mạnh inference (Workers AI) chỉ là một phần. Bạn cần state (trạng thái hội thoại), orchestration (điều phối bước), và guardrails (giới hạn tool) — giống nhân viên hỗ trợ thật cần sổ tay và quy trình, không chỉ miệng nói hay. Cloudflare Blog posts on agents stress that inference (Workers AI) is only one piece. You need state (conversation status), orchestration (step coordination), and guardrails (tool limits) — like a real support agent needs a playbook and process, not only eloquence. Cloudflare Blog posts on agents stress that inference (Workers AI) is only one piece. You need state (conversation status), orchestration (step coordination), and guardrails (tool limits) — like a real support agent needs a playbook and process, not only eloquence.

Trên hub, lộ trình AI Security & Adoption đặt agents sau Workers AI và AI Gateway: trước hết gọi được mô hình an toàn, sau đó mới mở rộng thành agent có tool — tránh “agent tự do” gọi API nhạy cảm không kiểm soát. On this hub, the AI Security & Adoption track places agents after Workers AI and AI Gateway: first call models safely, then expand into tool-using agents — avoiding an “autonomous” agent hitting sensitive APIs without control. On this hub, the AI Security & Adoption track places agents after Workers AI and AI Gateway: first call models safely, then expand into tool-using agents — avoiding an “autonomous” agent hitting sensitive APIs without control.

Hình 1: Kiến trúc AI kết hợp

Kiến trúc AI kết hợp (composable) Composable AI architecture Composable AI architecture

Ứng dụng AI có thể dựng end-to-end trên Cloudflare, hoặc gắn từng dịch vụ vào hạ tầng và dịch vụ bên ngoài. The architecture diagram illustrates how AI applications can be built end-to-end on Cloudflare, or single services can be integrated with external infrastructure and services. The architecture diagram illustrates how AI applications can be built end-to-end on Cloudflare, or single services can be integrated with external infrastructure and services.

Thuật ngữ: Concepts: Concepts: Workers AI · AI Gateway · External LLM · Composable stack

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · AI Artificial Intelligence (AI) Artificial Intelligence (AI)

Agents SDK và Durable Objects: trí nhớ gắn với một “phiên” Agents SDK and Durable Objects: memory tied to a session Agents SDK and Durable Objects: memory tied to a session

Workers stateless — mỗi request có thể là máy khác. Agent cần chỗ lưu hội thoại và biến nội bộ ổn định. Durable Objects (DO) cung cấp một instance có tên (ví dụ theo `userId` hoặc `roomId`) chạy liên tục logic và lưu state trong cùng object đó. Workers are stateless — each request may land on a different machine. Agents need a stable place for conversation and internal variables. Durable Objects (DO) provide a named instance (e.g. by `userId` or `roomId`) that runs logic and holds state in one place. Workers are stateless — each request may land on a different machine. Agents need a stable place for conversation and internal variables. Durable Objects (DO) provide a named instance (e.g. by `userId` or `roomId`) that runs logic and holds state in one place.

Agents SDK của Cloudflare bọc pattern phổ biến: class Agent kế thừa, hook `onRequest`, tích hợp Workers AI binding, định nghĩa tool mà mô hình được phép gọi. Bạn ít phải tự viết vòng lặp ReAct từ đầu — tập trung vào business rule và dữ liệu được phép đọc. Cloudflare’s Agents SDK wraps common patterns: extend an Agent class, hook `onRequest`, wire Workers AI bindings, define tools the model may call. You write less of a raw ReAct loop — and focus on business rules and allowed data. Cloudflare’s Agents SDK wraps common patterns: extend an Agent class, hook `onRequest`, wire Workers AI bindings, define tools the model may call. You write less of a raw ReAct loop — and focus on business rules and allowed data.

Hình dung: DO là “căn phòng” cho một cuộc chat; Workers AI là “bộ não” trong phòng; tool là “điện thoại nội bộ” chỉ gọi số đã whitelist. Không whitelist thì agent không được bấm số đó — dù mô hình muốn. Picture it: the DO is a “room” for one chat; Workers AI is the “brain” in the room; tools are an “internal phone” that only dials whitelisted numbers. No whitelist — the agent cannot dial, even if the model wants to. Picture it: the DO is a “room” for one chat; Workers AI is the “brain” in the room; tools are an “internal phone” that only dials whitelisted numbers. No whitelist — the agent cannot dial, even if the model wants to.

Workflows và chuỗi bước dài: khi agent cần “quy trình” Workflows and long chains: when agents need a “process” Workflows and long chains: when agents need a “process”

Một số tác vụ agent kéo dài phút hoặc giờ: duyệt tài liệu lớn, chờ phê duyệt người, retry API bên thứ ba. Workflows (khái niệm trên Developer Platform) giúp mô tả chuỗi bước durable — tách khỏi một HTTP request duy nhất — thay vì giữ connection mở hoặc mất state khi Worker timeout. Some agent tasks last minutes or hours: reviewing large docs, waiting for human approval, retrying third-party APIs. Workflows (a Developer Platform concept) describe durable step chains — separate from a single HTTP request — instead of holding a connection open or losing state on Worker timeout. Some agent tasks last minutes or hours: reviewing large docs, waiting for human approval, retrying third-party APIs. Workflows (a Developer Platform concept) describe durable step chains — separate from a single HTTP request — instead of holding a connection open or losing state on Worker timeout.

Bạn không cần học Workflows ngày đầu. Thứ tự hợp lý: (1) gọi Workers AI từ Worker, (2) thêm AI Gateway để log và rate limit, (3) chuyển hội thoại vào Agent + DO, (4) khi flow phức tạp, xem Workflows. Blog.cloudflare.com thường publish tính năng theo lớp — hub giúp bạn không nhảy cóc. You do not need Workflows on day one. A sensible order: (1) call Workers AI from a Worker, (2) add AI Gateway for logging and rate limits, (3) move conversation into Agent + DO, (4) when flows get complex, explore Workflows. blog.cloudflare.com often ships features in layers — the hub helps you avoid skipping steps. You do not need Workflows on day one. A sensible order: (1) call Workers AI from a Worker, (2) add AI Gateway for logging and rate limits, (3) move conversation into Agent + DO, (4) when flows get complex, explore Workflows. blog.cloudflare.com often ships features in layers — the hub helps you avoid skipping steps.

Bảo mật agent: tool scope, log và WAF cho endpoint public Securing agents: tool scope, logs, and WAF for public endpoints Securing agents: tool scope, logs, and WAF for public endpoints

Mỗi tool nên có mô tả rõ, tham số tối thiểu, và authorization kiểm tra identity trước khi đọc D1/KV. Log prompt và tool call qua AI Gateway (ẩn PII khi cần). Endpoint agent public (`/api/chat`) nên có WAF, rate limiting và — nếu có form — Turnstile cho hành vi bot. Each tool needs a clear description, minimal parameters, and authorization that checks identity before reading D1/KV. Log prompts and tool calls through AI Gateway (redact PII when needed). Public agent endpoints (`/api/chat`) deserve WAF, rate limiting, and — for forms — Turnstile against bots. Each tool needs a clear description, minimal parameters, and authorization that checks identity before reading D1/KV. Log prompts and tool calls through AI Gateway (redact PII when needed). Public agent endpoints (`/api/chat`) deserve WAF, rate limiting, and — for forms — Turnstile against bots.

Câu hỏi tự kiểm tra trước khi ship: “Agent có thể gọi tool nào mà user hiện tại không được phép?” Nếu không chắc, thu hẹp tool list và thêm test. Đọc bài Workers AI và AI Gateway trên hub, rồi mở tag agents trên blog.cloudflare.com cho ví dụ SDK mới nhất. Pre-ship self-check: “Which tools can this agent call that the current user should not access?” If unsure, narrow the tool list and add tests. Read Workers AI and AI Gateway posts on this hub, then open the agents tag on blog.cloudflare.com for the latest SDK examples. Pre-ship self-check: “Which tools can this agent call that the current user should not access?” If unsure, narrow the tool list and add tests. Read Workers AI and AI Gateway posts on this hub, then open the agents tag on blog.cloudflare.com for the latest SDK examples.

Hình minh họa Cloudflare Cloudflare visuals Cloudflare visuals

Sơ đồ Reference Architecture chính thức và (khi có) ảnh Dashboard — giúp đối chiếu khi học. Official Reference Architecture diagrams and (when available) Dashboard screenshots — useful while you learn. Official Reference Architecture diagrams and (when available) Dashboard screenshots — useful while you learn.

Kiến trúc AI đa nhà cung cấp

Quan sát và kiểm soát AI đa nhà cung cấp Multi-vendor AI observability and control Multi-vendor AI observability and control

Đưa rate limiting, cache và xử lý lỗi lên lớp proxy để áp cấu hình thống nhất cho nhiều dịch vụ và nhà cung cấp inference. By shifting features such as rate limiting, caching, and error handling to the proxy layer, organizations can apply unified configurations across services and inference service providers. By shifting features such as rate limiting, caching, and error handling to the proxy layer, organizations can apply unified configurations across services and inference service providers.

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · AI Artificial Intelligence (AI) Artificial Intelligence (AI)

Câu hỏi thường gặp Frequently asked questions Frequently asked questions

Agents SDK có bắt buộc Durable Objects không? Does the Agents SDK require Durable Objects? Does the Agents SDK require Durable Objects?

Pattern agent có state trên Cloudflare thường dùng Durable Objects để nhất quán phiên. Bạn có thể thử logic đơn giản stateless trước, nhưng hội thoại nhiều lượt thường cần DO. Stateful agent patterns on Cloudflare typically use Durable Objects for session consistency. You can prototype simple stateless logic first, but multi-turn chat usually needs DO. Stateful agent patterns on Cloudflare typically use Durable Objects for session consistency. You can prototype simple stateless logic first, but multi-turn chat usually needs DO.

Agent có thay thế Workers AI không? Do agents replace Workers AI? Do agents replace Workers AI?

Không. Workers AI cung cấp inference. Agents SDK điều phối nhiều lần gọi mô hình, nhớ context và gọi tool. Chúng bổ sung nhau. No. Workers AI provides inference. The Agents SDK orchestrates multiple model calls, memory, and tools. They complement each other. No. Workers AI provides inference. The Agents SDK orchestrates multiple model calls, memory, and tools. They complement each other.

AI Gateway có cần cho agent không? Do you need AI Gateway for agents? Do you need AI Gateway for agents?

Không bắt buộc cho prototype, nhưng production nên có: log, cache, rate limit và chính sách nhà cung cấp mô hình. Hub khuyên Gateway trước khi mở agent ra internet. Not mandatory for a prototype, but production should use it: logs, cache, rate limits, and provider policies. The hub recommends Gateway before exposing agents to the internet. Not mandatory for a prototype, but production should use it: logs, cache, rate limits, and provider policies. The hub recommends Gateway before exposing agents to the internet.

Học tiếp trên hub (on-page backlinks) Keep learning on this hub (on-page links) Keep learning on this hub (on-page links)

Nguồn tham khảo (blog.cloudflare.com) Sources (blog.cloudflare.com) Sources (blog.cloudflare.com)

Nội dung được viết lại để dễ hiểu hơn; luôn đọc bài gốc trên blog.cloudflare.com và docs chính thức khi cần chi tiết kỹ thuật hoặc cập nhật mới nhất. Content is rewritten for clarity; always read the original posts on blog.cloudflare.com and official docs for technical detail or the latest updates. Content is rewritten for clarity; always read the original posts on blog.cloudflare.com and official docs for technical detail or the latest updates.

What is Workers AI? Run AI models on Cloudflare without managing GPUs yourself
AI AI AI Cơ bản Entry កម្រិតចាប់ផ្តើម ~8 phút ~8 min ~8 នាទី

Workers AI là gì? Chạy mô hình AI trên Cloudflare mà không tự quản lý GPU What is Workers AI? Run AI models on Cloudflare without managing GPUs yourself What is Workers AI? Run AI models on Cloudflare without managing GPUs yourself

Workers AI giống thuê bếp công nghiệp đã sẵn sàng: bạn gọi món (mô hình), nhận kết quả — không phải tự xây nhà bếp GPU. Workers AI is like renting a ready commercial kitchen: you order a dish (model), get results — without building your own GPU kitchen. Workers AI is like renting a ready commercial kitchen: you order a dish (model), get results — without building your own GPU kitchen.

Đọc bài → Read post → អានអត្ថបទ →

What is AI Gateway? Control, observe, and protect AI traffic on Cloudflare
AI AI AI Trung cấp Intermediate កម្រិតមធ្យម ~8 phút ~8 min ~8 នាទី

AI Gateway là gì? Kiểm soát, quan sát và bảo vệ traffic AI trên Cloudflare What is AI Gateway? Control, observe, and protect AI traffic on Cloudflare What is AI Gateway? Control, observe, and protect AI traffic on Cloudflare

AI Gateway giống trung tâm điều phối cuộc gọi tới các “chuyên gia AI”: ghi nhật ký, giới hạn, đổi hướng — để bạn không mất kiểm soát khi app lớn dần. AI Gateway is like a switchboard for calls to AI specialists: logging, limits, routing — so you keep control as the app grows. AI Gateway is like a switchboard for calls to AI specialists: logging, limits, routing — so you keep control as the app grows.

Đọc bài → Read post → អានអត្ថបទ →

What is a WAF? Cloudflare website protection explained for non-specialists
Bảo mật Security សុវត្ថិភាព Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

WAF là gì? Bảo vệ website Cloudflare theo cách người không chuyên IT cũng hiểu What is a WAF? Cloudflare website protection explained for non-specialists What is a WAF? Cloudflare website protection explained for non-specialists

WAF giống bảo vệ cửa ra vào của website: xem ai đang gõ cửa, chặn hành vi đáng ngờ, rồi mới cho vào bên trong (origin). A WAF is like a doorman for your website: it checks who is knocking, blocks suspicious behavior, then lets safe traffic through to your origin. A WAF is like a doorman for your website: it checks who is knocking, blocks suspicious behavior, then lets safe traffic through to your origin.

Đọc bài → Read post → អានអត្ថបទ →

Xem tất cả bài blog Browse all blog posts Browse all blog posts

Chuỗi bài AI · Security · CDN · Workers · Developer Platform — viết lại cho người mới và trung cấp. AI · Security · CDN · Workers · Developer Platform — rewritten for entry and intermediate learners. AI · Security · CDN · Workers · Developer Platform — rewritten for entry and intermediate learners.