ARCHITECTURE · SECURITY · OVERSIGHT · 5 MIN READ

A human approval boundary for agent actions

Pause before consequential writes and approve the exact proposed operation.

Download example files Code + setup + checks in a ZIP
Jump to a section 11 sections

EXAMPLE USE CASE

Approve one exact draft without allowing later recipient changes

An agent may prepare a message, but approval must bind to its recipient and body rather than authorize any later send.

Input
An immutable draft proposal, reviewer identity, proposal digest and approval expiry.
Expected output
One simulated execution; a duplicate is deduplicated; a changed recipient is denied.
  • Success check: Only the exact unexpired proposal passes the check; a retry returns already completed.
  • Try a failure: Change the recipient or expire the decision. Neither may reuse the earlier approval.

Example scope: A local approval-contract lab that sends nothing. Authenticate reviewers and persist decisions/deduplication in a trusted service before enabling a real operation.

LangGraph examplePostgreSQL exampleOpen Policy Agent example
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
proposalreviewdecisionscoped approvalactual outcomeProposed operationExact action and payloadFrozen previewHash the proposalAuthorized reviewerConsent or rejectApproval recordScope, hash and expiryExecution gateRecheck before actingOutcome ledgerResult and audit
  1. Identify the actor, destination, resource, amount/content and stable operation ID before asking for review.

  2. Show a concrete reviewable result and bind its canonical payload to a digest/version.

  3. Verify the reviewer’s identity and scope. A model-produced approved flag is not a human decision.

  4. Persist who approved which immutable proposal, when it expires and whether it has been revoked.

  5. Verify the approval digest, expiry, current permissions and operation idempotency immediately before the effect.

  6. Record success, rejection, cancellation or uncertain outcome; reconcile repeated or interrupted operations.

    Result or stopping point
Frozen preview

Show a concrete reviewable result and bind its canonical payload to a digest/version.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

Components for this use case

  • A trusted review service stores reviewer identity, proposal digest, expiry and decision. The action service rechecks that record immediately before executing.
  • A workflow runtime resumes after the decision. The source operation uses a stable idempotency key so a timeout cannot accidentally send twice.

Review an exact operation

  • Present the target, parameters, expected effect, and relevant evidence.
  • Bind approval to a specific action version.
  • If the proposal changes, require a new decision for the changed operation.

Revalidate at execution time

  • Check authorization, resource state, and approval validity immediately before committing.
  • Use an idempotency key.
  • A stale approval or expired user session should not silently authorize a new operation.

Handle uncertainty

  • Show whether a request is waiting, rejected, committed, or unresolved.
  • If execution times out, reconcile with the authoritative service before retrying.
  • Preserve who approved the operation and the resulting record.

Set up the lab

  • Python 3.11 or newer. This local lab exposes the control flow without a model call.
  • Use an empty directory; the example may create a local SQLite file.
Shell
python3 -m venv .venv
source .venv/bin/activate

Implement the example

Save as approval.py

Python · approval.py
import hashlib
import json
import time

def digest(payload):
    return hashlib.sha256(json.dumps(payload, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
proposal = {"operation_id": "op-104", "action": "send_draft", "recipient": "demo@example.invalid", "body": "Order packed"}
approval = {"hash": digest(proposal), "reviewer": "reviewer-1", "expires": time.time()+300}
executed = set()
def execute(payload, decision):
    if decision["expires"] <= time.time() or decision["hash"] != digest(payload):
        raise PermissionError("Expired approval or changed proposal")
    if payload["operation_id"] in executed:
        return "already completed"
    executed.add(payload["operation_id"])
    return "simulated send only"

print(execute(proposal, approval))
print(execute(proposal, approval))
try:
    execute({**proposal, "recipient":"changed@example.invalid"}, approval)
except PermissionError:
    print("changed recipient blocked")

Run and verify

Shell
python approval.py
  • The lab does not send a message. It demonstrates an approval bound to one immutable proposal.
  • The changed recipient is rejected and a repeated operation is deduplicated.

Troubleshooting and failure tests

  • A Boolean approved flag is insufficient if the draft, recipient, amount, or resources can change later.
  • The reviewer identity must come from authentication, not a model response or an unverified request field.

Before production

  • Persist approvals and operation IDs; authorize the reviewer and recheck current resource state at execution.
  • Expose expiry, cancellation, rejection and audit history; do not silently auto-approve after a timeout.

Keep exploring

A governed tool layer with MCPAn agent that can pause and resumeAI agent evaluation: frameworks, tools and an example