Agent Construction with Claude
Official scope (Exam Guide v1.0): Agent SDK, custom loops and harnesses, managed agent deployment (self-hosted vs Anthropic-hosted), hooks for deterministic actions.
Four ways to build
| Option | What you get | Pick it when |
|---|---|---|
| Client SDK | Direct API access; you write the loop, or the beta tool runner runs your tools for you | Full control, custom loop, any of 7 languages |
| Agent SDK (Python, TypeScript) | Claude Code's agent loop as a library in a process you operate: built-in tools, permissions, sessions, hooks, subagents, MCP, skills, plugins | Coding-agent capabilities inside your own app |
| Managed Agents (beta) | Anthropic hosts the harness; sessions run in an Anthropic-managed cloud sandbox or a self-hosted sandbox on your infrastructure | No loop or sandbox to build; long-running, async, scheduled work |
| Claude Code CLI | Interactive terminal; -p with --output-format json for scripts and other languages | Development, one-off tasks, CI |
Managed Agents in brief
- Concepts: Agent (model, system prompt, tools, MCP servers, skills), Environment (where sessions run), Session (a running instance), Events (messages in and out, streamed over SSE; history stored server-side).
- Built-in tools: bash, file operations, web search and fetch, MCP servers. Built-in caching and compaction.
- Requires the
managed-agents-2026-04-01beta header (the SDK sets it). Not eligible for ZDR or HIPAA BAA coverage, because it is stateful by design. - Self-hosted vs Anthropic-hosted (design guidance on the trade-off): self-hosted sandboxes keep execution on your infrastructure for compliance or data residency; Anthropic-hosted means no sandbox to run. Compare control, maintenance, data location and cost.
What a hand-written loop must handle (verified mechanics)
Call the model → check stop_reason → run each tool_use → return every tool_result with the matching id → append to history → repeat. Also: pause_turn for server tools, max_tokens truncation, refusal, errors and retries, a step limit, and a clean stop.
Hooks for deterministic actions
Hooks run your code at lifecycle points (for example PreToolUse, PostToolUse, Stop, SubagentStop, PreCompact). A PreToolUse hook can deny, ask, allow or defer a call and rewrite its input (updatedInput); PostToolUse can add context for the model. Use hooks for what must happen every time (block a command, log every call, format after edits); use prompts for what should usually happen. Detail: 7.3.
Five design levers (design guidance)
Instructions, tools, permissions, context management, stop conditions. Most agent problems are fixed by adjusting one of these.
Product rules
Products you offer to others must use API key authentication; third parties may not offer claude.ai login or its rate limits without approval. Do not brand your product as "Claude Code"; "Claude Agent" or "Powered by Claude" is allowed.
Exam traps
- Agent SDK = client SDK. The Agent SDK wraps Claude Code's loop.
- Managed Agents for a ZDR or HIPAA-BAA workload. Not eligible.
- No step limit in a custom loop.
- "Never delete production data" written only in the prompt: enforce with hooks, permissions or sandboxing.
- Shipping a product on claude.ai login.
References
- Agent SDK overview — checked Oct 16, 2026
- Managed Agents overview — checked Oct 16, 2026
- Hooks in the SDK — checked Oct 16, 2026
- Handling stop reasons — checked Oct 16, 2026
- Tool use overview — checked Oct 16, 2026
Check your understanding
Claude Code's file and shell tools inside your own service. Option?Show answerHide answer
Answer
Agent SDK.A long-running agent with no infrastructure to manage, data must stay in your VPC. Option?Show answerHide answer
Answer
Managed Agents with a self-hosted sandbox.A custom loop sometimes runs forever. Missing?Show answerHide answer
Answer
A stop condition (step limit, budget, success check).Log every tool call, guaranteed. Mechanism?Show answerHide answer
Answer
A hook (PostToolUse).