Python SDK for TrustLoop — governance and audit trail for AI agents
Project description
trustloop
Python SDK for TrustLoop — governance, audit trail, and kill-switch for AI agents.
Intercept every tool call your agent makes. Log it. Block dangerous actions. Require human approval. Works with LangChain, CrewAI, AutoGen, or any custom Python agent.
Install
pip install trustloop
With async support:
pip install trustloop[async]
With LangChain integration:
pip install trustloop[langchain]
With CrewAI integration:
pip install trustloop[crewai]
Everything:
pip install trustloop[all]
Quick start
Get your free API key at trustloop.live/signup.
from trustloop import TrustLoop
tl = TrustLoop(api_key="tl_your_key_here", agent_name="my-agent")
# Check before running any tool
result = tl.intercept("send_email", {"to": "ceo@bank.com", "body": "..."})
if not result["allowed"]:
raise RuntimeError(result["message"])
# ... run the tool
Or set your key as an env var and let the SDK find it:
export TRUSTLOOP_API_KEY="tl_your_key_here"
export TRUSTLOOP_AGENT_NAME="my-agent"
tl = TrustLoop() # reads from env
Usage
Manual intercept
result = tl.intercept("delete_database", {"table": "users"})
# result = {
# "allowed": False,
# "status": "BLOCKED",
# "message": "Matched rule: block destructive database operations"
# }
Auto-raise on block
from trustloop import TrustLoop, TrustLoopBlockedError, TrustLoopPendingError
try:
tl.intercept("transfer_funds", {"amount": 50000}, raise_if_blocked=True)
except TrustLoopBlockedError as e:
print(f"Blocked: {e}")
except TrustLoopPendingError as e:
print(f"Waiting for approval: {e.approval_id}")
@tl.guard() decorator
@tl.guard("send_email")
def send_email(to: str, subject: str, body: str):
# Only runs if TrustLoop allows it
...
@tl.guard() # uses function name as tool name
def delete_user(user_id: str):
...
Async
from trustloop import AsyncTrustLoop
async with AsyncTrustLoop(api_key="tl_...") as tl:
await tl.intercept("post_tweet", {"text": "Hello world"}, raise_if_blocked=True)
@tl.guard("send_email")
async def send_email(to, subject, body):
...
LangChain
from trustloop import TrustLoop
from trustloop.integrations.langchain import wrap_tools
tl = TrustLoop(api_key="tl_...", agent_name="langchain-agent")
# Wrap all tools — one line, zero boilerplate
tools = wrap_tools([search_tool, email_tool, db_tool], tl)
agent = create_openai_tools_agent(llm, tools, prompt)
CrewAI
from trustloop import TrustLoop
from trustloop.integrations.crewai import governed_tool
tl = TrustLoop(api_key="tl_...", agent_name="crew-agent")
@governed_tool(tl)
class SendEmailTool(BaseTool):
name = "send_email"
description = "Send an email"
def _run(self, to: str, subject: str, body: str) -> str:
... # only runs if TrustLoop allows it
Governance rules
# Create a rule in plain English
tl.create_rule(
"Any wire transfer over £10,000 requires human approval",
action="approve",
approver_email="cfo@mycompany.com",
)
# Block a tool instantly (kill-switch)
tl.block_tool("drop_table", reason="Emergency: DB ops disabled")
# Unblock
tl.unblock_tool("drop_table")
Audit log
# Get recent calls
logs = tl.get_logs(limit=100, status="BLOCKED")
# Export as CSV
csv = tl.export_logs()
# Stats
stats = tl.get_stats()
print(stats["total"], stats["blocked"])
Human approvals
# List pending
pending = tl.get_pending_approvals()
# Approve or deny programmatically
tl.decide(pending[0]["id"], "approved")
Context manager
with TrustLoop(api_key="tl_...") as tl:
tl.intercept("my_tool", {...})
# connection closed automatically
MCP (Claude Desktop)
url = TrustLoop.mcp_url("tl_your_key")
# → "https://trustloop-production.up.railway.app/sse?api_key=tl_..."
Paste this into your claude_desktop_config.json:
{
"mcpServers": {
"trustloop": { "url": "<paste url here>" }
}
}
Environment variables
| Variable | Description |
|---|---|
TRUSTLOOP_API_KEY |
Your API key (avoids passing it in code) |
TRUSTLOOP_AGENT_NAME |
Default agent name for all intercepts |
TRUSTLOOP_BASE_URL |
Override API base URL (for on-prem deployments) |
Links
License
MIT
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 trustloop_sdk-1.0.0.tar.gz.
File metadata
- Download URL: trustloop_sdk-1.0.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
735ff07839e505ed7c318f9e809fc6426c7e8f4b4ce481193d0a946ba2f1f130
|
|
| MD5 |
9634f8e53eda5e1501fed863b0fc22eb
|
|
| BLAKE2b-256 |
7da843cba48406e6d52b3313ded7c65afa66389e305971cb27876f2f465a0599
|
File details
Details for the file trustloop_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: trustloop_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
446715c74d5f330379d98c790066d8f2259b933364eebe3afe263a2d60e5920c
|
|
| MD5 |
67974a02b712a65c561f583697b09596
|
|
| BLAKE2b-256 |
1fc24e22fe846a3aa44751c9a7cea62366b8de43de61c498444cc87cfa1abef3
|