By Sagar Shankaran, Founder of CallSphere
Learn how to install the Anthropic Python SDK, define tools, create your first Claude-powered agent, and execute multi-step workflows with structured tool calling.
Key takeaways
Anthropic's Claude models are purpose-built for agentic workflows. With native tool use, extended thinking, and a 200K-token context window, Claude gives agents the reasoning depth needed to handle multi-step tasks without losing coherence. The Anthropic Python SDK provides a clean, typed interface for building agents that call tools, process results, and iterate until a task is complete.
Unlike wrapper frameworks that add abstraction layers, building directly on the Anthropic SDK means you control every aspect of the agent loop — tool definitions, retry logic, context management, and output parsing. This tutorial walks you through the entire process from installation to a working agent.
Install the Anthropic Python SDK using pip:
flowchart LR
INPUT(["User intent"])
PARSE["Parse plus<br/>classify"]
PLAN["Plan and tool<br/>selection"]
AGENT["Agent loop<br/>LLM plus tools"]
GUARD{"Guardrails<br/>and policy"}
EXEC["Execute and<br/>verify result"]
OBS[("Trace and metrics")]
OUT(["Outcome plus<br/>next action"])
INPUT --> PARSE --> PLAN --> AGENT --> GUARD
GUARD -->|Pass| EXEC --> OUT
GUARD -->|Fail| AGENT
AGENT --> OBS
style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style OBS fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
pip install anthropic
Set your API key as an environment variable:
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
Verify the installation:
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=256,
messages=[{"role": "user", "content": "Say hello"}]
)
print(message.content[0].text)
If you see a greeting, your SDK and API key are configured correctly.
Claude agents gain capabilities through tools. Each tool is a JSON schema that tells Claude what the tool does, what parameters it accepts, and what it returns. Here is a simple calculator tool:
tools = [
{
"name": "calculator",
"description": "Performs arithmetic calculations. Use this for any math operation.",
"input_schema": {
"type": "object",
"properties": {
"expression": {
"type": "string",
"description": "A mathematical expression like '2 + 3 * 4'"
}
},
"required": ["expression"]
}
}
]
Tool descriptions matter. Claude uses the description to decide when to call each tool, so be specific about what the tool does and when it should be used.
An agentic workflow requires a loop: send a message to Claude, check if it wants to call tools, execute those tools, feed results back, and repeat until Claude produces a final text response.
import anthropic
import json
client = anthropic.Anthropic()
def run_agent(user_message: str, tools: list, system: str = "") -> str:
messages = [{"role": "user", "content": user_message}]
while True:
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=4096,
system=system,
tools=tools,
messages=messages,
)
# If Claude stops without tool use, return the text
if response.stop_reason == "end_turn":
text_blocks = [b.text for b in response.content if b.type == "text"]
return "\n".join(text_blocks)
# Process tool calls
messages.append({"role": "assistant", "content": response.content})
tool_results = []
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": json.dumps(result),
})
messages.append({"role": "user", "content": tool_results})
return "Agent loop ended unexpectedly"
The key insight is that Claude signals tool use through stop_reason == "tool_use" and embeds tool_use blocks in its response content. Your agent loop processes these blocks, executes the corresponding functions, and sends results back as tool_result messages.
The execute_tool function maps tool names to actual Python functions:
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
def execute_tool(name: str, inputs: dict):
if name == "calculator":
try:
result = eval(inputs["expression"]) # Use a safe parser in production
return {"result": result}
except Exception as e:
return {"error": str(e)}
return {"error": f"Unknown tool: {name}"}
In production, replace eval with a safe math parser like numexpr or asteval. Never execute arbitrary code from LLM outputs without sandboxing.
Put it all together:
system_prompt = """You are a helpful math assistant. Use the calculator tool
for any arithmetic. Show your reasoning before calculating."""
answer = run_agent(
"What is 15% tip on a $127.50 dinner bill, and what is the total?",
tools=tools,
system=system_prompt,
)
print(answer)
Claude will reason through the problem, call the calculator tool for 127.50 * 0.15, then call it again for 127.50 + 19.125, and return a formatted answer.
The Anthropic SDK is a thin client library that communicates directly with the Claude API. It does not include prompt templates, vector stores, or chain abstractions. This gives you full control over the agent loop, tool execution, and error handling without framework-imposed patterns. For many production use cases, this directness reduces bugs and makes debugging straightforward.
Yes. The SDK provides anthropic.AsyncAnthropic() for async usage. Replace client.messages.create() with await client.messages.create() inside an async function. This is essential for web servers where blocking calls would stall request handling.
Claude supports up to 128 tools in a single request. However, performance is best with fewer, well-described tools. If you have more than 20 tools, consider splitting them across specialized sub-agents or using tool categories with dynamic tool selection based on the user's query.
#Anthropic #Claude #AgentSDK #Python #GettingStarted #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
Using multiple chat AIs at once is a real 2026 workflow. Here is when it makes sense, how to set it up, and how CallSphere handles multi-model routing.
The 2026 desktop AI agent landscape — ServiceNow Project Arc, Anthropic Claude offerings, OpenAI agents, and Google Mariner. A buyer's map.
May 2026's biggest agent-architecture shift: planning, tool selection, and self-correction move inside the model. Framework code shrinks. Here is what changes.
A three-way comparison of Gemini Enterprise, Anthropic managed agents and OpenAI Frontier Platform after Cloud Next 2026 — strengths, gaps, buyer fit.
Anthropic's May 2026 push positions Claude as a vertical platform for financial services. The strategic positioning versus OpenAI and Google.
ServiceNow Project Arc vs Anthropic Managed Agents — runtime, governance, integration, and use cases. The 2026 enterprise autonomous agent comparison.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.