Been building a tiny external-consumer adapter around can_use_tool for evidence and review purposes. The seam feels really clean: the callback gives us tool_name, the tool_input dict, and a ToolPermissionContext carrying tool_use_id. That is everything a per-call policy gate needs, and it is materially simpler than reaching into message state.
One small thing we want to get right upfront. The SDK types annotate ToolPermissionContext.tool_use_id as str | None:
class ToolPermissionContext:
signal: Any | None
suggestions: list[PermissionUpdate]
tool_use_id: str | None
agent_id: str | None
For our use case, tool_use_id is what we use to correlate each policy decision back to the originating tool call in later audit. If it arrives as None, we have to fall back to a synthesized placeholder, which works but is not ideal.
Question: under what circumstances does tool_use_id actually arrive as None at the callback? Is that only hit on legacy or edge paths, or is it a real possibility for normal query() flows? Knowing when to expect None would let us calibrate the fallback path cleanly.
Tiny adapter that currently handles this defensively lives at Rul1an/Assay-Harness for reference.
Thanks for building the SDK. It has been a pleasure to work with.
Been building a tiny external-consumer adapter around
can_use_toolfor evidence and review purposes. The seam feels really clean: the callback gives ustool_name, thetool_inputdict, and aToolPermissionContextcarryingtool_use_id. That is everything a per-call policy gate needs, and it is materially simpler than reaching into message state.One small thing we want to get right upfront. The SDK types annotate
ToolPermissionContext.tool_use_idasstr | None:For our use case,
tool_use_idis what we use to correlate each policy decision back to the originating tool call in later audit. If it arrives asNone, we have to fall back to a synthesized placeholder, which works but is not ideal.Question: under what circumstances does
tool_use_idactually arrive asNoneat the callback? Is that only hit on legacy or edge paths, or is it a real possibility for normalquery()flows? Knowing when to expectNonewould let us calibrate the fallback path cleanly.Tiny adapter that currently handles this defensively lives at Rul1an/Assay-Harness for reference.
Thanks for building the SDK. It has been a pleasure to work with.