MolTrust trust verification middleware for LangChain 1.x
Project description
moltrust-langchain
Add trust verification to LangChain 1.x agents in one line.
moltrust-langchain plugs into LangChain 1.x's AgentMiddleware hook system to
check MolTrust trust scores before an agent reasons and before it calls out
to other agents/tools. Below-threshold agents are blocked (or warned/logged).
Install
pip install moltrust-langchain
Usage
from langchain.agents import create_agent
from moltrust_langchain import MolTrustMiddleware
agent = create_agent(
model="anthropic:claude-sonnet-4-6",
tools=[...],
middleware=[MolTrustMiddleware(min_score=60)],
)
This example matches the real
langchain.agents.create_agentsignature (middleware: Sequence[AgentMiddleware] = ()), verified against langchain 1.3.11.
Usage tiers
Tier 1 — no account required (default):
MolTrustMiddleware(min_score=60) # keyless; reads scores rate-limited
Tier 2 — free account (higher limits):
MolTrustMiddleware(min_score=60, api_key="mt_...") # or MOLTRUST_API_KEY env
The API key is sent as the X-API-Key header only when present.
What it does
MolTrustMiddleware is a langchain.agents.middleware.AgentMiddleware. It uses
two hook points (verified against langchain 1.3.11):
before_model(state, runtime)— checks this agent's own DID (agent_did=...) before it reasons. A blocked check raisesTrustCheckFailed(halts the agent) whenaction="block".wrap_tool_call(request, handler)— checks the target of a tool / A2A call (DID from the tool-call args underdid_key, oragent_did_mapby tool name). A blocked call returns an errorToolMessage(the agent can react) instead of raising.
min_score is on the 0–100 MolTrust trust score (trust_score from
GET /skill/trust-score/{did}) — the behavioral score, not a 0–5 rating.
Scores are recomputable: verify the on-chain solvency component of any agent
yourself at
https://api.moltrust.ch/credits/solvency/{did}
Options
MolTrustMiddleware(
min_score=60, # 0-100 trust score threshold
action="block", # "block" | "warn" | "log"
agent_did="did:moltrust:…", # this agent's DID (before_model self-check)
agent_did_map={"call_agent": "did:moltrust:…"}, # tool → target DID
did_key="did", # DID key in tool-call args / runtime context
pass_without_did=True, # allow calls with no resolvable DID
check_model=True, check_tools=True,
)
Difference from Microsoft AGT
Microsoft's Agent Governance Toolkit enforces policies — what an agent may do (scope, sandboxing, zero-trust identity). MolTrust verifies behavioral trust — is this agent trustworthy, based on verifiable history. Complementary, not competing: AGT bounds authority; MolTrust decides who has earned it.
Honest limitations (0.1.0)
- LangChain agents have no MolTrust DID by default — supply
agent_did(for the self-check) and/or adidin tool-call args oragent_did_map(for targets). - A withheld score (registered agent, too few endorsements → API returns
trust_score: null) is treated like an unregistered agent: fail-closed inblock, fail-open inwarn/log. - On a registry/transport error the middleware fails open (logs, allows) so a MolTrust hiccup never breaks your agent.
- Synchronous hooks only. For fully async agents (
ainvoke/astream), asyncabefore_model/awrap_tool_callare a follow-up.
License
MIT © CryptoKRI GmbH — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 moltrust_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: moltrust_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50da59b9aca93ab242c24d861ce82c468ba4b866024c617f2dea2f964dea0352
|
|
| MD5 |
27d87fe74bced70889269796cac7e478
|
|
| BLAKE2b-256 |
b788ae9f7bafc453470d2e1e1fa21706e2eb98954e3f2afc606e4e4e1b266b68
|