"""Order action tools -- write operations requiring human approval.""" from __future__ import annotations from langchain_core.tools import tool from langgraph.types import interrupt @tool def cancel_order(order_id: str) -> dict: """Cancel an order. Requires human approval before execution.""" response = interrupt( { "action": "cancel_order", "order_id": order_id, "message": f"Please confirm: cancel order {order_id}?", } ) if isinstance(response, bool): approved = response elif isinstance(response, dict): approved = response.get("approved", False) else: approved = bool(response) if approved: return { "status": "cancelled", "order_id": order_id, "message": f"Order {order_id} has been successfully cancelled.", } return { "status": "kept", "order_id": order_id, "message": f"Order {order_id} cancellation was declined. The order remains active.", }