# Practical ways to use the Claude Agent SDK
🤖 Delegate specialized tasks to sub-agents and keep your main context lean.
Sub-agents delegate specific subtasks to specialized agents, enabling parallel and expert processing without polluting the main agent's context.
📌 Title: Sub-agents in the SDK
🔗 URL:
🧩 Overview
Define specialized agents via the `agents` parameter. The main agent calls them through the `Agent` tool. Each sub-agent gets its own prompt, tool restrictions, and model settings. Results return as summaries to the main agent.
🛠 How to use it
Define sub-agents in the `agents` parameter using `AgentDefinition` with `description`, `prompt`, `tools`, and `model`. Include `"Agent"` in `allowed_tools` to auto-approve sub-agent invocations. Each sub-agent gets its own tool restrictions, prompt, and model settings.
🏗 Practical usage
- Delegate large file exploration to a `research-assistant` sub-agent, returning only summaries to the parent. Keeps main context lean.
- Run `style-checker` / `security-scanner` / `test-coverage` concurrently, reducing code review time from minutes to seconds.
- Give a `database-migration` sub-agent SQL best practices and rollback strategies in its prompt for expert handling.
- Use factory functions to dynamically select `model: "opus"` vs `sonnet` based on runtime conditions.
💡 Use cases
🔍 Delegating large-scale file exploration
⚡ Parallel code review (style/security/coverage)
🎯 Expert task splitting across specialized agents
⚠️ Watch out
Sub-agents cannot spawn their own sub-agents (one level only). For large-scale orchestration, use the `Workflow` tool (TS v0.3.149+). Capture `agentId` and `session_id` for follow-up via `resume`.
#
ClaudeAgentSDK# #
AI#