Agent SDK — Python

Agent

by davila7 · Added 5mo ago

Claude

Install

npx claude-code-templates@latest --agent=cli-tool/components/skills/development/claude-api/python/agent-sdk --yes

Add to Claude

claude mcp add agent-sdk-python

About

Agent SDK — Python

The Claude Agent SDK provides a higher-level interface for building AI agents with built-in tools, safety features, and agentic capabilities.

Installation

pip install claude-agent-sdk

Quick Start

import anyio
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage

async def main():
    async for message in query(
        prompt="Explain this codebase",
        options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"])
    ):
        if isinstance(message, ResultMessage):
            print(message.result)

anyio.run(main)

Built-in Tools

ToolDescription
ReadRead files in the workspace
WriteCreate new files
EditMake precise edits to existing files
BashExecute shell commands
GlobFind files by pattern
GrepSearch files by content
WebSearchSearch the web for information
WebFetchFetch and analyze web pages
AskUserQuestionAsk user clarifying questions
AgentSpawn subagents

Primary Interfaces

query() — Simple One-Shot Usage

The query() function is the simplest way to run an agent. It returns an async iterator of messages.

from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage

async for message in query(
    prompt="Explain this codebase",
    options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"])
):
    if isinstance(message, ResultMessage):
        print(message.result)

ClaudeSDKClient — Full Control

ClaudeSDKClient provides full control over the agent lifecycle. Use it when you need custom tools, hooks, streaming, or the ability to interrupt execution.

import anyio
from claude_agent_s

Tags

FullStackaitmplclaude-code-templates

From Our Store

View all →
Claude Code

Claude Code Power User Kit

$39+

Advanced Claude Code skills and configurations

OpenClaw

OpenClaw Business Starter Kit

$59+

Set Up Your AI Assistant in 60 Minutes