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.2.0.tar.gz (29.4 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.2.0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_nuggets-0.2.0.tar.gz
  • Upload date:
  • Size: 29.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 3ea1866790f2c9b88c0cdc0b44192e80a6ef1ca92bf9a23a88804152c716dffa
MD5 4a306a74b20bbc1854ae5b01c835a4a8
BLAKE2b-256 f6d303cf70a7c28d34d1a983ed2d39b83bff8c448765a70c0a877ec0178fbff8

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_nuggets-0.2.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.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_nuggets-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4172928c904db329332862e7a40f363f296ea9a47aefd070d33770ea6e167050
MD5 8584e9996e63dbf4f122dc363a169659
BLAKE2b-256 d8d732abf0069d37d84c324e32e8a705ab7e9f0ef58ddcb911274a6a9c8749be

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_nuggets-0.2.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