Approval Workflows

When an agent attempts an action that requires human approval (as defined in its Policy), the SDK automatically pauses execution, sends an MFA notification to the human, and waits for the response.

Handling Approvals

Your agent code doesn't need complex state machines. The SDK handles the polling and blocking seamlessly.

TypeScript
try {
  // If this action requires approval, the SDK blocks here.
  // A Slack/Email notification is sent to the admin.
  const result = await nayker.execute({
    action: 'transfer_funds',
    payload: { amount: 5000, currency: 'USD' },
    notify: 'admin_slack_channel'
  });
  
  console.log("Action approved and executed!");
} catch (error) {
  if (error.code === 'APPROVAL_DENIED') {
    console.log("The human denied this action.");
  }
}
Python
try:
    # Execution blocks until approved via Slack
    result = nayker.execute(
        action="transfer_funds",
        payload={"amount": 5000, "currency": "USD"},
        notify="admin_slack_channel"
    )
    print("Approved!")
except NaykerApprovalDeniedError:
    print("The human denied this action.")

Slack Notification Format

The human reviewer receives a rich Slack message containing the Agent ID, the proposed payload, and a risk score, with "Approve" and "Deny" buttons.

Common Errors

  • APPROVAL_TIMEOUT: The human did not respond within the timeframe defined in the policy.
  • APPROVAL_DENIED: The human clicked the Deny button.