else branch: a failed constraint is a deny, not a fallthrough. The trusted host code chooses the capability based on the refund amount.mkdir dmint-refund-tutorial && cd dmint-refund-tutorial python3 -m venv .venv source .venv/bin/activate pip install dmint
dmint init-keys
~/.config/dmint/signing.key ~/.config/dmint/integrity.key
public_key_hex value; the host verifier needs it. The private key stays with the approval process.policy.json:{ "rules": [ { "effect": "allow", "tool": "billing", "action": "issue_small_refund", "constraints": { "properties": { "amount": { "type": "number", "maximum": 99.99 } } } }, { "effect": "approval_required", "tool": "billing", "action": "issue_large_refund", "constraints": { "properties": { "amount": { "type": "number", "minimum": 100, "maximum": 500 } } } } ] }
dmint verify-policy policy.json
✓ Verified policy.json: 2 rule(s) [ALLOW] tool='billing', action='issue_small_refund', resource='NoResource' [APPROVAL_REQUIRED] tool='billing', action='issue_large_refund', resource='NoResource'
resource, which means they match requests with no resource. That is intentional for this example, because the capability itself identifies the operation. If you add resource-bearing calls, use an explicit resource selector (and "resource": "*" for a global rule).deny rule is needed. A request that matches no rule is denied by default with DMT_DEFAULT_DENIED.dmint policy-digest policy.json
Dmint.local): If your agent and CLI run on the same development machine, you can skip dmint init-keys and replace the boilerplate setup below with a single line: dmint = Dmint.local("policy.json", agent_id="support-agent-01"). You can then retry with dmint.retry(issue_large_refund, "cust_42", 250.0, "ticket-1204") without passing approval_credential. The explicit setup below demonstrates the full split-key architecture for multi-host production deployments.app.py. Replace PASTE_PUBLIC_KEY_HEX with the value printed by dmint init-keys.from datetime import datetime, timedelta, timezone from pathlib import Path import sys from dmint import ( ApprovalRequiredError, AuthorizationError, ApprovalVerifier, Dmint, Policy, PolicyProvenance, SQLiteApprovalStore, TrustedContext, policy_digest, ) from dmint.core import public_key_from_hex PUBLIC_KEY_HEX = "PASTE_PUBLIC_KEY_HEX" policy = Policy.from_file("policy.json") store = SQLiteApprovalStore("approvals.sqlite3", deployment_epoch="default") provenance = PolicyProvenance( version_id="refund-policy-v1", policy_digest=policy_digest(policy), evaluated_at=datetime.now(timezone.utc), ) verifier = ApprovalVerifier( trusted_issuers={ "dmint-authority": public_key_from_hex(PUBLIC_KEY_HEX), }, audience="dmint/dashboard/v1", ) dmint = Dmint( policy=policy, agent_id="support-agent-01", context=TrustedContext({"tenant": "prod-us"}), approval_store=store, approval_verifier=verifier, policy_provenance=provenance, approval_ttl=timedelta(minutes=5), ) @dmint.protect("billing.issue_small_refund") def issue_small_refund(customer_id: str, amount: float, reason: str) -> str: return f"Refunded ${amount:.2f} to {customer_id}" @dmint.protect("billing.issue_large_refund") def issue_large_refund(customer_id: str, amount: float, reason: str) -> str: return f"Refunded ${amount:.2f} to {customer_id}" def issue_refund(customer_id: str, amount: float, reason: str) -> str: """Trusted host routing. The agent supplies data, not the route.""" if amount < 100: return issue_small_refund(customer_id, amount, reason) if amount <= 500: return issue_large_refund(customer_id, amount, reason) raise ValueError("Refunds over $500 require manual finance review") if __name__ == "__main__": if len(sys.argv) == 2: credential = Path(sys.argv[1]).read_bytes() print( dmint.retry( issue_large_refund, "cust_42", 250.0, "ticket-1204", approval_credential=credential, ) ) else: print(issue_refund("cust_42", 45.0, "duplicate charge")) try: print(issue_refund("cust_42", 250.0, "ticket-1204")) except ApprovalRequiredError as exc: print(f"Approval required: {exc.approval_id}")
issue_refund routing function is deliberately trusted host code. An agent cannot select issue_large_refund directly to bypass the policy, and the policy’s constraint on issue_large_refund denies any out-of-range amount even if a caller uses the capability directly.python app.py
Refunded $45.00 to cust_42 Approval required: apr_...
dmint pending --db-path approvals.sqlite3
APPROVAL ID TOOL/ACTION RESOURCE/TARGET PRINCIPAL REQUESTED ----------------------------------------------- --------------------- --------------- ---------------- --------- apr_... billing.issue_large_refund (none) support-agent-01 0s ago
dmint approve apr_... \ --db-path approvals.sqlite3 \ --policy policy.json \ --approver-id alice@example.com \ --authority-issuer dmint-authority \ --reason "Verified outage ticket #1204" \ --output-assertion approval.json
✓ Approved 'apr_...' (billing.issue_large_refund) successfully. Reason: Verified outage ticket #1204
APPROVED and writes the signed assertion to approval.json. The private key never goes to the agent process.The issuer passed to--authority-issuermust match the issuer ID in the verifier’strusted_issuersmapping. This example usesdmint-authority, the ID printed byinit-keys.
python app.py approval.json
Refunded $250.00 to cust_42
CONSUMED before executing the function.python app.py approval.json
ApprovalConsumedError (DMT_APPROVAL_CONSUMED). Requesting a different amount or argument also fails with DMT_APPROVAL_REQUEST_MISMATCH; an approval for $250 cannot authorize $251.dmint dashboard \ --db-path approvals.sqlite3 \ --approver-id alice@example.com \ --authority-issuer dmint-authority \ --port 8080
python app.py ./apr_....assertion.json
DMINT_DASHBOARD_IDENTITY_HEADER plus --trusted-proxy). See Human Approvals for the attribution rules.| Event | Result |
billing.issue_small_refund with $45 | ALLOW; function ran |
billing.issue_large_refund with $250 | APPROVAL_REQUIRED; no function execution |
Approval for $250 | APPROVED record plus signed assertion |
| Retry with the same arguments | Signature/fingerprint verified, record consumed once, function ran |
| Retry with different arguments | DMT_APPROVAL_REQUEST_MISMATCH; no execution |
| Replay after success | DMT_APPROVAL_CONSUMED; no execution |
| Policy changed after approval | DMT_APPROVAL_POLICY_INVALID; approval invalidated |