Skip to main content

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.

Status: 0.1.0, built and unit-tested locally. Not yet published to PyPI.

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": "Lowe's",
    "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 can json.loads the output.
  • Failures raise. Every failure — missing key, timeout, network error, non-2xx status, malformed response — raises SealgrafError (API failures raise SealgrafApiError with .status_code, .detail, and the server's stable .code when 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_approval is a normal outcome, not an error.
  • Fail closed. A fresh allow without a decision token is treated as malformed and raises. An idempotent replay of a check returns the original record flagged "replayed": true with "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 14: groceries, household, dining, travel, software, office_supplies, shopping, transport, entertainment, health, supplies, materials, equipment, fuel).
  • The key travels only in the X-API-Key header. 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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-sealgraf 0.1.0
File Size Uploaded Provenance Actions
langchain_sealgraf-0.1.0.tar.gz 23.2 kB Without provenance Details for langchain_sealgraf-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-sealgraf 0.1.0
File Interpreter ABI Platform Actions
langchain_sealgraf-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_sealgraf-0.1.0-py3-none-any.whl

Total release size: 41.2 kB

Release files / langchain_sealgraf-0.1.0.tar.gz

Download URL langchain_sealgraf-0.1.0.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
08f93c444a692f294916931b845ef8d1f3a1896f693d4c54cfb59f03cc023f8d
BLAKE2b-256 checksum
How to use checksums
3fe84c669ef3bcc20fab72862a76f677cb65d6086d2c39d2de31b72649c6a1da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / langchain_sealgraf-0.1.0-py3-none-any.whl

Download URL langchain_sealgraf-0.1.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2f8656f25d15f6f45e3ea3efa690acdc4571eb50e586c2f7803eb3a29b6eb7f
BLAKE2b-256 checksum
How to use checksums
081c64e503c5aa22bf86086644d3f2748779ed5e1d6c4cdc00a90d2723ff43ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for langchain-sealgraf 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page