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.
Installation avec revue préalable
Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.
npx -y tokrepo@latest install b9f86852-f532-455e-853e-d2af0153eff6 --target codexDry-run d'abord, confirmez les écritures, puis lancez cette commande.
What it is
The Anthropic Agent SDK is the official framework for building AI agents powered by Claude. It provides structured tool use, memory management, multi-step orchestration, and guardrails for production deployments. The SDK handles the agent loop (observe, think, act, repeat) with built-in error recovery, token management, and conversation persistence.
The SDK targets developers building autonomous AI applications: customer support agents, research assistants, code generation pipelines, and workflow automation. It provides the production scaffolding that turns a single LLM call into a reliable agent system.
How it saves time or tokens
The SDK manages the agent loop internally, handling retries, tool call parsing, and conversation state. Without it, you write custom code for each of these concerns. Built-in token management prevents context window overflow by summarizing or truncating conversation history automatically. Error recovery means failed tool calls are retried with context rather than crashing the entire agent session.
How to use
- Install the SDK:
pip install claude-agent-sdk
- Define tools and create an agent:
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_prompt='You are a research assistant. Answer questions using web search.'
)
- Run the agent on a task:
result = agent.run('What are the latest developments in quantum computing?')
print(result.output)
Example
Multi-tool agent with memory:
from claude_agent_sdk import Agent, tool, MemoryStore
@tool
def query_database(sql: str) -> str:
'Execute a SQL query against the analytics database.'
return db.execute(sql)
@tool
def send_email(to: str, subject: str, body: str) -> str:
'Send an email notification.'
return email_service.send(to, subject, body)
memory = MemoryStore(backend='sqlite')
agent = Agent(
model='claude-sonnet-4-20250514',
tools=[query_database, send_email],
memory=memory,
)
# Agent remembers context across sessions
agent.run('Send a weekly revenue report to the finance team')
Related on TokRepo
- AI Tools for Agents — Compare agent frameworks for building autonomous AI systems
- Multi-Agent Frameworks — Multi-agent orchestration for complex task decomposition
Common pitfalls
- Tool functions must have clear docstrings. The SDK sends docstrings to Claude as tool descriptions. Vague docstrings lead to incorrect tool selection.
- Memory persistence requires explicit configuration. Without a memory backend, agent context is lost between sessions.
- Long-running agent tasks can accumulate significant token costs. Set max_turns or token budgets to prevent runaway execution.
- Always check the official documentation for the latest version-specific changes and migration guides before upgrading in production environments.
- For team deployments, establish clear guidelines on configuration and usage patterns to ensure consistency across developers.
Questions fréquentes
The Agent SDK is designed for Claude models. It supports Claude Sonnet, Claude Opus, and Claude Haiku. The SDK handles model-specific features like extended thinking and tool use automatically.
The MemoryStore persists conversation history and key facts across agent sessions. It supports SQLite and PostgreSQL backends. The agent can recall previous interactions and decisions without re-establishing context.
The SDK focuses on single-agent orchestration with tools. For multi-agent systems with coordination between agents, you can compose multiple SDK agents or use a multi-agent framework that delegates to SDK agents.
When a tool call fails, the SDK captures the error, includes it in the conversation context, and lets Claude retry with awareness of what went wrong. This handles transient failures like network timeouts without manual intervention.
The Anthropic Python SDK provides low-level API access for single completions. The Agent SDK adds the agent loop, tool orchestration, memory, and production guardrails on top. Use the Python SDK for simple API calls; use the Agent SDK for autonomous agent applications.
Sources citées (3)
- Anthropic Agent SDK— Official Anthropic SDK for building AI agents with Claude
- Anthropic Tool Use Docs— Claude tool use and function calling
- Anthropic Cookbook— Production agent patterns and best practices
En lien sur TokRepo
Source et remerciements
Created by Anthropic. Licensed under MIT.
anthropics/claude-agent-sdk — Official Anthropic Agent SDK
Fil de discussion
Actifs similaires
Claude Agent SDK — Build Agents with Claude Code Power
Anthropic's official TypeScript SDK for building AI agents with Claude Code's full capabilities — file editing, command execution, codebase understanding, and complex workflows. npm package.
Claude Agent SDK Demos — 8 Official Example Projects
Official demo collection by Anthropic showcasing the Claude Agent SDK: email agent, research agent, resume generator, chat app, Excel processing, and more. MIT license, 2,100+ stars.
Claude Swarm — Multi-Agent Orchestration with SDK
Python-based multi-agent orchestration built on Claude Agent SDK. Opus decomposes tasks, Haiku workers execute in parallel waves with real-time TUI dashboard and budget control.
Pipelock — MCP Firewall for Agent Egress
Run Pipelock as an agent firewall/proxy to scan MCP traffic for injection, secrets, SSRF, and risky tool chains; integrate with Claude Code fast.