from agent_sentinel import guarded_action@guarded_action( name="transfer_funds", cost_usd=0.10, requires_human_approval=True, approval_description="Transfer funds between customer accounts",)def transfer_funds(from_acct: str, to_acct: str, amount: float): # This will block until human approves/rejects return transfer_service.execute(from_acct, to_acct, amount)
PolicyEngine.configure() is a convenience wrapper for budget/rate-limit/evidence settings; approval kwargs (require_approval, approval_actions, approval_threshold_usd, approval_timeout_seconds, approval_tags, approval_risk_levels) live on PolicyConfig and are typically authored via the platform UI and synced to the SDK by enable_remote_sync. For local-only configuration, assign PolicyEngine._config directly as shown above.
Approval statistics
View approval metrics via platform:
GET /api/v1/approvals/stats
Returns:
Total pending approvals
Average decision time
Approval vs rejection rate
Counts by priority/risk level
Custom approval handlers (for custom UI)
If not using the web console, implement a custom approval handler:
from agent_sentinel import HumanApprovalHandler, ApprovalRequest, ApprovalResponse, ApprovalStatusdef my_approval_handler(request: ApprovalRequest) -> ApprovalResponse: # Send to Slack, custom UI, etc. slack_response = send_slack_approval_request( channel="#approvals", action=request.action_name, description=request.description, cost=request.estimated_cost, ) # Wait for human response (blocking) decision = wait_for_slack_response(slack_response.ts) return ApprovalResponse( request_id=request.request_id, status=ApprovalStatus.APPROVED if decision.approved else ApprovalStatus.REJECTED, decided_by_email=decision.approver_email, decision_notes=decision.notes, )# Register handlerHumanApprovalHandler.set_approval_handler(my_approval_handler)
Best practices
Set appropriate timeouts: Critical actions should have short timeouts (5-10 min), while less urgent actions can have longer timeouts (1-24 hours).
Use risk levels: Classify actions by risk to help approvers prioritize. Critical-risk items should notify immediately.
Handle timeouts gracefully: Always handle EXPIRED status - don’t assume approvals will be granted within the timeout window.
Provide context: Include detailed descriptions and input parameters so approvers can make informed decisions without needing to ask for more info.