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.
Metadata
Release files for moltrust-langchain 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| moltrust_langchain-0.1.2.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| moltrust_langchain-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.6 kB
Release files / moltrust_langchain-0.1.2.tar.gz
| Download URL | moltrust_langchain-0.1.2.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd651182da2b7abbdf069e6831e2edde8efc9d1380172f24f36b37966c0705da
|
|
BLAKE2b-256 checksum How to use checksums |
5ec9a3145206169d8b5e5f39907abce010123716f81aabaa345b2dc133f25999
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / moltrust_langchain-0.1.2-py3-none-any.whl
| Download URL | moltrust_langchain-0.1.2-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90b08fc65d5b1162f72a46fb0dd14dbddea2978be287608ff9720d40f22475cf
|
|
BLAKE2b-256 checksum How to use checksums |
ab74e1f7357211fb65caa99847e2fd17094318cea6e9cdc01d2b5d34e624ef1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|