taw·lmsĐăng nhập
Claude Code thực chiến — best practices từ Anthropic

Bài 6 · Best practices từ Anthropic Engineering

Claude Agent SDK — Claude Code thành library

Bài học này chưa có video. Cứ đọc nội dung phía dưới nhé.

Agent SDK là gì?

Claude Agent SDK = Claude Code repackaged thành library dùng được trong Python / TypeScript.

Build agent autonomous đọc file, chạy command, search web, edit code — y hệt Claude Code, nhưng programmable.

Install

# TypeScript
npm install @anthropic-ai/claude-agent-sdk

# Python
pip install claude-agent-sdk

TypeScript SDK bundle sẵn Claude Code binary — không cần cài thêm.

Code đầu tiên

import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "Find and fix the bug in auth.ts",
  options: { allowedTools: ["Read", "Edit", "Bash"] }
})) {
  console.log(message);
}
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions

async def main():
    async for message in query(
        prompt="Find and fix the bug in auth.py",
        options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"]),
    ):
        print(message)

asyncio.run(main())

Built-in tools

ToolTác dụng
ReadĐọc file
WriteTạo file mới
EditSửa file chính xác
BashChạy shell command
GlobTìm file theo pattern
GrepSearch regex
WebSearchSearch Google
WebFetchFetch URL
AskUserQuestionHỏi user (multiple choice)
MonitorWatch background script

So với Anthropic Client SDK

Client SDKAgent SDK
Tool loopBạn tự codeClaude tự handle
Build agentPhải implement scaffoldCó sẵn
Use caseLLM call đơn giảnAgent thực sự

So với Claude Code CLI

Use caseBest choice
Interactive devCLI
CI/CD pipelineSDK
Custom appSDK
One-off taskCLI
Production automationSDK

Nhiều team dùng cả 2: CLI hằng ngày, SDK cho production.

Khi nào nên dùng?

  • Build product có AI agent bên trong (chatbot doanh nghiệp, code review bot, support bot)
  • CI/CD: chạy Claude tự động kiểm code mỗi PR
  • Workflow automation: agent xử lý email, sync data

Lưu ý

Từ 15/6/2026, Agent SDK trên gói subscription dùng Agent SDK credit riêng (tách khỏi quota interactive). Dùng API key thay vì login claude.ai.

Nguồn chính thống: code.claude.com/docs/en/agent-sdk/overview

Bạn đang xem ở chế độ preview công khai. Để nộp bài tập, hỏi AI tutor, và làm quiz — đăng nhập.
Evals cho AI agent — đo chất lượng đúng cáchInfrastructure noise — vì sao benchmark agent không nên tin 100%→