Nuggets authority middleware for LangChain / LangGraph
Project description
langchain-nuggets
Authority middleware for LangChain / LangGraph — pre-execution trust enforcement on every tool call.
Wrap any ToolNode and the middleware calls the Nuggets authority endpoint before each tool executes. The backend evaluates a scoped delegation, returns an ALLOW or DENY decision, and signs an audit proof. Tools that aren't allowed never run.
Installation
pip install langchain-nuggets
For LangGraph Platform OIDC auth:
pip install langchain-nuggets[langgraph]
Authority Middleware
from langchain_nuggets.middleware import NuggetsAuthorityMiddleware, MiddlewareConfig
from langgraph.prebuilt import ToolNode
config = MiddlewareConfig(
api_url="https://accounts.nuggets.life",
oidc_issuer_url="https://auth.nuggets.life",
agent_id="did:web:auth.nuggets.life:your-agent-id",
controller_id="did:web:auth.nuggets.life:your-controller-id",
delegation_id="42",
agent_private_key="/secrets/agent-jwks.json",
)
middleware = NuggetsAuthorityMiddleware(config)
tool_node = ToolNode(
tools=your_tools,
wrap_tool_call=middleware.wrap_tool_call,
)
Execution model: Agent → Tool Call → Nuggets Authority Check → Allow/Deny → Emit Proof
Trust primitives enforced: Actor Identity, Authority (delegation), Policy, Intent, Consent, Accountability (provenance).
| Behaviour | Detail |
|---|---|
| ALLOW | Tool executes; cryptographic proof artifact emitted |
| DENY | Tool blocked; structured error returned with reason_code |
| ERROR | Fail closed — tool not executed |
To provision the agent identity, private key, and delegation referenced above, see the agent provisioning runbook.
Proof verification (on by default)
Every ALLOW carries a proof signed by the authority, and the SDK verifies it before the tool runs — discovering the authority's signing identity from {api_url}/.well-known/authority-configuration, pinning the proof's issuer to that authority, verifying the signature against the published JWKS, and binding the proof to the request. Any failure fails closed: DENY with reason_code = PROOF_VERIFICATION_FAILED, tool not run. On by default — no config.
Every decision is therefore independently verifiable. A third party can validate an emitted proof out-of-band:
from langchain_nuggets.middleware import verify_authority_proof, discover_authority
issuer, jwks_uri = discover_authority("https://accounts.nuggets.life")
verify_authority_proof(proof_jws, expected={...}, issuer=issuer, jwks_uri=jwks_uri)
Opt out only deliberately (e.g. an offline harness verifying proofs separately): MiddlewareConfig(..., verify_proofs=False).
With create_agent
For the LangChain create_agent API, install the agent extra and use the AgentMiddleware adapter (same config, same enforcement):
pip install langchain-nuggets[agent]
from langchain.agents import create_agent
from langchain_nuggets.middleware import NuggetsAuthorityAgentMiddleware, MiddlewareConfig
agent = create_agent(
model="...",
tools=your_tools,
middleware=[NuggetsAuthorityAgentMiddleware(MiddlewareConfig(...))],
)
Agent private key
The accounts portal generates an RS256 keypair at agent creation and lets you download the private key as a JWKS file. MiddlewareConfig.agent_private_key accepts:
- A filesystem path to a PEM, JWK JSON, or JWKS JSON file
- A raw PEM string
- A JWK or JWKS dict
The key is never transmitted; only the signed agent_proof JWS is sent.
Test mode
test_mode=True short-circuits the live auth flow during local development — every check returns ALLOW, no HTTP is made, and the emitted proof artifact is flagged as test-mode-unverifiable.
LangGraph Platform OIDC auth
from langchain_nuggets.langgraph import NuggetsAuth
nuggets = NuggetsAuth(issuer_url="https://auth.nuggets.life")
auth = nuggets.auth # pass to langgraph.json
Pre-built authorization helpers:
from langchain_nuggets.langgraph import require_scopes, ownership_filter
Self-hosted / private CA
Point the URLs at your own deployment and pass ca_cert to either constructor:
MiddlewareConfig(
api_url="https://nuggets.internal.example.com",
oidc_issuer_url="https://oidc.internal.example.com",
# ...
ca_cert="/etc/ssl/private-ca/nuggets-ca.pem",
)
Set verify_ssl=False to disable TLS verification (development only).
About Nuggets
Nuggets provides decentralized identity and verifiable trust infrastructure for people and AI agents. Learn more at nuggets.life.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_nuggets-1.0.0.tar.gz.
File metadata
- Download URL: langchain_nuggets-1.0.0.tar.gz
- Upload date:
- Size: 33.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fae5e2e35b0809255601b88c7f0c8cd1cc849f274cac97554aea91ea15ec27cd
|
|
| MD5 |
7afed057ec3edcc162de66c1574e7939
|
|
| BLAKE2b-256 |
b139c40c1dd39a69e212791ed97c53320606dcbfcb324b5936553e5ec1938b00
|
Provenance
The following attestation bundles were made for langchain_nuggets-1.0.0.tar.gz:
Publisher:
release-pypi.yml on NuggetsLtd/langchain-nuggets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_nuggets-1.0.0.tar.gz -
Subject digest:
fae5e2e35b0809255601b88c7f0c8cd1cc849f274cac97554aea91ea15ec27cd - Sigstore transparency entry: 1766151092
- Sigstore integration time:
-
Permalink:
NuggetsLtd/langchain-nuggets@3822407edb474fabecacb6bb937849752b7c3c98 -
Branch / Tag:
refs/tags/python-v1.0.0 - Owner: https://github.com/NuggetsLtd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@3822407edb474fabecacb6bb937849752b7c3c98 -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchain_nuggets-1.0.0-py3-none-any.whl.
File metadata
- Download URL: langchain_nuggets-1.0.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73d19280ca295cad864c48126bc3394b02b7c64649d96da6924e104d781cd14a
|
|
| MD5 |
47fbb2194bc632d73754bb889b6b26af
|
|
| BLAKE2b-256 |
b2f9393437e282600c05f3cbc1bdc01ae28633d090701f4e33f6a49f31f6ed7d
|
Provenance
The following attestation bundles were made for langchain_nuggets-1.0.0-py3-none-any.whl:
Publisher:
release-pypi.yml on NuggetsLtd/langchain-nuggets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_nuggets-1.0.0-py3-none-any.whl -
Subject digest:
73d19280ca295cad864c48126bc3394b02b7c64649d96da6924e104d781cd14a - Sigstore transparency entry: 1766151428
- Sigstore integration time:
-
Permalink:
NuggetsLtd/langchain-nuggets@3822407edb474fabecacb6bb937849752b7c3c98 -
Branch / Tag:
refs/tags/python-v1.0.0 - Owner: https://github.com/NuggetsLtd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@3822407edb474fabecacb6bb937849752b7c3c98 -
Trigger Event:
push
-
Statement type: