
Artificial intelligence agents are transforming how we automate complex workflows, perform multi-step tasks, and interact with data and external services.
Among the leading tools empowering developers to build such AI agents is the Claude Agent SDK from Anthropic.
This powerful SDK enables you to create reliable, production-ready AI agents that leverage the state-of-the-art Anthropic AI Claude models, including Claude Code and Claude Opus, to perform sophisticated code execution, file operations, semantic search, and more. The Claude Agent SDK provides all the building blocks needed to build production-ready agents.
In this guide, we’ll walk you through everything you need to know about the Claude Agent SDK—from installation and setup to building specialized agents with custom tools and managing context effectively.
Whether you want to build general-purpose agents or highly specialized AI assistants, this step-by-step tutorial will help you harness the full potential of the agent SDK to build agents that are both powerful and safe.
The Claude Agent SDK is a developer toolkit designed to build interactive AI agents powered by Anthropic’s aligned frontier models, such as Claude Code and Claude Opus.
These AI agents can autonomously perform tasks by gathering context, executing code, interacting with external APIs, managing filesystems, and more—all while following a structured loop of reasoning and action.
The key design principle behind the Claude Agent SDK is to give agents access to a computer. Agents run in a sandboxed container to enhance security and isolate processes, preventing prompt injection and other risks. The SDK supports subagents by default, enabling parallelization of tasks.
At its core, the SDK enables you to:
The SDK works by connecting your code to Anthropic’s Claude API via your Claude API key, allowing you to build production-ready agents that can be embedded in Python or TypeScript applications.
Creating an AI agent using the Claude Agent SDK involves several key steps, from setup to deployment. They include:
The Claude Agent SDK follows a structured loop of gathering context → taking action → verifying work → repeating. The SDK includes built-in features for error handling, session management, and monitoring to support production-ready applications.
Agents use tools to fetch context (files, APIs), perform actions (running code, calling APIs), then check the results and decide whether to continue.
This loop is designed to let agents act autonomously while giving you oversight and control.
Use the SDK’s options object to set the agent’s role, working directory, allowed tools, and permission strategy. A typical configuration looks like this (Python example):
from claude_code_sdk import ClaudeCodeOptions
# Step 1: Define the agent's role
options = ClaudeCodeOptions(
system_prompt="You are a Python code reviewer focused on security",
cwd="/path/to/project"
)
# Step 2: Set operational parameters
options.allowed_tools = ["Read", "Grep"] # Tools the agent can use
options.permission_mode = "manual" # or "acceptEdits", "acceptAll"
options.max_turns = 5 # Limit number of iterations
This defines a “code reviewer” agent that works within a given directory and can only read or search files until a human approves further actions.
Start interacting with your agent by calling the high‑level query function or by creating a persistent client:
import anyio
from claude_code_sdk import query, ClaudeSDKClient
# Option A: One‑off query (streaming):
async def run_query():
async for msg in query("Review main.py for security issues", options=options):
for block in msg.content:
if block.type == "text":
print(block.text)
elif block.type == "tool_use":
print(f"Using tool: {block.tool_name}")
# Option B: Persistent client for multi‑turn interactions:
async def run_client():
async with ClaudeSDKClient(options=options) as client:
await client.query("Find all SQL queries in the codebase")
async for response in client.receive_response():
# handle responses
pass
anyio.run(run_query)
The query API streams back messages that include either text responses or instructions to use tools.
To extend functionality beyond the built‑in tools, implement custom tools, and define subagents:
from claude_code_sdk import tool, create_sdk_mcp_server
@tool("security_scan", "Scan code for vulnerabilities", args_schema={"file": str})
async def security_scanner(args):
file_path = args["file"]
# ... custom scanning logic ...
return {"content": [{"type": "text", "text": f"Scanned {file_path}"}]}
server = create_sdk_mcp_server(
name="security-tools",
version="1.0.0",
tools=[security_scanner]
)
options.mcp_servers = {"security": server}
options.allowed_tools.append("mcp__security__security_scan")
---
name: sql-expert
description: Analyzes and optimizes SQL queries
allowed_tools: ["Read", "Grep"]
model: claude-3-sonnet
---
You are an SQL optimization expert. Focus on query performance and security. The main agent will automatically delegate SQL-related tasks to this subagent.
These subagents run with isolated context windows and can be invoked automatically when the main agent encounters relevant tasks.
By following these steps, you can create robust AI agents that operate autonomously yet safely using Anthropic’s Claude Agent SDK.
If you’re looking to implement AI-powered customer support agents that reduce support costs and improve satisfaction, consider Helply.
Helply is a self-learning conversational AI support agent designed to plug into your help desk and knowledge base. It automatically resolves over 70% of Tier-1 customer inquiries instantly, 24/7.
It helps reduce ticket volume by enabling users to chat directly with the bot instead of searching through articles.
Helply has the following features:
Helply trains on diverse content types, including;
This continuous enrichment ensures the agent stays up to date and knowledgeable.
Customize the agent’s look and feel, persona (friendly, plainspoken, playful, etc.), styling rules (such as bolding key words), and response style (short, crisp answers).
You can also define fallback behaviors for when the bot doesn’t know an answer, such as triggering a form or suggesting contacting support.
Helply can perform interactive and transactional tasks beyond answering questions, including;
Triggering emails, calling APIs (e.g., Stripe to retrieve invoices)
Executing product-specific workflows, like creating help articles.
Other features include:
4. Contacts & Personalization: The agent can leverage user-specific data (such as plan type or permissions) to tailor responses, providing personalized answers like “You’re on a Premium plan, so yes, you have this feature.”
5. Conversations Dashboard: Access past user conversations to gain insights, perform training, and conduct quality checks to continuously improve the agent’s performance.
6. Gap Finder: Helply analyzes support tickets to detect common questions the bot can’t yet answer, highlight knowledge gaps, and help you train the bot on these topics to improve future coverage.
7. Easy Deployment: Helply provides embed codes to add the agent to your website or help center, allowing users to chat with the bot wherever you deploy it.
Experience the power of AI-driven self-service support! Book a FREE demo today and see how conversational AI agents can transform your customer support.
LiveAgent vs Chatbase vs Helply: Compare features, pricing, and pros/cons. See which AI support tool fits your team. Click here to learn more!
Build AI agents with Kimi K2.5 using tools, coding with vision, and agent swarms. Learn best modes, guardrails, and recipes to ship reliable agents.
End-to-end support conversations resolved by an AI support agent that takes real actions, not just answers questions.