Lesson 03 Claude Agent SDK Intro
Theme:
Lesson 03 · Slide 1

Lesson 03 — Claude Agent SDK Intro

From the 80-line hand-rolled loop to the SDK that takes most of it off your plate.

Agents Module 2 Claude Agent SDK

Lesson 03 · Slide 2

Recap of Module 1

The Claude Agent SDK gives you all of those as one Agent(...).run(...) call.

Lesson 03 · Slide 3

What “the Claude Agent SDK” actually is

Key clarification

There is no separate claude-agent-sdk PyPI package in 2026 Q2. The SDK is a set of higher-level primitives — Agent, tool, Tool, message helpers — exposed inside the official anthropic Python package.

You install one thing:

pip install anthropic

…and import both the low-level Anthropic() client and the SDK primitives from the same package.

Lesson 03 · Slide 4

The rebrand from “Computer Use”

If your search engine sends you to old Computer Use docs, you're reading the right SDK under its old name.

Lesson 03 · Slide 5

Five primitives the SDK gives you

Agent

Wraps the loop. You give it a model, a system prompt, a tool list, and call .run(user_message).

@tool / Tool

Decorator + class to declare a Python function as an LLM-callable tool. Pulls types and docstring into the JSON Schema for you.

Message helpers

assistant_message, tool_result, … — so you don't hand-write the {"role": ..., "content": [...]} shape.

Stop-condition primitives

Built-in max_turns, max_cost_usd, and an on_step hook for caller-driven interrupts.

Plus: .stream() and per-event callbacks for token-by-token output and observability.

Lesson 03 · Slide 6

Hello-world agent in 12 lines

from anthropic import Anthropic
from anthropic.agents import Agent, tool

@tool
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    return f"{city}: 4°C, light rain"

agent = Agent(
    client=Anthropic(),
    model="claude-3-5-sonnet-latest",
    system="You are a helpful weather assistant.",
    tools=[get_weather],
)
result = agent.run("What's the weather in Kyiv?")
print(result.final_text)

This is the same agent as L02's 80-line version, in 12 lines. The SDK provides exactly what we wrote by hand last lesson.

Lesson 03 · Slide 7

What the SDK takes off your plate

You wrote by hand in L02SDK does for you
The for turn in range(MAX_TURNS): loopAgent.run()
Branch on stop_reasoninternal
Append assistant + tool_result blocksinternal
Cost trackingresult.usage + max_cost_usd= arg
Tool-error → is_error: Trueinternal try / except in @tool wrapper
Turn capmax_turns= arg
Lesson 03 · Slide 8

The @tool decorator in detail

Notes: Compare to L02 Slide 5 — the TOOLS list with hand-written JSON Schema is gone.
Lesson 03 · Slide 9

Stop conditions in the SDK

agent = Agent(
    client=Anthropic(),
    model="claude-3-5-sonnet-latest",
    system="...",
    tools=[...],
    max_turns=10,           # turn cap
    max_cost_usd=0.50,      # cost cap
    on_step=log_step,       # caller hook, can raise to interrupt
)

Three of the four L01 stop conditions are now config. Natural exit (end_turn) is automatic. Caller interrupt is on_step raising.

Lesson 03 · Slide 10

Streaming and observability

Render token-by-token, log each step, or pipe events to an observability backend. The free-tier event surface is much richer than what hand-rolled L02 gave you.

Lesson 03 · Slide 11

When to pick Claude Agent SDK

Pick it when

  • Claude is your model.
  • The agent is tool-heavy (5+ tools).
  • You don't need a graph or multi-agent shape.

This is the sweet spot — and exactly what L04 builds.

Pick something else when

  • You need explicit graph control flow → LangGraph.
  • You need multi-provider model routing → OpenAI Agents SDK.
  • You need multi-agent role play → CrewAI.
Lesson 03 · Slide 12

Cost of switching

Lesson 03 · Slide 13

Recap & what's next

Coming up: Lesson 04 — build a tool-heavy research assistant in ~120 lines using the SDK we just met.
1 / ?