Week 10 of 12 🤖

Subagents & Task Delegation

Subagents และการมอบหมายงาน

Subagents 与任务分派

Subagents & Task Delegation

1. Introduction / บทนำ / 简介

Subagents คือผู้ช่วย AI เฉพาะทางที่ Claude สร้างขึ้นเพื่อจัดการงานเฉพาะ ประเภทในตัว ได้แก่ Explore (ค้นหาเร็ว), Plan (สถาปัตยกรรม) และ general-purpose (เครื่องมือครบ) คุณยังสร้าง subagents ที่กำหนดเองสำหรับโปรเจกต์ได้
Subagents 是 Claude 可以派生出来处理特定任务的专门 AI 助手。内置类型包括 Explore(快速搜索)、Plan(架构规划)和 general-purpose(全套工具)。你还可以为自己的项目创建自定义 subagents。
Subagents are specialized AI assistants that Claude can spawn to handle specific tasks. Built-in types include Explore (fast search), Plan (architecture), and general-purpose (full tools). You can also create custom subagents for your project.

Fun Facts / ข้อเท็จจริงที่น่าสนใจ / 趣味知识

  • Explore agents use Haiku for speed — they're read-only!
  • Custom subagents are defined as Markdown files with frontmatter.
  • Background agents auto-approve permissions so they don't block.
Hundreds of weaver ants building a nest from leaves
Weaver ants building a nest: many small workers, one shared task — like subagents. — Photo: VinetVas17, CC BY-SA 4.0, via Wikimedia Commons

2. Vocabulary / คำศัพท์ / 词汇

Click a card to flip it. คลิกการ์ดเพื่อพลิก 点击卡片翻面。

agent
เอเจนต์
智能体
An AI assistant that works on tasks
subagent
ซับเอเจนต์
子智能体
A helper agent spawned by the main agent
delegate
มอบหมาย
分派
To give a task to someone else
parallel
ขนาน
并行
Running multiple tasks at the same time
background
พื้นหลัง
后台
Running without blocking the main task
foreground
เบื้องหน้า
前台
The currently active and visible task
worktree
เวิร์กทรี
工作树
An isolated copy of a git repository
spawn
สร้าง / เรียก
派生
To create a new subagent
isolation
การแยก
隔离
Keeping things separate to avoid conflicts
task
งาน
任务
A specific piece of work to be done
inherit
สืบทอด
继承
To receive settings from a parent
custom
กำหนดเอง
自定义
Created by the user for specific needs

3. Grammar Focus / ไวยากรณ์ / 语法焦点

Passive Voice (is assigned, was completed) / Passive Voice (is assigned, was completed) / 被动语态(is assigned、was completed)

