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"
# }
Agent reason field
Pass a plain English explanation of why the agent is taking an action. The reason is stored in the audit log and shown in the approval email so the human approver sees intent, not just raw arguments. PII is masked before storage.
result = tl.intercept(
"transfer_funds",
{"to_account": "GB29NWBK60161331926819", "amount": 5000},
reason="User requested urgent payment to cover supplier invoice INV-0042 due today",
)
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
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