# Anthropic Agent SDK — Build Production AI Agents > Official Anthropic SDK for building AI agents with tool use, memory, and orchestration. Production-grade agent framework with Claude as the backbone for autonomous tasks. ## Install Save as a script file and run: ## Quick Use ```bash pip install claude-agent-sdk ``` ```python from claude_agent_sdk import Agent, tool @tool def search_web(query: str) -> str: "Search the web for information." return do_search(query) agent = Agent( model="claude-sonnet-4-20250514", tools=[search_web], system="You are a helpful research assistant.", ) result = agent.run("Find the latest news about AI regulation in the EU") print(result.output) ``` ## What is the Anthropic Agent SDK? The Anthropic Agent SDK is the official Python framework for building production AI agents powered by Claude. It provides structured tool use, conversation memory, multi-turn orchestration, and guardrails — everything needed to build autonomous agents that reliably complete complex tasks. Think of it as the "official way" to build Claude-powered agents beyond simple API calls. **Answer-Ready**: Anthropic Agent SDK is the official framework for building production AI agents with Claude. Structured tool use, conversation memory, multi-turn orchestration, and safety guardrails. Supports agent handoffs, parallel tool execution, and streaming. The backbone for Claude Code's own agent system. **Best for**: Developers building production autonomous agents with Claude. **Works with**: Claude Opus, Sonnet, Haiku via Anthropic API. **Setup time**: Under 3 minutes. ## Core Features ### 1. Tool Use (Structured) ```python from claude_agent_sdk import Agent, tool @tool def get_weather(city: str) -> dict: "Get current weather for a city." return {"temp": 22, "condition": "sunny"} @tool def send_email(to: str, subject: str, body: str) -> str: "Send an email." return f"Email sent to {to}" agent = Agent( model="claude-sonnet-4-20250514", tools=[get_weather, send_email], ) ``` ### 2. Multi-Turn Orchestration ```python # Agent maintains conversation state across turns result = agent.run("What's the weather in Tokyo?") result = agent.run("Now email that to alice@example.com") # Agent remembers previous context ``` ### 3. Agent Handoffs ```python from claude_agent_sdk import Agent researcher = Agent(name="researcher", model="claude-sonnet-4-20250514", system="You research topics thoroughly.") writer = Agent(name="writer", model="claude-sonnet-4-20250514", system="You write clear, engaging content.") # Researcher hands off to writer orchestrator = Agent( model="claude-sonnet-4-20250514", agents=[researcher, writer], system="Coordinate research and writing tasks.", ) ``` ### 4. Streaming ```python for event in agent.run_stream("Analyze this codebase"): if event.type == "text": print(event.text, end="") elif event.type == "tool_use": print(f"\n[Using tool: {event.tool_name}]") ``` ### 5. Guardrails ```python agent = Agent( model="claude-sonnet-4-20250514", max_turns=10, # Limit autonomous loops max_tokens=4096, # Limit output length allowed_tools=["search_web"], # Restrict tool access ) ``` ## Architecture | Component | Purpose | |-----------|---------| | Agent | Core orchestration loop | | Tool | Typed function the agent can call | | Memory | Conversation state management | | Handoff | Transfer between specialized agents | | Guardrail | Safety and resource limits | ## FAQ **Q: How does this relate to Claude Code?** A: Claude Code is built on top of the Agent SDK. The SDK gives you the building blocks to create your own agent systems. **Q: Can I use it with other LLMs?** A: The SDK is designed for Claude. For multi-provider support, use LiteLLM or Bifrost as a proxy. **Q: Is it production-ready?** A: Yes, the SDK is designed for production use with proper error handling, retries, and resource management. ## Source & Thanks > Created by [Anthropic](https://github.com/anthropics). Licensed under MIT. > > [anthropics/claude-agent-sdk](https://github.com/anthropics/claude-agent-sdk) — Official Anthropic Agent SDK ## 快速使用 ```bash pip install claude-agent-sdk ``` Anthropic 官方 Agent 框架,构建生产级 Claude Agent。 ## 什么是 Anthropic Agent SDK? Anthropic 官方 Python 框架,用于构建基于 Claude 的生产级 AI Agent。提供工具调用、对话记忆、多轮编排和安全护栏。 **一句话总结**:Anthropic 官方 Agent 框架,结构化工具调用 + 对话记忆 + Agent 切换 + 安全护栏,Claude Code 的底层架构,生产就绪。 **适合人群**:构建生产级 Claude 自主 Agent 的开发者。 ## 核心功能 ### 1. 工具调用 Python 装饰器定义工具,自动类型推断。 ### 2. Agent 切换 多个专业 Agent 间任务移交。 ### 3. 流式输出 实时文本和工具调用事件。 ### 4. 安全护栏 轮次限制、工具白名单、输出长度控制。 ## 常见问题 **Q: 和 Claude Code 关系?** A: Claude Code 基于 Agent SDK 构建。SDK 是构建自定义 Agent 系统的基础。 ## 来源与致谢 > [anthropics/claude-agent-sdk](https://github.com/anthropics/claude-agent-sdk) — Anthropic 官方 --- Source: https://tokrepo.com/en/workflows/b9f86852-f532-455e-853e-d2af0153eff6 Author: Agent Toolkit