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.
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.
Frequently Asked Questions
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.
Citations (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
Related on TokRepo
Source & Thanks
Created by Anthropic. Licensed under MIT.
anthropics/claude-agent-sdk — Official Anthropic Agent SDK