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

Production5 min readFirst readThe Agent Loop

After this section you can

  • Decide between an agent SDK and the raw API for a given job
  • Name the five things a harness has to get right that a hand-rolled loop usually misses
  • Take an agent through the operational checklist before deploying it
38

Agent SDK: Production-Ready Patterns

The raw Messages API gives you one call. Real agents need the loop, tool orchestration, subagents, permissions, context management, and hooks around it. The Claude Agent SDK is that harness — when to reach for it, and the patterns that matter.

THE CENTRAL IDEA

Everything so far — the loop, tool use, memory, delegation — you can hand-build on the Messages API, and understanding how is the point of this guide. But rebuilding the harness for every project is wasted motion. The Claude Agent SDK (the engine extracted from Claude Code) packages the battle-tested pieces: the agent loop, tool execution, subagents, permission gating, context compaction, MCP connectivity, and lifecycle hooks. The FDE skill isn’t “can you use the SDK” — it’s knowing which layer to build at, and what production concerns the harness has to solve no matter who writes it.

What the harness wraps around a raw model call
HOOKS · OBSERVABILITY · SESSION PERSISTENCE (outer ring) subagent orchestration context management · compaction permissions · guardrails · MCP tools the agent loop Messages API one model call goal in → → result out

Related

More in LLM & Agentic

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

Unlock Premium