langchain-sealgraf
Sealgraf spend-approval tools for LangChain agents.
Sealgraf is the owner-approval layer for agent spending: the agent checks BEFORE buying → the owner approves above their pre-set limits on Sealgraf's own surface → the completed purchase is sealed into a receipt neither side can rewrite. This package wraps the full loop — including the token claim and the completion, which go over Sealgraf's REST API — as four LangChain tools.
Install
pip install langchain-sealgraf
Depends only on langchain-core, httpx, and pydantic — not the
full langchain metapackage.
Configure
The API key is an agent-scope Sealgraf key. It is host configuration, never a tool argument (tool arguments are chosen by the model and land in prompts and logs).
export SEALGRAF_API_KEY=<your agent-scope API key>
# optional:
export SEALGRAF_BASE_URL=https://sealgraf.com # default
export SEALGRAF_TIMEOUT_SECONDS=20 # default
Or pass configuration in code:
from langchain_sealgraf import get_sealgraf_tools
tools = get_sealgraf_tools(api_key="see_...", base_url="https://sealgraf.com")
# or hand in a pre-built client:
from langchain_sealgraf import SealgrafClient, get_sealgraf_tools
tools = get_sealgraf_tools(SealgrafClient("https://sealgraf.com", "see_..."))
Use
from langchain_sealgraf import get_sealgraf_tools
tools = get_sealgraf_tools()
# → [sealgraf_check_permission, sealgraf_claim_decision_token,
# sealgraf_complete_purchase, sealgraf_get_receipt]
# Any LangChain agent that takes tools can run the loop:
agent = create_agent(model, tools=tools) # LangChain v1 style
# or bind them to a chat model, a graph, or call them directly:
check = tools[0]
print(check.invoke({
"category": "household",
"amount_minor": 4250, # $42.50, integer minor units
"counterparty": "Example Hardware",
"description": "Trash bags",
}))
SealgrafToolkit().get_tools() returns the same four tools as a
bundle.
The four tools
| Tool | Sealgraf operation | Purpose |
|---|---|---|
sealgraf_check_permission |
POST /v1/preauthorize |
Ask permission BEFORE buying. Returns allow (with a single-use decision_token), deny, or needs_human_approval. |
sealgraf_claim_decision_token |
POST /v1/preauthorize/{id}/decision-token |
After the owner approves, claim the single-use decision token. Fails with code not_approved_yet while the owner hasn't decided — wait and retry. |
sealgraf_complete_purchase |
POST /v1/preauthorize/{id}/complete |
Report the finished purchase; Sealgraf seals it into a receipt. Retry-safe with the same completion_nonce. |
sealgraf_get_receipt |
GET /v1/preauthorize/{id} or GET /v1/receipts/{id} |
Read a check's state or a sealed receipt. |
Conventions
- Outputs are JSON strings. Each tool returns the parsed Sealgraf
result serialized as JSON (per LangChain's string-return convention)
with a stable shape:
outcome,state,preauth_id,decision_token,receipt_id,replayed, ... A chain that needs the values canjson.loadsthe output. - Failures raise. Every failure — missing key, timeout, network
error, non-2xx status, malformed response — raises
SealgrafError(API failures raiseSealgrafApiErrorwith.status_code,.detail, and the server's stable.codewhen it sends one). The tools never return an error string: in a spend loop, a raised error fails the tool call outright, while an error-shaped string is one misreading away from a purchase.needs_human_approvalis a normal outcome, not an error. - Fail closed. A fresh
allowwithout a decision token is treated as malformed and raises. An idempotent replay of a check returns the original record flagged"replayed": truewith"decision_token_redelivered": false— Sealgraf never re-serves tokens, and a replay is never presented as a fresh permission. - Amounts are integer minor units (cents): $42.50 is
4250, everywhere. - Categories are a closed list (Sealgraf's canonical 17: groceries, household, dining, travel, software, office_supplies, shopping, transport, entertainment, health, supplies, materials, equipment, fuel, services, shipping, repairs).
- The amount paid is required.
sealgraf_complete_purchaseneedscompleted_amount_minor— what was actually paid, in cents. Sealgraf seals it as the amount the agent reported; it does not see or move the payment itself. - No verification link. This package does not create a shareable check link or a receipt view. Its tools return the sealed receipt record; the owner views and shares receipts in their Sealgraf account.
- The key travels only in the
X-API-Keyheader. Decision tokens are passed through untouched and are never logged by this package.
The spend loop
check_permission ── allow ──────────────► complete_purchase ──► receipt
│
└─ needs_human_approval ─► owner approves in Sealgraf
└─► claim_decision_token ─► complete_purchase
│
└─ deny ─► do not buy
Development
python -m venv .venv && .venv/bin/pip install -e ".[test]"
.venv/bin/python -m pytest # mocked HTTP only; no network
License
MIT
Metadata
Release files for langchain-sealgraf 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_sealgraf-0.1.1.tar.gz | 24.6 kB | Without provenance | Details for langchain_sealgraf-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_sealgraf-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for langchain_sealgraf-0.1.1-py3-none-any.whl |
Total release size: 43.6 kB
Release files / langchain_sealgraf-0.1.1.tar.gz
| Download URL | langchain_sealgraf-0.1.1.tar.gz |
|---|---|
| Size | 24.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52dcab28bf42eef8b91d2106a95de5f68cbfbeadd19424515df456f4459eb4e5
|
|
BLAKE2b-256 checksum How to use checksums |
2f281bec7c2969eb778d9fbeccf3d9605153123e03d89cc717d30c6a81e65ea8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / langchain_sealgraf-0.1.1-py3-none-any.whl
| Download URL | langchain_sealgraf-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46a52b354384593e2c6f5e289b14d9bc72b4e83d4b06e062d7da11329e60ff88
|
|
BLAKE2b-256 checksum How to use checksums |
f2a573e8d40c57a1200aab19ee918b5e37a3c27ac880568d0b7c3ff4cac58410
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for langchain-sealgraf 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.