Python SDK for TrustProtocol — AI agent governance and audit trail
Project description
TrustProtocol Python SDK
Governance and cryptographic audit trail for AI agents.
Installation
pip install trustprotocol
Quick Start
from trustprotocol import TrustProtocol
tp = TrustProtocol("your-api-key")
result = tp.intercept(
agent_id="finance-agent-01",
action="Transfer 5000 EUR to supplier ACME",
cost_eur=5000.0,
user_id="marie@yourcompany.com"
)
if result.authorized:
print(f"✓ Authorized — Risk score: {result.risk_score}/100")
# Execute the action
else:
print(f"✗ Blocked — {result.block_reason}")
Raise on block
from trustprotocol import TrustProtocol, TrustProtocolError
tp = TrustProtocol("your-api-key")
try:
result = tp.intercept(
agent_id="finance-agent-01",
action="Transfer 150000 EUR to new beneficiary",
cost_eur=150000.0,
user_id="marie@yourcompany.com",
raise_on_block=True
)
# Execute action
except TrustProtocolError as e:
print(f"Blocked: {e.block_reason}")
print(f"Risk score: {e.risk_score}/100")
print(f"Reasons: {e.reasons}")
With LangChain
from trustprotocol import TrustProtocol
from langchain.tools import tool
tp = TrustProtocol("your-api-key")
@tool
def governed_payment(amount: float, recipient: str, user_id: str) -> str:
"""Execute a payment with TrustProtocol governance."""
result = tp.intercept(
agent_id="payment-agent",
action=f"Transfer {amount} EUR to {recipient}",
cost_eur=amount,
user_id=user_id,
raise_on_block=True
)
return f"Payment authorized. Attestation: {result.attestation_id}"
With the OpenAI Agents SDK
Requires the optional openai-agents extra: pip install "trustprotocol[openai-agents]"
from agents import Agent
from trustprotocol import TrustProtocol
from trustprotocol.openai_agents import protect_tools
tp = TrustProtocol("your-api-key")
agent = Agent(
name="finance-agent",
tools=protect_tools([transfer_funds, send_email], tp, user_id="marie@yourcompany.com"),
)
Every call to a protected tool is intercepted via /intercept before it runs.
If TrustProtocol blocks the action, the tool call is rejected and the model
is told why instead of the run crashing.
Audit & Verification
# Get audit ledger
ledger = tp.ledger(agent_id="finance-agent-01")
print(f"Total actions: {ledger['total']}")
# Verify chain integrity
verification = tp.verify_chain()
print(f"Chain valid: {verification['chain_valid']}")
# Pending approvals
approvals = tp.approvals()
print(f"Pending: {len(approvals.get('pending', []))}")
Links
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 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 trustprotocol-1.0.1.tar.gz.
File metadata
- Download URL: trustprotocol-1.0.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c027222630e9b412377dd1b2bc5240858b5514f47e0d3c376d666997f49091a5
|
|
| MD5 |
eb41eb298c45d9257a19370930ab720d
|
|
| BLAKE2b-256 |
4ef87601173faa10fafa06fe940189f44cff508a92c5f06328c94f43b50d704d
|
File details
Details for the file trustprotocol-1.0.1-py3-none-any.whl.
File metadata
- Download URL: trustprotocol-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.5 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 |
694877213b27669b2810a7b2204ac83ebe942bbdbe2cf2da127cc8a175e32762
|
|
| MD5 |
f79b364714968c360353842741dfa6f8
|
|
| BLAKE2b-256 |
a8e024c1641cd71653404c6e86a1d3de89102aa3e8acc12f96f83719439841db
|