ファイルを自動的に読み取り、コマンドを実行し、ウェブを検索し、コードを編集するなど、さらに多くのことができる AI エージェントを構築します。Agent SDK は、Claude Code を強化する同じツール、エージェントループ、およびコンテキスト管理を提供し、Python と TypeScript でプログラム可能です。エージェントハーネス設計の背景については、ブログの「A harness for every task: dynamic workflows in Claude Code」を参照してください。
import asynciofrom claude_agent_sdk import query, ClaudeAgentOptionsasync 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) # Claude reads the file, finds the bug, edits itasyncio.run(main())
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); // Claude reads the file, finds the bug, edits it}