feat: expose agent_type on ToolPermissionContext for can_use_tool#1131
Open
sridhar-3009 wants to merge 1 commit into
Open
feat: expose agent_type on ToolPermissionContext for can_use_tool#1131sridhar-3009 wants to merge 1 commit into
sridhar-3009 wants to merge 1 commit into
Conversation
PreToolUse/PostToolUse/PermissionRequest hook inputs already carry agent_type alongside agent_id (via _SubagentContextMixin) so hook callbacks can tell which sub-agent a tool call came from. The can_use_tool permission-callback path never got the same treatment: SDKControlPermissionRequest only declared agent_id, and query.py's ToolPermissionContext construction only read agent_id off the wire payload, silently leaving agent_type on the table. This adds agent_type to SDKControlPermissionRequest and ToolPermissionContext, and forwards it in the can_use_tool control request handler, matching the existing agent_id plumbing. Addresses the permission-callback half of anthropics#275 (the hooks half was already covered by prior work on PreToolUse/PostToolUse/ PermissionRequest hook inputs).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the permission-callback half of #275 ("Expose subagent type to hooks and permission callbacks").
The hooks half of this request is already handled:
PreToolUseHookInput,PostToolUseHookInput,PostToolUseFailureHookInput, andPermissionRequestHookInputall carryagent_typealongsideagent_idvia_SubagentContextMixin(see the comment attypes.pyaroundBaseHookInput/_SubagentContextMixin— "agent_id/agent_type are present on BaseHookInput in the CLI's schema").The
can_use_toolpermission-callback path never got the same treatment:SDKControlPermissionRequest(the wire-protocol TypedDict for this control request) only declaredagent_id, notagent_type.query.py's_handle_control_requestonly readagent_idoff the request intoToolPermissionContext, droppingagent_typeeven though it travels alongsideagent_ideverywhere else in this schema.ToolPermissionContext(the dataclass callers ofcan_use_toolactually receive) had noagent_typefield at all.This PR adds
agent_typein all three places, mirroring the exactagent_idplumbing already in place, socan_use_toolcallbacks can attribute a permission decision to the correct sub-agent type (e.g. "code-reviewer" vs "general-purpose") the same way hook callbacks already can.Test plan
test_permission_callback_receives_agent_typeandtest_permission_callback_missing_agent_typeintests/test_tool_callbacks.py, mirroring the existingtest_permission_callback_receives_tool_use_id/test_permission_callback_missing_agent_idtests foragent_id.pytest(1241 passed, 5 pre-existing skips, no new failures)mypy src/(strict mode, clean)ruff check/ruff format --check(clean)🤖 Generated with Claude Code