1.2 — Agent Construction with Claude
CCDV-F Domain 1 · Task 1.2
What You Need to Know
An agent is a model calling tools in a loop. The harness is the code that runs the loop. A turn is one round trip. A hook is harness code that runs at a fixed point.
The Bare Loop
Send prompt with tool definitions → if response requests tools, execute them, append results, call again → end when no tool calls or a cap trips. Production needs a harness: turn caps, spend budgets, retries, tool-result validation, state persistence and observability. These belong in code, never in the prompt.
The Agent SDK as the Packaged Harness
Key options:
max_turns/maxTurns— caps the loop (tool-use turns only)max_budget_usd/maxBudgetUsd— stops when estimated spend reaches the dollar value
Both default to no limit. Result subtypes: success, error_max_turns, error_max_budget_usd, error_during_execution (also error_max_structured_output_retries). Every subtype carries total_cost_usd, num_turns, session_id. The result text is present only on success.
Budget is cumulative across subagents. Subagent spawn depth and concurrency are controlled by environment variables (CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH, CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS).
A limit result is not a model failure. Documented recovery: resume the session with a raised limit, tighten the task brief, or split oversized work.
Where the Agent Runs
- Self-hosted: your process runs the loop (custom or Agent SDK)
- Anthropic-hosted: Claude Managed Agents (separate product; REST API; Anthropic runs the harness and sandbox)
Hooks Enforce, Prompts Request
A PreToolUse hook fires before a tool executes and can deny it deterministically. A system-prompt rule is an instruction the model may not follow. A hook executes outside the model’s discretion.
Key Concept: “Prompts request, hooks enforce” is the exam’s favourite construction.
Exam Traps
- Accepting max_iterations, budget_limit or turn_cap as real SDK options
- Reading error_max_turns as the model failing, then fixing it with a better prompt
- Treating a system-prompt prohibition as a guardrail equivalent to a hook
- Assuming subagent spend escapes the parent’s budget cap
- Describing Claude Managed Agents as the Agent SDK hosted for you
Check your understanding
Practice Scenario
A developer-platform team ships a repository-maintenance agent with Bash access. Policy says it must never invoke the production database CLI, even if malicious text in a cloned repository instructs it to. Which control actually enforces the policy?
Log in to save your progress.
Sources
- Tutorial: Build a tool-using agent, Claude Platform Docs
- How the agent loop works, Claude Code Docs
- Give Claude custom tools, Claude Code Docs
- Building with the Claude API, Anthropic Academy