Understanding Computer Use

The Claude Agent SDK

4 min read

Anthropic released the Claude Agent SDK - the same infrastructure powering Claude Code - to help developers build sophisticated agents without reinventing the wheel.

What is the Agent SDK?

The Agent SDK provides:

  • Pre-built agentic loops for Computer Use and tool calling
  • State management for long-running sessions
  • Error recovery patterns
  • Observability hooks for debugging

Core Components

from anthropic import Anthropic

# Initialize the client
client = Anthropic()

# Tool definitions are passed as dicts to the API
tools = [
    {
        "type": "computer_20250124",
        "name": "computer",
        "display_width_px": 1024,
        "display_height_px": 768,
        "display_number": 0
    },
    {
        "type": "bash_20250124",
        "name": "bash"
    },
    {
        "type": "text_editor_20250124",
        "name": "str_replace_editor"
    }
]

The Agent Loop Pattern

The SDK simplifies the agentic loop:

async def run_agent(task: str):
    messages = [{"role": "user", "content": task}]

    while True:
        response = await client.messages.create(
            model="claude-sonnet-4-5-20250514",
            max_tokens=4096,
            tools=tools,
            messages=messages,
            betas=["computer-use-2025-01-24"]
        )

        # Check if agent is done
        if response.stop_reason == "end_turn":
            return extract_result(response)

        # Execute tool calls
        tool_results = await execute_tools(response.content)

        # Add to conversation
        messages.append({"role": "assistant", "content": response.content})
        messages.append({"role": "user", "content": tool_results})

Why Use the SDK?

Without SDK With SDK
Build loop from scratch Pre-built agent loop
Handle all edge cases Built-in error recovery
Manual state tracking Automatic state management
Custom debugging Observability hooks

Note: The Agent SDK uses the same patterns that power Claude Code, Anthropic's AI coding assistant.

In the next module, we'll set up your development environment to start building. :::

Quiz

Module 1: Understanding Computer Use

Take Quiz
FREE WEEKLY NEWSLETTER

Stay on the Nerd Track

One email per week — courses, deep dives, tools, and AI experiments.

No spam. Unsubscribe anytime.