How do you choose between a workflow, an agent and a multi-agent system?
Start with the simplest thing that works. Use a workflow when the steps are known and auditability matters: chaining, routing, parallelization, orchestrator-workers or evaluator-optimizer. Use an agent loop with a budget when the steps can't be known in advance. Move to multiple agents only for independent, parallel work that would overflow one context, and give each subagent a distinct, bounded brief.
How do Agent SDK hooks make behaviour deterministic?
Hooks are callbacks on events such as PreToolUse, PostToolUse and Stop. PreToolUse can allow, deny, ask, defer or rewrite a call with updatedInput, and deny wins when hooks disagree. Use hooks or the tool's own code for anything that must always happen. A throwing callback lets the action proceed unless the matcher sets onFailure: "block".
How do you diagnose a misbehaving agent from its trace?
Match the symptom to the missing pattern. Repeated identical calls point to no termination or budget. Late-run forgetting points to context bloat, so use subagents or compaction. Redone work after compaction points to no progress file. A returning user starting from scratch points to no memory. A false "done" points to no independent verification. A destructive action points to no human approval gate.
When should you use Claude Managed Agents instead of your own harness?
Use Managed Agents for long-running, asynchronous work when you don't want to build the loop, tool execution and sandbox yourself. You define an agent (model, prompt, tools, MCP servers, skills) and an environment (Anthropic's cloud sandbox or a self-hosted one), then run sessions and stream events. Use the Messages API or the Agent SDK when you need a custom loop and fine-grained control.