Skip to content
DocsUse AIadvancedCustom Agents
Chapter 12 of 15·advanced·12 min read

Custom Agents

Agent Tùy Chỉnh

Building and configuring custom AI agents

Hover or tap any paragraph to see Vietnamese translation

Creating Custom Agents

Beyond built-in agents, you can create custom agents suited to your project's specific workflows. Custom agents are defined in markdown with system prompts and configuration.

Agent File Structure

Custom Agent Definition
1# .claude/agents/my-reviewer.md2---3name: my-reviewer4description: Custom code reviewer for our team standards5model: sonnet6tools:7  - Read8  - Grep9  - Glob10---1112# My Reviewer Agent

Agent Configuration

Frontmatter Fields

  • name: Identifier to invoke the agent.
  • description: Short description of what agent does.
  • model: Model to use (haiku, sonnet, opus).
  • tools: List of tools the agent can use.
Frontmatter Example
1---2name: doc-writer3description: Writes technical documentation4model: haiku  # Fast and cheap for docs5tools:6  - Read7  - Write8  - Glob9---

Tool Restrictions

You can restrict which tools an agent can use. This is useful for read-only agents or agents that shouldn't run bash commands.

Tool Restrictions
1# Read-only agent (for research/analysis)2tools:3  - Read4  - Glob5  - Grep6  - WebFetch78# Full access agent (for implementation)9tools:10  - Read11  - Write12  - Edit13  - Bash14  - Glob15  - Grep

Using Custom Agents

Using Custom Agents
1# Spawn custom agent via Agent tool2Agent(subagent_type="my-reviewer", prompt="review auth module")34# In team context5/team spawn my-reviewer "review the changes"67# Direct invocation8"use my-reviewer agent to check the API code"

Example Custom Agents

Database Migration Reviewer

Migration Reviewer Agent
1# .claude/agents/migration-reviewer.md2---3name: migration-reviewer4description: Reviews database migrations for safety5model: opus6tools: [Read, Grep, Glob]7---89# Migration Reviewer1011Review database migrations for:121. Backwards compatibility132. Rollback capability143. Performance impact on large tables154. Index usage165. Data integrity1718Flag any destructive operations that need careful review.

API Documentation Writer

API Docs Agent
1# .claude/agents/api-docs.md2---3name: api-docs4description: Generates OpenAPI documentation from code5model: sonnet6tools: [Read, Write, Glob]7---89# API Documentation Writer1011Generate OpenAPI 3.0 documentation by:121. Reading route definitions132. Extracting request/response types143. Adding descriptions and examples154. Writing to docs/api.yaml
Tip
Place agents in .claude/agents/ so they're automatically available in the project.

Agent Best Practices

  • Keep system prompt concise and focused on one purpose.
  • Choose appropriate model: haiku for simple, opus for complex.
  • Restrict tools to reduce risk and increase speed.
  • Include output format in prompt for consistency.

Key Takeaways

Điểm Chính

  • Custom agents are defined in .claude/agents/ as markdown filesCustom agents được định nghĩa trong .claude/agents/ dưới dạng markdown
  • Frontmatter configures name, model, and available toolsFrontmatter cấu hình name, model và tools có sẵn
  • Tool restrictions can make agents read-only or limitedGiới hạn tools có thể làm agents read-only hoặc hạn chế
  • Choose model based on task complexityChọn model dựa trên độ phức tạp của task

Practice

Test your understanding of this chapter

Quiz

Where should custom agents be placed?

Custom agents nên được đặt ở đâu?

True or False

Custom agents must have access to all tools.

Custom agents phải có quyền truy cập tất cả tools.

Code Challenge

Complete the frontmatter field for specifying the AI model

Hoàn thành trường frontmatter để chỉ định AI model

: sonnet
Quiz

Which model should you use for simple, fast tasks?

Model nào nên dùng cho tasks đơn giản, nhanh?

← → to navigate chapters
Built: 4/8/2026, 12:01:11 PM