1:1 mentoring with Big Tech AI engineers
LLM & Agentic

Agent SDK Patterns

Production patterns for building AI agents with the Claude Agent SDK: the loop, subagents, permissions, context management, MCP, and hooks — plus when to use the SDK vs the raw API.

Last updated

After this section you can

  • Choose between the Agent SDK, the Tool Runner or a manual loop, and Managed Agents for a given task
  • Name the five duties of an agent harness and where each is handled
  • Take an SDK agent through a deployment checklist: bounds, isolation, credentials, state, telemetry
31

Agent SDK: Production-Ready Patterns

When the Agent SDK is the right base and when the raw API is, the five things any harness has to get right, and what it takes to run SDK agents on your own infrastructure.

Key idea

The Agent SDK is Claude Code as a library: a harness you host. Use it when the task needs files, a shell and an open-ended loop. Whichever base you pick, the limits, the sandbox, the credentials and the evals are still yours to set.

The Agent SDK hands you five harness duties; deployment stays yours
FIVE DUTIES AROUND THE LOOP Tools and gates SDK GIVES YOU built-ins, MCP, modes, rules, hooks YOU DECIDE which tools, which paths Context SDK GIVES YOU auto-compaction, prompt caching YOU DECIDE what must survive it Delegation SDK GIVES YOU subagents with their own context, caps YOU DECIDE when a split pays Bounds SDK GIVES YOU turn and dollar caps, interrupt() YOU DECIDE the numbers, a deadline Observability SDK GIVES YOU hooks, OTel spans, cost estimates YOU DECIDE alerts, dashboards Always yours: where it runs · credentials · state that survives a restart · evals A harness removes loop code. The limits, the blast radius and the definition of done are still decisions you make.

Related

More in LLM & Agentic

Get full access to all 74+ sections with code examples, diagrams, and interactive animations.

Unlock Premium