Skip to main content

Nuggets identity verification toolkit for LangChain Python

Project description

langchain-nuggets

Nuggets identity verification toolkit for LangChain Python. Provides 11 ready-to-use tools for KYC, KYA, and credential verification that plug directly into any LangChain agent.

Installation

pip install langchain-nuggets

Quick Start

from langchain_nuggets import NuggetsToolkit

# Config via env vars: NUGGETS_API_URL, NUGGETS_PARTNER_ID, NUGGETS_PARTNER_SECRET
toolkit = NuggetsToolkit()
tools = toolkit.get_tools()

# Or pass config directly
toolkit = NuggetsToolkit(
    api_url="https://api.nuggets.life",
    partner_id="your-partner-id",
    partner_secret="your-secret",
)

Tools

KYC (Know Your Customer)

Tool Description
initiate_kyc_verification Start identity verification flow, returns deeplink/QR for Nuggets app
check_kyc_status Poll verification session status (pending/completed/failed/expired)
verify_age Selective disclosure age proof without revealing date of birth
verify_credential Request specific credential (address, email, phone, nationality)

KYA (Know Your Agent)

Tool Description
register_agent_identity Register AI agent identity with DID and provenance signals
verify_agent_identity Verify another agent's identity and provenance
get_agent_trust_score Get trust score (0-1) based on verified signals

Auth & Credentials

Tool Description
request_credential_presentation Ask user to present verifiable credentials
verify_presentation Check presentation status and verify credentials
initiate_oauth_flow Start OAuth 2.0/OIDC flow with Nuggets as IdP
check_auth_status Check user's authentication and verification status

Usage with LangChain Agent

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_nuggets import NuggetsToolkit

toolkit = NuggetsToolkit()
tools = toolkit.get_tools()

llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant that can verify user identities using Nuggets."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

result = executor.invoke({"input": "Verify alice@example.com"})

Configuration

Parameter Env Variable Description
api_url NUGGETS_API_URL Nuggets API base URL
partner_id NUGGETS_PARTNER_ID Your partner ID
partner_secret NUGGETS_PARTNER_SECRET Your partner secret

Self-Hosted Deployment

All classes accept configurable URLs — point to your own Nuggets instance:

toolkit = NuggetsToolkit(
    api_url="https://nuggets.internal.example.com/api",
    partner_id="your-partner-id",
    partner_secret="your-secret",
)

Custom CA Certificates

For self-hosted instances using a private CA:

toolkit = NuggetsToolkit(
    api_url="https://nuggets.internal.example.com/api",
    partner_id="your-partner-id",
    partner_secret="your-secret",
    ca_cert="/etc/ssl/private-ca/nuggets-ca.pem",
)

The ca_cert and verify_ssl parameters are also available on:

  • NuggetsAuth(issuer_url=..., ca_cert=..., verify_ssl=...)
  • MiddlewareConfig(api_url=..., ca_cert=..., verify_ssl=...)
  • NuggetsApiClient({"api_url": ..., "ca_cert": ..., "verify_ssl": ...})

To disable TLS verification entirely (development/staging only):

toolkit = NuggetsToolkit(..., verify_ssl=False)

License

MIT

Authority Middleware

Intercept every LangChain/LangGraph tool call with pre-execution trust enforcement. The middleware validates authority against the Nuggets control plane, blocks unauthorized actions, and emits cryptographic proof artifacts.

from langchain_nuggets.middleware import NuggetsAuthorityMiddleware, MiddlewareConfig
from langgraph.prebuilt import ToolNode

config = MiddlewareConfig(
    api_url="https://api.nuggets.life",
    partner_id="your-partner-id",
    partner_secret="your-secret",
    agent_id="agent-001",
    controller_id="org-001",
    delegation_id="del-001",
)

middleware = NuggetsAuthorityMiddleware(config)

tool_node = ToolNode(
    tools=your_tools,
    wrap_tool_call=middleware.wrap_tool_call,   # sync
    # awrap_tool_call=middleware.awrap_tool_call,  # async
)

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, proof artifact emitted
DENY Tool blocked, structured error returned
ERROR Fail closed — tool not executed

Access proof artifacts after execution:

for proof in middleware.proofs:
    print(f"{proof.proof_id}: {proof.tool} latency={proof.latency_ms:.0f}ms")

See the demo script for a complete working example.

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

langchain_nuggets-0.3.0.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_nuggets-0.3.0-py3-none-any.whl (35.7 kB view details)

Uploaded Python 3

File details

Details for the file langchain_nuggets-0.3.0.tar.gz.

File metadata

  • Download URL: langchain_nuggets-0.3.0.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langchain_nuggets-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f0707094f293d13200adf7bd1444770e555cea6e085d9db9631272cea67c00a3
MD5 af80cfd6fd771746dc4aa180a368822c
BLAKE2b-256 6ee8a9e9306d44b29b20764f265d74ba93b3b8d2de477b788faebf81d43bbc6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_nuggets-0.3.0.tar.gz:

Publisher: release-pypi.yml on NuggetsLtd/langchain-nuggets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_nuggets-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_nuggets-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 499272192db9352f68a8f5d6a83f970c5dbb8e1954d45e1935288b38533243a0
MD5 87862b3f5e6c9f938713b4c3d36d1bee
BLAKE2b-256 6026e00bb24bbfd9bc9cea50622518c4974efd28e688e589fd6c2d73281dee46

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_nuggets-0.3.0-py3-none-any.whl:

Publisher: release-pypi.yml on NuggetsLtd/langchain-nuggets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page