KRIT.JUNSREE PERSONAL WEBSITE
MEDIUM

3 วิธีสร้าง AI Agent ด้วย Claude — SDK, Markdown, Teams

Cobus Greyling วิเคราะห์ 3 approach จาก Anthropic — Agent SDK (programmatic, code-first Python), Markdown Definition (declarative, .md + YAML ใน .claude/agents/), Agent Teams (conversational, natural language). ต่างกันที่ persona + mental model. Anthropic ไม่ converge ให้ dev เลือกตามปัญหา ไม่ใช่ตาม platform

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

☰ ON THIS PAGE

Cobus Greyling วิเคราะห์ 3 approach จาก Anthropic สำหรับสร้าง AI Agent — Agent SDK (programmatic), Markdown Definition (declarative), Agent Teams (conversational). แต่ละ approach ตรงกับ persona + mental model ต่างกัน

Anthropic ไม่ converge ไปที่ pattern เดียว — ให้ dev เลือก 3 abstraction ต่างกัน ตามปัญหา

Observation ของผู้เขียน

Platform ส่วนใหญ่ให้ agent framework เดียว — Anthropic ให้ 3 tier ต่างกัน. แต่ละ persona คิดต่างกัน — Python dev ที่ build product ≠ DevOps configure tooling ≠ researcher สำรวจปัญหา

Approach 1: Agent SDK — Programmatic

Code-first. Define agent ใน Python. คุม system prompt, tool, model, conversation loop เอง ทุกอย่าง explicit

python
from claude_code_sdk import query, ClaudeCodeOptions

response = query(
    prompt="Review this code for security vulnerabilities",
    options=ClaudeCodeOptions(
        system_prompt="You are a security auditor...",
        allowed_tools=["Read", "Grep", "Glob"],
        model="sonnet",
        max_turns=15,
    )
)

Approach สำหรับ product engineer — ต้องการ deterministic control, version agent definition ใน source, test ใน CI, deploy เป็น service

ใช้เมื่อ: production app, API-driven workflow, ระบบที่ agent เป็น component ของ architecture

Approach 2: Markdown Definition — Declarative

Define agent เป็น .md file + YAML. ไม่ต้องเขียน Python

yaml
---
name: code-reviewer
description: Expert code reviewer. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
maxTurns: 10
---

You are a senior code reviewer. When invoked:
1. Run git diff to see recent changes
2. Review modified files for quality and security
3. Flag any issues with specific line references

Drop ใน .claude/agents/ — Claude Code detect เอง

ทำไม Claude ใช้ frontmatter? มันคือ lightweight metadata ที่ Claude โหลดเข้า system prompt เสมอ

Frontmatter บอก Claude ว่าไฟล์/skill/command นี้ทำอะไร + ใช้เมื่อไหร่ — ไม่ต้องโหลด instruction ทั้งหมด (progressive disclosure ประหยัด token). Detailed instruction อยู่ใน markdown body โหลดเฉพาะเมื่อเกี่ยวข้อง

Configuration-as-code สำหรับ AI Agent — mental model เดียวกับ Dockerfile / GitHub Action. Declarative, portable, version-controlled

ใช้เมื่อ: project-level tooling, team-shared agent, reusable specialist ที่อยู่กับ codebase

Approach 3: Agent Teams — Conversational

Agent Teams = ephemeral · code-defined agent = durable

Departure ที่ radical ที่สุด. ไม่เขียน code หรือ config — describe เป็นภาษาธรรมชาติ:

“Create a team to review this API design. One teammate focused on security. One on developer experience. One playing devil’s advocate.”

Claude spawn 3 agent แต่ละตัวมี context window ของตัวเอง ส่ง message ตรงหากันได้ collaborate/disagree/converge. ไม่มี DAG ไม่มี predefined workflow — agent จัดตัวเองรอบปัญหา

ใช้เมื่อ: exploratory work, design review, parallel research, ปัญหาที่ต้องการ diverse perspective มากกว่า deterministic pipeline

สัญญาณของการ Diversification

AI platform ส่วนใหญ่ consolidate ไปที่ framework เดียว — Anthropic ทำตรงข้าม. Ship 3 paradigm ต่างกัน ให้ dev เลือกตามปัญหา ไม่ใช่ตาม platform

บอกอะไร 2 อย่าง:

  1. Anthropic ไม่เชื่อว่ามี “abstraction ที่ถูกต้อง” เดียวสำหรับ agent orchestration — security scanner pipeline ไม่มีอะไรเหมือน brainstorming session
  2. เดิมพันที่ dev — ให้ primitive 3 ระดับของ abstraction แล้วให้ dev เลือกให้ถูก

Code

1. Agent SDK

text
python examples/sdk_agents.py

3 agent ใน Python — security auditor, code quality reviewer, orchestrator ที่ delegate ระหว่างพวกมัน

2. Markdown Definition

text
agents/
├── security-reviewer.md
├── quality-reviewer.md
└── documentation-checker.md

Drop ใน .claude/agents/ — Claude Code detect เอง

3. Agent Teams

text
python examples/team_review.py

Prompt ที่ spawn team 3 agent: security specialist, UX advocate, devil’s advocate

Running Example

bash
pip install claude-code-sdk

python examples/sdk_agents.py     # SDK approach
python examples/team_review.py    # Team approach
cp agents/*.md .claude/agents/    # Markdown agents

Take Away

3 approach map กับ spectrum ที่ engineer ทุกคนเห็น — Infrastructure จาก shell script → Terraform → natural language provisioning · CI/CD จาก Makefile → YAML pipeline → AI-driven workflow. Agent orchestration ตาม arc เดียวกัน

Anthropic ship ทั้ง 3 stage พร้อมกัน

คำถามไม่ใช่ approach ไหนดีสุด — คือ approach ไหนเหมาะกับปัญหาของคุณ

  • Build product ด้วย SDK
  • Configure project tooling ด้วย markdown
  • Explore idea ด้วย teams

3 tool. 3 mental model. Platform เดียว


แหล่งที่มา: “Three Ways To Build AI Agents With Claude” โดย Cobus Greyling ตีพิมพ์ 2 เม.ย. 2026 บน Medium · อ่านต้นฉบับ

Leave a Reply

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