KRIT.JUNSREE PERSONAL WEBSITE
MEDIUM

สร้าง Specialised AI Agent ด้วย Claude Agent SDK

Cobus Greyling อธิบายความต่าง SDK (dev tool + programmatic) vs Agent Teams (Claude spawn on-the-fly). SDK เน้น specialized agent narrow mandate + restricted tool + focused prompt. Constraint = feature. รวม subagent pattern + @tool decorator + example security-reviewer + performance-reviewer

By krit.junsree@gmail.com ◆ Jul 10, 2026 ◆ 9 MIN READ Beginner

☰ ON THIS PAGE

Cobus Greyling อธิบายความต่างของ Claude Agent SDK vs Claude Agent Teams — SDK สำหรับ build specialized agent ที่มี narrow mandate + restricted tool + focused prompt (ไม่ใช่ generalist)

Claude Agent SDK vs Agent Teams ต่างกันยังไง

2 layer แก้ 2 ปัญหาต่างกัน

Claude Agent SDK

Python/TypeScript package สำหรับ build agent แบบ programmatic. Dev เขียน code นิยาม system prompt, tool, permission — คุม agentic loop เอง. SDK = dev tool ผลิต agent ที่รันใน infrastructure + product ของคุณเอง

Claude Agent Teams

Feature ใน Claude Code (CLI) ที่ Claude สร้าง + จัดการ sub-agent หลายตัวระหว่างรัน task. ไม่ต้อง pre-define — Claude spawn specialist agent ตาม task on-the-fly

กลับมาที่ Agent SDK

Framework ส่วนใหญ่ให้ generic agent คาดหวังว่ามันทำได้ทุกอย่าง. Claude Agent SDK ตรงข้าม — build specialized agent หลายตัว ที่ narrow mandate + restricted tool + focused prompt:

  • Security auditor อ่านไฟล์เท่านั้น
  • Contract reviewer process document เท่านั้น
  • Invoice agent extract structured data เท่านั้น

Entry Point + Config

SDK มี 2 entry: query() = async one-shot · ClaudeSDKClient = multi-turn ยัง context. Config เหมือนกัน

python
from claude_agent_sdk import query, ClaudeAgentOptions

async for message in query(
    prompt="Review auth.py for security vulnerabilities",
    options=ClaudeAgentOptions(
        system_prompt="You are a security auditor. Report vulnerabilities only.",
        allowed_tools=["Read", "Grep", "Glob"],
        permission_mode="acceptEdits",
        max_turns=10,
    ),
):
    print(message)

Allowed tool นิยาม capability — read-only agent เขียนไม่ได้ · search agent แก้ไฟล์ไม่ได้

Permission mode กำหนด autonomy — default ต้อง user approve destructive action · accept-edits auto-approve file change · bypass = fully autonomous

Tool Surface

SDK มี built-in tool. Dev เพิ่ม custom tool ผ่าน @tool decorator + MCP server:

python
from claude_agent_sdk import tool, create_sdk_mcp_server

@tool("extract_invoice", "Extract structured data from invoice text", {
    "text": str
})
async def extract_invoice(args):
    # Your extraction logic here
    return {"content": [{"type": "text", "text": result}]}

server = create_sdk_mcp_server(
    name="invoice-tools",
    version="1.0.0",
    tools=[extract_invoice],
)

Subagent Architecture

Power จริงมาจาก subagent — parent agent spawn child ที่ specialize สำหรับ subtask. แต่ละ subagent รันใน isolated context · parent เห็นแค่ summary ไม่เห็น intermediate tool call:

python
from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition

options = ClaudeAgentOptions(
    allowed_tools=["Read", "Glob", "Agent"],
    agents={
        "security-reviewer": AgentDefinition(
            description="Reviews code for security vulnerabilities",
            prompt="You are a security expert. Identify OWASP top 10 issues.",
            tools=["Read", "Grep", "Glob"],
        ),
        "performance-reviewer": AgentDefinition(
            description="Reviews code for performance bottlenecks",
            prompt="You are a performance engineer. Find N+1 queries, memory leaks, blocking calls.",
            tools=["Read", "Grep", "Glob"],
        ),
    },
)

Parent ตัดสินใจว่าจะเรียก subagent ไหน — security reviewer ไม่ดู performance · performance reviewer ไม่ flag security

7 Agent, 1 SDK

7 agent ใช้ SDK infrastructure เดียวกัน. แต่ละ agent = distinct configuration ไม่ใช่ separate codebase. System prompt + tool + constraint แยกความต่าง

Design Principle

Constraint = feature — restrict tool ต่อ agent สร้าง safety boundary + ป้องกัน context contamination. Subagent รันอิสระ security audit ไม่ปนกับ performance review. SDK จัดการ agentic loop · dev นิยาม purpose + tool · infrastructure จัดการ execution

Conclusion

Claude Agent SDK = runtime สำหรับ specialized AI agent — ไม่ใช่ chatbot framework หรือ prompt wrapper. ให้แต่ละ agent มี identity, scoped capability, isolated context. Specialization = product · SDK = infrastructure


แหล่งที่มา: “Building Specialised AI Agents using Claude Agent SDK” โดย Cobus Greyling ตีพิมพ์ 27 มี.ค. 2026 บน Medium · อ่านต้นฉบับ

Leave a Reply

Your email address will not be published. Required fields are marked *