[DOCS] Python subagent example uses incorrect pattern to detect tool_use blocks
Documentation Type
Incorrect/outdated documentation
Documentation Location
https://platform.claude.com/docs/en/agent-sdk/subagents#detecting-subagent-invocation
Section/Topic
"Detecting subagent invocation" section, Python code example
Current Documentation
The Python example uses this pattern to detect tool_use blocks:
if getattr(block, 'type', None) == 'tool_use' and block.name == 'Task':
print(f"Subagent invoked: {block.input.get('subagent_type')}")
What's Wrong or Missing?
The getattr(block, 'type', None) == 'tool_use' check will always fail because ToolUseBlock dataclasses in the Python SDK do not expose a type attribute.
Other Python examples in the documentation correctly use isinstance():
todo-tracking.md:if isinstance(block, ToolUseBlock) and block.name == "TodoWrite":python.md:if isinstance(block, ToolUseBlock):
The subagents page is inconsistent with the rest of the Python SDK documentation.
Suggested Improvement
Before:
if getattr(block, 'type', None) == 'tool_use' and block.name == 'Task':
After:
if isinstance(block, ToolUseBlock) and block.name == 'Task':
This follows the Pythonic pattern used elsewhere in the SDK documentation and will actually work.
Impact
High - Prevents users from using a feature
Additional Context
Affected Pages:
| Page | Line(s) | Context |
|------|---------|---------|
| https://platform.claude.com/docs/en/agent-sdk/subagents | 294 | Python example for detecting subagent invocation |
Total scope: 1 page affected
Correct patterns for reference:
| Page | Line(s) | Pattern Used |
|------|---------|--------------|
| https://platform.claude.com/docs/en/agent-sdk/todo-tracking | 66, 160 | isinstance(block, ToolUseBlock) |
| https://platform.claude.com/docs/en/agent-sdk/python | 2063, 2101 | isinstance(block, ToolUseBlock) |
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