docs: add approval-bound tool execution example - #6757
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe tool hooks guide adds approval-bound side-effect documentation. It covers deterministic SHA-256 action digests, approval decisions, human review, and execution blocking. Later use-case headings are renumbered from 3–6 to 4–7. ChangesTool Hooks Documentation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/edge/en/learn/tool-hooks.mdx (1)
186-190: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winHarden
stable_digestagainst non-JSON-serializable tool inputs.
stable_digestcallsjson.dumps(action, sort_keys=True, separators=(",", ":"))on anactiondict that embedsctx.tool_inputdirectly.tool_inputis typed asdict[str, Any], so a value that is not natively JSON-serializable (adatetime,UUID,Decimal,Enum,Path, or another custom object) raisesTypeErrorinside the hook. The guide documentsHookAbortedas the deliberate way to block a call, but does not describe this failure mode. The same risk applies to thejson.dumps(action, indent=2, sort_keys=True)call used for the human-readable prompt.Add a
default=strfallback to bothjson.dumpscalls so the example degrades gracefully instead of crashing on non-JSON-native fields.📝 Proposed fix
def stable_digest(action: dict[str, Any]) -> str: - payload = json.dumps(action, sort_keys=True, separators=(",", ":")) + payload = json.dumps(action, sort_keys=True, separators=(",", ":"), default=str) return hashlib.sha256(payload.encode("utf-8")).hexdigest()response = ctx.request_human_input( prompt=f"Approve {ctx.tool_name} action?", default_message=( f"Action digest: {digest}\n" - f"Action: {json.dumps(action, indent=2, sort_keys=True)}\n" + f"Action: {json.dumps(action, indent=2, sort_keys=True, default=str)}\n" "Type 'yes' to approve:" ), )Also applies to: 215-222
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/edge/en/learn/tool-hooks.mdx` around lines 186 - 190, Add a default=str fallback to both json.dumps calls in the tool-hook example: stable_digest and the human-readable action prompt serialization. Preserve the existing sorting, separators, and indentation options so non-JSON-serializable tool inputs are converted to strings instead of raising TypeError.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@docs/edge/en/learn/tool-hooks.mdx`:
- Around line 186-190: Add a default=str fallback to both json.dumps calls in
the tool-hook example: stable_digest and the human-readable action prompt
serialization. Preserve the existing sorting, separators, and indentation
options so non-JSON-serializable tool inputs are converted to strings instead of
raising TypeError.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9157506c-b690-4442-8b23-942fd1f04f85
📒 Files selected for processing (1)
docs/edge/en/learn/tool-hooks.mdx
|
Thanks for the review. The current PR head already applies the suggested |
Summary
Checks