| disable-model-invocation | true |
| name | claude-agent-sdk |
| description | Builds Claude Agent SDK agents in Python. Use when creating custom tools, hooks, sub-agents, or MCP integrations with the Agent SDK. Python ์์ด์ ํธ ๊ตฌ์ถ ์ ์ฌ์ฉ. |
Claude Agent SDK
Python ๊ธฐ๋ฐ ๋
๋ฆฝ ์คํํ AI ์์ด์ ํธ ์ฝ๋ ์์ฑ.
vs agent-creator:
| ํญ๋ชฉ | agent-creator | claude-agent-sdk |
|---|
| ๊ฒฐ๊ณผ๋ฌผ | .claude/agents/*.md | *.py ํ์ผ |
| ์คํ ํ๊ฒฝ | Claude Code ๋ด๋ถ | ๋
๋ฆฝ Python ์ฑ |
| ์ฉ๋ | ์์
์์ | ํ๋ก๋์
์๋ํ |
Instructions
์ํฌํ๋ก์ฐ 1: ์ ์์ด์ ํธ ํ๋ก์ ํธ
-
์ฉ๋ ํ์
- ๋ฌด์์ ์๋ํํ ๊ฒ์ธ๊ฐ?
- ์ด๋ค ๋๊ตฌ๊ฐ ํ์ํ๊ฐ? (ํ์ผ, ๋ช
๋ น, ์น, ์ปค์คํ
)
- ์๋ธ์์ด์ ํธ ํ์ ์ฌ๋ถ
-
ํ
ํ๋ฆฟ ์ ํ
| ์ฉ๋ | ํ
ํ๋ฆฟ |
|---|
| ์ต์ ์์ | templates/basic-agent.py |
| ์ปค์คํ
๋๊ตฌ | templates/tool-agent.py |
| ํ
(๊ฒ์ฆ/๋ก๊น
) | templates/hook-agent.py |
| ์๋ธ์์ด์ ํธ | templates/multi-agent.py |
| ํ๋ก๋์
| templates/production-agent.py |
-
ํ๋ก์ ํธ ๊ตฌ์กฐ ์์ฑ
{project}/
โโโ pyproject.toml
โโโ agent.py # ๋ฉ์ธ ์์ด์ ํธ
โโโ tools.py # ์ปค์คํ
๋๊ตฌ (์ ํ)
โโโ hooks.py # ํ
์ ์ (์ ํ)
-
์ฝ๋ ์์ฑ: ํ
ํ๋ฆฟ ๊ธฐ๋ฐ์ผ๋ก ์ฌ์ฉ์ ์๊ตฌ์ ๋ง๊ฒ ์์
์ํฌํ๋ก์ฐ 2: ๊ธฐ๋ฅ ์ถ๊ฐ
๊ธฐ์กด ์์ด์ ํธ์ ๊ธฐ๋ฅ ์ถ๊ฐ ์:
-
ํค์๋ โ ๋ฆฌ์์ค ๋งค์นญ
| ํค์๋ | ๋ฆฌ์์ค |
|---|
| ์ค์น, pyproject | resources/01-setup.md |
| query, ๊ธฐ๋ณธ, ์ต์
| resources/02-query-options.md |
| ๋๊ตฌ, @tool | resources/03-custom-tools.md |
| ํ
, hook, ๊ฒ์ฆ | resources/04-hooks.md |
| ์๋ธ์์ด์ ํธ, ์์ | resources/05-subagents.md |
| ์ธ์
, resume | resources/06-sessions.md |
| MCP, playwright | resources/07-mcp.md |
-
๋ฆฌ์์ค ๋ก๋ โ ํจํด ์ ์ฉ
์ํฌํ๋ก์ฐ 3: ์ฝ๋ ๋ฆฌ๋ทฐ/๊ฐ์
๊ธฐ์กด ์์ด์ ํธ ์ฝ๋ ๋ถ์ ์์ฒญ ์:
- ๊ตฌ์กฐ ํ์ธ: ํ์ฌ ์ฌ์ฉ ์ค์ธ ๊ธฐ๋ฅ ํ์
- ๊ฐ์ ์ ์ ์:
- ์๋ฌ ํธ๋ค๋ง ์ถ๊ฐ
- ํ
์ผ๋ก ๊ฒ์ฆ/๋ก๊น
- ์๋ธ์์ด์ ํธ๋ก ๋ถ๋ฆฌ
- ์ธ์
๊ด๋ฆฌ ์ถ๊ฐ
ํต์ฌ ํจํด
๊ธฐ๋ณธ query()
from claude_agent_sdk import query, ClaudeAgentOptions
async for msg in query(
prompt="์์
์ง์",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Edit", "Bash"],
cwd="/path/to/project",
permission_mode="acceptEdits"
)
):
if hasattr(msg, "result"):
print(msg.result)
์ปค์คํ
๋๊ตฌ
from claude_agent_sdk import tool, create_sdk_mcp_server
@tool("search", "๊ฒ์ ์ํ", {"query": str})
async def search(args):
return {"content": [{"type": "text", "text": f"๊ฒฐ๊ณผ: {args['query']}"}]}
server = create_sdk_mcp_server("my-tools", "1.0.0", tools=[search])
ํ
async def validate_bash(input_data, tool_use_id, context):
cmd = input_data.get("tool_input", {}).get("command", "")
if "rm -rf" in cmd:
return {"decision": "block", "reason": "์ํํ ๋ช
๋ น์ด"}
return {}
options = ClaudeAgentOptions(
hooks={"PreToolUse": [HookMatcher(matcher="Bash", hooks=[validate_bash])]}
)
์ค์ ์์น
- allowed_tools ์ต์ํ: ํ์ํ ๋๊ตฌ๋ง ํ๊ฐ
- permission_mode ์ ์คํ:
bypassPermissions๋ ํ๋ก๋์
์ ์ฉ
- ์๋ฌ ํธ๋ค๋ง:
try/except๋ก graceful ์ฒ๋ฆฌ
- ์ธ์
ํ์ฉ: ์ฅ๊ธฐ ์์
์ session_id ์ ์ฅ ํ resume
Technical Details
REFERENCE.md: SDK API ์ ์ฒด ๊ฐ์
resources/: ๊ธฐ๋ฅ๋ณ ์์ธ ํจํด
templates/: ์์ ํ ์์ด์ ํธ ์ฝ๋