Your first purchase with Sealgraf and LangChain
Use the published LangChain tools to check a purchase, handle an owner decision, and report the completed purchase. No LLM or payment integration is required for this operator-led walkthrough. It does not make a payment. You make the purchase separately only after an allowed decision.
Prepare your account
Create a free account, set a mandate and create an agent key. Use a purchase you actually intend to make, in a category permitted by your mandate. To exercise owner approval, choose an amount above your approval threshold but within your purchase cap and remaining budget.
Install the package, then run the following blocks in the same Python session. Keep the session private: the decision token is a credential.
pip install langchain-sealgraf==0.1.1
Check before buying
Enter your actual proposed purchase, not demonstration payment data. Amounts are integer minor units: 1250 means USD 12.50. Keep the request identity and original result; do not generate a new identity when retrying a lost response.
import json
import os
from getpass import getpass
from langchain_sealgraf import get_sealgraf_tools
os.environ["SEALGRAF_API_KEY"] = getpass("Agent API key: ")
tools = {tool.name: tool for tool in get_sealgraf_tools()}
check_args = {
"category": input("Allowed purchase category: "),
"amount_minor": int(input("Proposed amount in minor units: ")),
"currency": "USD",
"counterparty": input("Seller: "),
"description": input("What are you buying? "),
"idempotency_key": input("Unique request identity (8+ characters): "),
}
check = json.loads(tools["sealgraf_check_permission"].invoke(check_args))
print("Outcome:", check["outcome"])
preauth_id = check["preauth_id"]
A denial means stop: do not pay or run the completion block. If the outcome requires human approval, stop here and notify the owner. The owner decides in Sealgraf. After the owner confirms a decision, read the original check once; do not keep an agent polling while it waits.
status = json.loads(tools["sealgraf_get_receipt"].invoke({
"preauth_id": preauth_id,
}))
print("State:", status["state"])
If this is an owner-approved check and its state is authorized, collect its token once. An immediately allowed check already includes its token; do not claim it again.
if check["outcome"] == "needs_human_approval":
if status["state"] != "authorized":
raise RuntimeError("Not authorized: do not pay")
claim = json.loads(tools["sealgraf_claim_decision_token"].invoke({
"preauth_id": preauth_id,
}))
decision_token = claim.get("decision_token")
elif check["outcome"] == "allow":
decision_token = check.get("decision_token")
else:
raise RuntimeError("Denied: do not pay")
if not decision_token:
raise RuntimeError("No token recovered: stop and preserve the original check")
Make the purchase through your own payment channel
Run this guard immediately before proceeding to your payment channel:
from datetime import datetime, timezone
expiry = (claim if check["outcome"] == "needs_human_approval" else check).get("token_expires_at")
if status["state"] != "authorized" or not expiry:
raise RuntimeError("No current authorization: do not pay")
if datetime.fromisoformat(expiry.replace("Z", "+00:00")) <= datetime.now(timezone.utc):
raise RuntimeError("Authorization expired: do not pay")
Before paying, confirm the original authorization is still valid and the seller, category, currency and amount match the proposed purchase. The check or claim returns the token expiry; do not use an expired token. If terms change, resolve that change before initiating payment.
Make the purchase once, through your own checkout or separately configured payment tool. Retain the merchant's payment result and actual charged amount. A timeout or uncertain payment result is not permission to pay again: reconcile the original attempt first.
Report only a completed purchase
Run this block only after you have independently confirmed the purchase completed. Enter the actual charge and merchant reference. The completion nonce identifies this completion and must remain unchanged across retries.
if input("Type PAID only after confirming the payment completed: ") != "PAID":
raise RuntimeError("No confirmed payment: stop")
completion_args = {
"preauth_id": preauth_id,
"decision_token": decision_token,
"completion_nonce": input("Stable completion nonce (8+ characters): "),
"completed_amount_minor": int(input("Actual charged amount in minor units: ")),
"counterparty_receipt_ref": input("Merchant payment/order reference: "),
"note": "Purchase completion reported by the operator",
}
completion = json.loads(
tools["sealgraf_complete_purchase"].invoke(completion_args)
)
receipt_id = completion["receipt_id"]
print("Sealed receipt:", receipt_id)
If the completion response is lost, retry **the same completion_args**, including the original amount and evidence. Do not repeat the payment. A seal is not amended on retry. If authorization expired before sealing, preserve the original decision and payment evidence and surface the unsealed result; a fresh check cannot retroactively authorize that payment.
Read the receipt
receipt = json.loads(tools["sealgraf_get_receipt"].invoke({
"receipt_id": receipt_id,
}))
print("Receipt retrieved:", receipt_id)
Open the receipt in your Sealgraf account to see its details and public verification link. The public view is masked: a stranger sees the kind of purchase, not the amount or merchant details. This walkthrough seals a caller-reported charge. It does not independently prove that your payment channel charged that amount.
Continue building
This walkthrough is deliberately operated step by step. An autonomous payment adapter also needs durable attempt state, transport-level duplicate-send protection, and read-only recovery of uncertain payments; those properties are not supplied by this example.