# 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#