Agents SDK Agents SDK Agents SDK · Lab 1/2 Lab 1/2 Lab 1/2 · 20 phút · 20 min · 20 នាទី

01

Bắt đầu với Agent Starter Getting Started with the Agent Starter ចាប់ផ្តើមជាមួយ Agent Starter

Tạo Agent từ Agent Starter và xem tool / schedule đi kèm. Create a new Agent using the Agent Starter and explore its functionality. បង្កើត Agent ពី Agent Starter ហើយមើល tool / schedule ដែលភ្ជាប់មក។

Nội dung bước (lệnh, code) giữ nguyên tiếng Anh từ nguồn chính thức. Step body (commands, code) stays in English from the official source. ខ្លឹមសារជំហាន (ពាក្យបញ្ជា និង code) រក្សាភាសាអង់គ្លេសពីប្រភពផ្លូវការ។ labs.cloudflare.dev ↗

Cần trước Prerequisites តម្រូវការជាមុន

  • Node.js v20+ Node.js v20+ Node.js v20+
  • Tài khoản Cloudflare Cloudflare Account គណនី Cloudflare
  • Terminal / dòng lệnh Terminal/Command Line Terminal / ពាក្យបញ្ជា
  • Biết JavaScript cơ bản Basic JavaScript knowledge ចេះ JavaScript មូលដ្ឋាន

Bạn sẽ làm được Learning objectives គោលបំណងសិក្សា

  • Nhớ Agent Framework không phụ thuộc một model Recall that the Agent Framework is model Agnostic ចងចាំថា Agent Framework មិនចាំបាច់ model តែមួយ
  • Khám phá use case chat phổ biến Explore common chat use case ស្វែងយល់ use case chat ទូទៅ
  • Chạy tool đúng như định nghĩa trong AI SDK Execute tools as defined in the AI SDK រត់ tool តាមនិយមន័យក្នុង AI SDK
  • Schedule một hành động cho tương lai Schedule an action for the future កំណត់ពេលសកម្មភាពសម្រាប់ពេលក្រោយ

Bước 1 Step 1 ជំហាន 1

Tạo Agent đầu tiên Create Your first Agent បង្កើត Agent ដំបូង

Chúng ta đang xây What we're building អ្វីដែលយើងកំពុងសង់
A Cloudflare Workers application that makes use of an Agent.
Vì sao quan trọng Why this matters ហេតុអ្វីសំខាន់
The Agent starter provides common interfaces for Agents.
txt
// Create new Agent from a template
npx create-cloudflare@latest —template cloudflare/agents-starter my-first-agent// Navigate to your new project
cd my-first-agent// Install dependencies and start development server
npm install// Update your OPENAI_API_KEY with a valid key.npm start
txt
⚡ Local server running at http://localhost:5173
  • npm not found: Install Node.js v20+ from nodejs.org
  • Permission denied: Use sudo npm install -g wrangler (macOS/Linux)
  • Build errors: Delete node_modules and run npm install again

Bước 2: Xem tool có sẵn Step 2: Explore available tools ជំហាន 2: មើល tool ដែលមាន

Chúng ta đang xây What we're building អ្វីដែលយើងកំពុងសង់
The starter shows how tools can be defined.
Vì sao quan trọng Why this matters ហេតុអ្វីសំខាន់
Agents often have tools that can run with or without human intervention.
bash
# If your local server has stopped
npm start

Khám phá tool Explore the tools ស្វែងយល់ tool

  1. Via the Chat Interface ask: What is the time in Vegas?
  1. Go explore src/tools.ts and find the implementation of getLocalTime
  1. Via the chat interface ask: What is the current weather in Las Vegas?
  1. Navigate to src/tools.ts and locate the definition of getWeatherInfomration
  1. In src/tools.ts locate the exported executions object.

Bước 3: Xem schedule task Step 3: Explore scheduling tasks ជំហាន 3: មើលការកំណត់ពេល task

Chúng ta đang xây What we're building អ្វីដែលយើងកំពុងសង់
The starter provides some tools that expose the internal scheduling API.
Vì sao quan trọng Why this matters ហេតុអ្វីសំខាន់
When you have state, and the ability to schedule, all sorts of new use cases arise.
bash
# If your local server has stopped
npm start

Xem phần triển khai Explore the implementation មើលការអនុវត្ត

  1. Via the chat interface ask for a specific timing: In twenty seconds say supdawg
  1. In src/tools.ts, note how the tools getScheduledTasks and cancelScheduledTask are using RPC methods based on the response from getCurrentAgent
  2. Via the chat interface ask to make a recurring tast: Every 15 seconds say supdawg
  1. Stop that from happening “Cancel the recurring task”

✅ Great work! You now have a functional Agent Starter that allows you to call tools both autonomously and keeping the human in the loop. You’re ready to add custom tools in Step 2!

✅ Great work! You now have a functional Agent Starter that allows you to call tools both autonomously and keeping the human in the loop. You’re ready to add custom tools in Step 2!

✅ Great work! You now have a functional Agent Starter that allows you to call tools both autonomously and keeping the human in the loop. You’re ready to add custom tools in Step 2!