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.
Ngoài các agent có sẵn, bạn có thể tạo agent riêng phù hợp với workflow đặc thù của dự án. Custom agents được định nghĩa bằng markdown với system prompt và cấu hình.
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- name: Identifier to invoke the agent.
name: Identifier để gọi agent.
- description: Short description of what agent does.
description: Mô tả ngắn về agent làm gì.
- model: Model to use (haiku, sonnet, opus).
model: Model sử dụng (haiku, sonnet, opus).
- tools: List of tools the agent can use.
tools: Danh sách tools agent có thể sử dụng.
1---2name: doc-writer3description: Writes technical documentation4model: haiku # Fast and cheap for docs5tools:6 - Read7 - Write8 - Glob9---You can restrict which tools an agent can use. This is useful for read-only agents or agents that shouldn't run bash commands.
Bạn có thể giới hạn tools mà agent có thể sử dụng. Điều này hữu ích cho read-only agents hoặc agents không nên chạy bash commands.
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 - Grep1# 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"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.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Đặt agents trong .claude/agents/ để chúng tự động available trong project.
- Keep system prompt concise and focused on one purpose.
Giữ system prompt ngắn gọn và tập trung vào một mục đích.
- Choose appropriate model: haiku for simple, opus for complex.
Chọn model phù hợp: haiku cho đơn giản, opus cho phức tạp.
- Restrict tools to reduce risk and increase speed.
Restrict tools để giảm rủi ro và tăng tốc độ.
- Include output format in prompt for consistency.
Include output format trong prompt để nhất quán.
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
Where should custom agents be placed?
Custom agents nên được đặt ở đâu?
Custom agents must have access to all tools.
Custom agents phải có quyền truy cập tất cả tools.
Complete the frontmatter field for specifying the AI model
Hoàn thành trường frontmatter để chỉ định AI model
: sonnetWhich model should you use for simple, fast tasks?
Model nào nên dùng cho tasks đơn giản, nhanh?