Why Claude Agent SDK & What's Included
Direct integration via the Anthropic Python client gives you control over every step. Unlike LangChain, there are no extra abstractions: you define tools in Anthropic format, write the dispatch handler, and manage history. For agents with 3–5 tools, this approach saves up to 40% of your development budget. Typical cost for a basic agent is $2,000–$5,000, with a 5-day turnaround. We guarantee reliable integration with 5+ years of AI agent development experience and over 50 successful deployments. Our trusted AI integration approach ensures robust, scalable solutions.
| Stage | What You Get |
|---|---|
| Design | Agent architecture, tool schema, error matrix |
| Implementation | Full agent code with tool use, streaming, logging |
| Integration | Deployment in your environment (Docker, Kubernetes) |
| Documentation | README with tool descriptions and examples |
| Training | 4-hour team workshop |
| Support | 2 weeks of incident management post-launch |
How to Integrate Claude Agent SDK with Direct API
The agentic loop is a sequence: user → model → tool call → result → model. Claude Agent SDK automates this loop. The model decides which tool to call and with which parameters. The execute_tool dispatcher performs the call and returns the result. The message history stores all interactions, including tool results.
Key Steps for Integration
- Define tools in Anthropic format with explicit, mutually exclusive examples in descriptions.
- Implement
execute_tooldispatcher with robust error handling. - Manage message history and iteration limit (e.g., 10 iterations max).
- Test with parallel calls and streaming for low latency.
import anthropic
import json
client = anthropic.Anthropic()
tools = [
{
"name": "search_database",
"description": "Search information in the corporate database",
"input_schema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"},
"table": {"type": "string", "enum": ["products", "orders", "customers"]},
"limit": {"type": "integer", "default": 10},
},
"required": ["query"],
},
},
{
"name": "create_ticket",
"description": "Create a ticket in the support system",
"input_schema": {
"type": "object",
"properties": {
"title": {"type": "string"},
"description": {"type": "string"},
"priority": {"type": "string", "enum": ["low", "medium", "high", "critical"]},
"customer_id": {"type": "string"},
},
"required": ["title", "description", "customer_id"],
},
},
]
def execute_tool(tool_name: str, tool_input: dict) -> str:
"""Tool invocation dispatcher"""
handlers = {
"search_database": lambda i: db.search(**i),
"create_ticket": lambda i: helpdesk.create(**i),
}
handler = handlers.get(tool_name)
if not handler:
return f"Unknown tool: {tool_name}"
try:
result = handler(tool_input)
return json.dumps(result, ensure_ascii=False)
except Exception as e:
return f"Error: {e}"
def run_agent(user_message: str, system_prompt: str = None) -> str:
"""Agentic loop with tool use"""
messages = [{"role": "user", "content": user_message}]
for iteration in range(10):
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=4096,
system=system_prompt or "You are a helpful assistant with access to corporate tools.",
tools=tools,
messages=messages,
)
messages.append({"role": "assistant", "content": response.content})
if response.stop_reason == "end_turn":
text_blocks = [b.text for b in response.content if b.type == "text"]
return "\n".join(text_blocks)
if response.stop_reason == "tool_use":
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": result,
})
messages.append({"role": "user", "content": tool_results})
return "Iteration limit reached"
What Are the Advanced Features? Parallel Calls, Streaming, Computer Use
Parallel Tool Calls
Claude can call multiple tools in one turn. The code below uses asyncio.to_thread to execute tools concurrently, reducing overall latency.
def run_agent_with_parallel_tools(user_message: str) -> str:
messages = [{"role": "user", "content": user_message}]
while True:
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=4096,
tools=tools,
messages=messages,
)
messages.append({"role": "assistant", "content": response.content})
if response.stop_reason == "end_turn":
return next((b.text for b in response.content if b.type == "text"), "")
tool_use_blocks = [b for b in response.content if b.type == "tool_use"]
if not tool_use_blocks:
break
import asyncio
async def execute_parallel():
tasks = [
asyncio.to_thread(execute_tool, block.name, block.input)
for block in tool_use_blocks
]
return await asyncio.gather(*tasks)
results = asyncio.run(execute_parallel())
tool_results = [
{
"type": "tool_result",
"tool_use_id": block.id,
"content": result,
}
for block, result in zip(tool_use_blocks, results)
]
messages.append({"role": "user", "content": tool_results})
return ""
Streaming Agent for Low Latency
def run_streaming_agent(user_message: str):
messages = [{"role": "user", "content": user_message}]
while True:
collected_content = []
tool_use_id = None
tool_name = None
tool_input_parts = []
with client.messages.stream(
model="claude-opus-4-5",
max_tokens=4096,
tools=tools,
messages=messages,
) as stream:
for event in stream:
if hasattr(event, "type"):
if event.type == "content_block_start":
if event.content_block.type == "tool_use":
tool_use_id = event.content_block.id
tool_name = event.content_block.name
elif event.type == "content_block_delta":
if hasattr(event.delta, "text"):
print(event.delta.text, end="", flush=True)
collected_content.append({"type": "text_delta", "text": event.delta.text})
elif hasattr(event.delta, "partial_json"):
tool_input_parts.append(event.delta.partial_json)
final_message = stream.get_final_message()
messages.append({"role": "assistant", "content": final_message.content})
if final_message.stop_reason == "end_turn":
break
if tool_use_id:
full_tool_input = json.loads("".join(tool_input_parts))
result = execute_tool(tool_name, full_tool_input)
messages.append({
"role": "user",
"content": [{"type": "tool_result", "tool_use_id": tool_use_id, "content": result}],
})
Computer Use (beta) — Computer Control
computer_use_tools = [
{"type": "computer_20241022", "name": "computer", "display_width_px": 1920, "display_height_px": 1080},
{"type": "bash_20241022", "name": "bash"},
{"type": "text_editor_20241022", "name": "str_replace_editor"},
]
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=4096,
tools=computer_use_tools,
messages=[{"role": "user", "content": "Open the browser, go to company.ru, find the 'Contacts' section and copy the phone number."}],
betas=["computer-use-2024-10-22"],
)
Practical Case: Corporate Portal Integration
From our practice: a client needed an AI assistant for their corporate portal built on Python/FastAPI without external frameworks. We chose the direct Anthropic API because LangChain was overkill for a 5-tool setup. Tools included: search_knowledge_base (vector search over documents), get_employee_info (HR), create_it_ticket (ServiceDesk), get_meeting_rooms (booking), get_company_policies (policies). Result: 2-week implementation (vs 4 with LangChain, 2x faster), 450 lines of code, 80 ms lower first-token latency. The customer saved over $3,000 on development — these funds were redirected to additional features. This case exemplifies how LLM agents can be deployed efficiently with direct API integration.
| Tool | Purpose | Daily Call Frequency |
|---|---|---|
| search_knowledge_base | Document search | 1500+ |
| get_employee_info | Employee data | 800+ |
| create_it_ticket | Create ServiceDesk ticket | 300+ |
| get_meeting_rooms | Book meeting rooms | 200+ |
| get_company_policies | Policy documents | 100+ |
How Much Does Claude Agent Integration Cost? Timelines and Pricing
| Stage | Duration | Cost Range |
|---|---|---|
| Basic agent with 3–5 tools | 3–5 days | $2,000–$5,000 |
| Streaming + production error handling | 3–5 days | $2,000–$4,000 |
| Computer Use integration | 1–2 weeks | $5,000–$10,000 |
| Web application integration | 1 week | $3,000–$6,000 |
For a typical project, the cost savings amount to $3,000 over a $7,500 budget — a 40% reduction. Average cost per agent session is $0.15, saving $500 per month compared to LangChain-based solutions.
Common Integration Mistakes & How to Avoid Them
- Poorly designed tool schemas (ambiguous descriptions) — the agent gets confused. Use explicit mutually exclusive examples in the field description.
- Missing error handling in
execute_tool— the agent gets stuck in a loop. - Ignoring the iteration limit — token leaks.
- Wrong model choice for Computer Use (needs
claude-opus-4-5).
For more details on tool configuration, refer to the official Anthropic SDK repository.
Monitoring and Token Cost Optimization
In production, it's important to track the cost of each agentic call. The Claude API returns usage with input and output token counts in each response. We embed a counter in run_agent:
def run_agent_tracked(user_message: str) -> dict:
total_input_tokens = 0
total_output_tokens = 0
iterations = 0
messages = [{"role": "user", "content": user_message}]
while iterations < 10:
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=4096,
tools=tools,
messages=messages,
)
total_input_tokens += response.usage.input_tokens
total_output_tokens += response.usage.output_tokens
iterations += 1
# ... tool use handling ...
if response.stop_reason == "end_turn":
break
return {
"result": "...",
"tokens_in": total_input_tokens,
"tokens_out": total_output_tokens,
"iterations": iterations,
}
An average agent session with 3 tool calls consumes 2000–5000 input tokens and 500–1500 output tokens. We log this data to Prometheus and build dashboards by cost per user, per scenario, and per day. This allows quick detection of abnormally long chains and prompt optimization.
Additional optimization: caching via prompt_caching (header anthropic-beta: prompt-caching-2024-07-31) reduces the cost of repeated system prompts by 90%. For tools with rare descriptions (>1024 tokens), caching is automatic and saves up to 40% of tokens in multi-turn dialogues. Total token savings at 10,000 agentic calls per day represent a significant budget item that should be factored in from day one.
Get a consultation from an engineer with 5+ years of AI agent experience — we'll evaluate your project in 1 day. With over 50+ successful projects, we are a trusted partner for production-grade agents. Our AI agent development expertise ensures efficient tool configuration and robust deployment, handling 10,000+ agent calls daily in production.







