You are building developer productivity tools using the Claude Agent SDK. The agent helps engineers explore unfamiliar codebases, understand legacy systems, generate boilerplate code, and automate repetitive tasks. It uses the built-in tools (Read, Write, Bash, Grep, Glob) and integrates with Model Context Protocol (MCP) servers.
An engineer asks your agent to add comprehensive tests to a legacy codebase with 200 files and minimal existing test coverage. The engineer hasn't specified which modules to prioritize.
How should the agent decompose this open-ended task?
The task is open-ended because neither the critical modules nor the required testing sequence is known in advance. The agent should first use lightweight discovery tools to map the repository, locate existing tests, identify central modules, and determine which components have high fan-in, business significance, complex branching, or extensive external dependencies. It can then produce an initial risk-based testing plan and refine it as new dependency information appears.
Anthropic distinguishes predefined workflows from agents that dynamically control their processes and tool usage. Agents are appropriate when the required steps cannot be reliably hardcoded and must adapt to environmental evidence. During execution, they should obtain ground truth through tool results and use that feedback to determine subsequent actions. (https://www.anthropic.com/research/building-effective-agents) Anthropic also identifies orchestrator-worker designs as suitable for complex coding and search tasks where the necessary subtasks depend on what the investigation reveals. (https://www.anthropic.com/research/building-effective-agents)
Option A assigns effort using directory boundaries rather than risk. Option C exhausts context before delivering value. Option D uses alphabetical order, which has no relationship to impact or coverage priority.
Option B establishes an evidence-driven decomposition: discover, prioritize, test high-impact paths, measure results, and revise the plan as dependencies and uncovered risks emerge.
Official references/topics: Dynamic Task Decomposition; Adaptive Agent Loops; Orchestrator-Workers; Risk-Based Test Planning.