Thai:
Passive voice เน้นการกระทำหรือผลลัพธ์ ไม่ใช่ผู้ทำ รูปแบบ: be + กริยาช่อง 3 ตัวอย่าง: 'The task is assigned to a subagent.' (ไม่เน้นว่าใครมอบหมาย) Active: 'Claude assigns the task.'
中文:
被动语态强调动作或结果,而不是执行者。形式:be + 过去分词。例如:'The task is assigned to a subagent.'(任务被分派给一个 subagent。我们不关注是谁分派的。)主动语态:'Claude assigns the task.'(Claude 分派任务。)
English:
Passive voice emphasizes the action or result, not who does it. Form: be + past participle. Example: 'The task is assigned to a subagent.' (We don't focus on who assigned it.) Active: 'Claude assigns the task.'
งานถูกมอบหมายให้ subagent
任务被分派给一个 subagent。
The task is delegated to a subagent.
Custom agents ถูกกำหนดในไฟล์ Markdown
自定义 agents 在 Markdown 文件中定义。
Custom agents are defined in Markdown files.
ผลลัพธ์ถูกส่งคืนโดย Explore agent
结果由 Explore agent 返回。
The results were returned by the Explore agent.

Section Check 1

Which agent type is read-only?

Agent ประเภทใดเป็นแบบอ่านอย่างเดียว?

哪种 agent 类型是只读的?

Section Check 2

Which is passive voice?

ข้อใดเป็น passive voice?

哪个句子是被动语态?

Section Check 3

Where are custom agents defined?

Custom agents ถูกกำหนดที่ไหน?

自定义 agents 在哪里定义?

4. Tutorial Steps / ขั้นตอนการเรียนรู้ / 教程步骤

1
Use built-in agents / ใช้ agents ในตัว / 使用内置 agents
Ask Claude to 'use the Explore agent to find all API endpoints' — it spawns a fast search agent.

How to do it

  • Say: Use the Explore agent to find all API endpoints.
  • The agent searches in parallel and returns a short report.
  • Your main context stays small — the agent's reading does not fill your conversation.
2
Create a custom agent / สร้าง agent ที่กำหนดเอง / 创建自定义 agent
Create .claude/agents/reviewer.md with name, description, and tool restrictions.

How to do it

  • Create .claude/agents/reviewer.md.
  • Frontmatter: name, description, and optional tool limits.
  • The markdown body is the agent's job description — write it like instructions to a new teammate.
3
Run agents in background / รัน agents ในพื้นหลัง / 在后台运行 agents
Set background: true in frontmatter, or press Ctrl+B during execution.

How to do it

  • Put background: true in the agent's frontmatter, or press Ctrl+B while one runs.
  • You keep working; a notification arrives when the agent finishes.
  • Good for long jobs: big searches, test runs, batch edits.
4
Configure agent tools / ตั้งค่าเครื่องมือ agent / 配置 agent 工具
Use 'tools' for allowlist or 'disallowedTools' for denylist in frontmatter.

How to do it

  • tools: Read, Grep = allowlist — the agent can use only these.
  • disallowedTools: = denylist — everything except these.
  • Fewer tools = safer and more focused. A reviewer that cannot edit cannot break anything.
5
Manage with /agents / จัดการด้วย /agents / 用 /agents 管理
Type /agents to view, enable, or disable configured subagents.

How to do it

  • Type /agents to see every configured agent.
  • Enable or disable them from the list — disabled agents stay on disk.
  • Check here first when an agent "disappears".

5. Anatomy of a subagent / ส่วนประกอบของ subagent / 子代理的构造

An agent file is four frontmatter fields plus a job description. Each field has a job:

FieldWhat it does
namethe agent's id — how you and Claude refer to it
descriptionwhen Claude should pick this agent by itself. Write it like advice to a dispatcher: "Use for code review after changes."
toolscomma-separated allowlist (Read, Grep). Leave it out and the agent gets every tool — leash it on purpose.
modeloptional: run this agent on a cheaper/faster model (haiku) or a stronger one (opus)

What actually happens when you say "use the reviewer agent":

1
The main Claude reads every agent's description and picks the match (or obeys you naming one directly).
2
The agent starts with a fresh, separate context — it does not see your conversation, only its own instructions and the task.
3
It works with only its allowed tools. A reviewer without Edit can read every file and change none — the leash is the safety.
4
It returns one final report. All its reading and searching stays in its own context — your conversation only receives the conclusion. That is why agents keep long sessions fast.

Two habits that make agents work well: keep the body instructions specific and short (a job description, not an essay), and test a new agent by invoking it by name first — automatic dispatch only works once the description is sharp.

6. Hands-On Activity / กิจกรรมลงมือทำ / 动手练习

แบบฝึกหัด: สร้าง code-reviewer subagent ที่มีเฉพาะเครื่องมือ Read และ Grep ทดสอบโดยขอให้ Claude ใช้มันตรวจสอบโค้ด
练习:创建一个只有 Read 和 Grep 工具的自定义 code-reviewer subagent。然后让 Claude 用它做一次代码审查来测试。
Practice: Create a custom code-reviewer subagent that only has Read and Grep tools. Test it by asking Claude to use it for a code review.

Step by step

  1. Create .claude/agents/reviewer.md with frontmatter tools: Read, Grep.
  2. Body: Review code for bugs and unclear names. Report findings. Never edit files.
  3. Type /agents and check the reviewer is listed.
  4. Say: Use the reviewer agent to review my main source file.

✓ You did it right if: you get a list of findings and not a single file was changed.

📜 A complete working reviewer agent / ตัวอย่างคำตอบ / 示例答案
# Save as: .claude/agents/reviewer.md
# (tools list is comma separated - only these two are allowed)

---
name: reviewer
description: Reviews code for bugs and unclear names. Use for code review.
tools: Read, Grep
---

You are a careful code reviewer.
- Report bugs, unclear names and missing error handling.
- Suggest fixes, but NEVER edit files yourself.
- End with one line: "N issues found."

# ---- Use it ----
> Use the reviewer agent to review app.py
* reviewer: 3 issues found - unused import (line 2),
  no error handling in load_data(), unclear name "x".
  (no files changed - the agent has no Edit tool)

7. Reference Table / ตารางอ้างอิง / 参考表

Command / ToolEnglishภาษาไทย中文
ExploreFast read-only search (Haiku)ค้นหาเร็วแบบอ่านอย่างเดียว快速只读搜索
PlanArchitecture researchวิจัยสถาปัตยกรรม架构研究
general-purposeFull tools, complex tasksเครื่องมือครบ งานซับซ้อน全套工具,复杂任务
.claude/agents/Custom agent directoryไดเรกทอรี agent ที่กำหนดเอง自定义 agent 目录
/agentsManage agentsจัดการ agents管理 agents

8. Interactive Lab / ห้องทดลอง / 互动实验室

Race sequential against parallel, and put a reviewer agent on a tool leash. / แข่งแบบเรียงกับแบบขนาน และจำกัดเครื่องมือ agent / 顺序 vs 并行赛跑,并给 agent 限制工具

Four research tasks. Run them one-by-one, then all at once.

9. Summary / สรุป / 总结

Subagents จัดการงานเฉพาะทาง ประเภทในตัว: Explore, Plan, general-purpose Custom agents คือไฟล์ Markdown ใน .claude/agents/ Passive voice (be + กริยาช่อง 3) เน้นการกระทำมากกว่าผู้กระทำ
Subagents 处理专门的任务。内置类型:Explore、Plan、general-purpose。自定义 agents 是 .claude/agents/ 里的 Markdown 文件。被动语态(be + 过去分词)强调动作而不是执行者。
Subagents handle specialized tasks. Built-in types: Explore, Plan, general-purpose. Custom agents are Markdown files in .claude/agents/. Passive voice (be + past participle) emphasizes actions over actors.

Homework / การบ้าน / 作业

1. สร้าง subagent ที่กำหนดเองสำหรับโปรเจกต์
2. เปรียบเทียบ Explore, Plan และ general-purpose agents
3. เขียนประโยค active 5 ประโยคใหม่เป็น passive voice
1. 为你的项目创建一个自定义 subagent。
2. 比较 Explore、Plan 和 general-purpose agents。
3. 把 5 个主动语态句子改写成被动语态。
1. Create a custom subagent for your project.
2. Compare Explore, Plan, and general-purpose agents.
3. Rewrite 5 active sentences into passive voice.