The accountability layer for AI agents. Trace, explain, and control agent actions.
Project description
AgentTrace ๐ก๏ธ
Block dangerous AI agent actions. Explain every decision. One line of code.
Your AI agent's conscience โ blocks harm, explains reasoning, logs everything.
The Problem
AI agents are making autonomous decisions. Nobody knows why.
When they go wrong, nobody can explain what happened.
- ๐ด 51% of enterprises have AI agents in production (Ringly.io, 2026)
- ๐ด 75% have experienced negative consequences from GenAI (McKinsey, 2025)
- ๐ด 42% abandoned AI projects due to reliability issues (S&P Global, 2025)
- ๐ด "AI Accountability" is now the #1 enterprise requirement for new AI tools (GlobeNewsWire/Jitterbit, May 2026)
The EU AI Act mandates explainability by December 2027. Boards want decision logs. Your customers want to trust your AI.
Nobody else provides this combination: open-source + real-time blocking + plain-English explanations + full trace.
What You Get
| Feature | AgentTrace | Langfuse | Portkey | Lakera |
|---|---|---|---|---|
| Blocks dangerous actions | โ | โ | โ ๏ธ Partial | โ (LLM only) |
| Explains WHY in plain English | โ | โ | โ | โ |
| Native AI agent support | โ | โ | โ ๏ธ Partial | โ |
| Open-source & self-hosted | โ | โ | โ | โ |
| Full audit trail | โ | โ | โ ๏ธ | โ |
Quick Start
TypeScript / Node.js
npm install agenttrace
import { AgentTrace } from 'agenttrace';
const guard = new AgentTrace({
rules: [
'block_pii_leakage', // Stop PII leaking to users
'block_financial_advice', // No unqualified investment advice
'block_harmful_content', // Violence, illegal activities, self-harm
'require_human_approval', // Gate high-value transactions
],
explain: true, // Generate plain-English explanations
humanApproval: {
threshold: 1000, // Require approval for actions > $1,000
onApprovalRequired: async ({ description, amount }) => {
// Send Slack alert, email, UI prompt โ whatever you need
return await myApprovalSystem.request(description, amount);
},
},
});
// Wrap your agent โ same interface, now accountable
const safeAgent = guard.wrap(myAgent);
const result = await safeAgent.run("Process this customer refund");
// If BLOCKED:
// result.blocked โ true
// result.reason โ "Agent action BLOCKED. Violated rule(s): require_human_approval..."
// result.violations โ [{ rule, description, severity, evidence }]
// If ALLOWED:
// result.blocked โ false
// result.explanation โ "Agent processed a $50 refund because the customer's..."
// result.riskLevel โ 'LOW'
// result.auditTrail โ [step1, step2, ...] โ full reasoning chain
// result.auditId โ 'uuid-...' โ look it up later
Python
pip install agenttrace
from agenttrace import AgentTrace, AgentTraceOptions
guard = AgentTrace(AgentTraceOptions(
rules=["block_pii_leakage", "block_harmful_content", "block_financial_advice"],
debug=True,
))
safe_agent = guard.wrap(my_langchain_agent)
result = safe_agent.invoke("Process customer request")
print(result.blocked) # True/False
print(result.risk_level) # 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
print(result.audit_id) # UUID for audit trail lookup
Built-in Rules
AgentTrace ships with 13 built-in rules designed to enforce enterprise-grade accountability.
| Rule | Category | What it blocks | Severity |
|---|---|---|---|
block_pii_leakage |
Privacy | Emails, phones, SSNs, credit card numbers, Aadhaar, API Keys. | HIGHโCRITICAL |
block_special_category_data |
Privacy | GDPR Art 9 data: health, genetics, sexual orientation, political views. | HIGHโCRITICAL |
block_manipulation |
EU AI Act | Art 5 prohibited practices: artificial urgency, dark patterns, gaslighting. | HIGHโCRITICAL |
block_discriminatory_output |
Fairness | EU Charter Art 21: Bias on race, gender, age, religion, nationality, disability. | CRITICAL |
block_ai_identity_deception |
Transparency | EU AI Act Art 50: Agents claiming to be human or denying being AI. | CRITICAL |
block_medical_advice |
Professional | Unqualified diagnosis, treatment recommendations, dosage instructions. | CRITICAL |
block_legal_advice |
Professional | Unauthorized Practice of Law (UPL): specific legal strategy advice. | HIGH |
block_financial_advice |
Professional | Investment recommendations, guaranteed returns, loan guidance. | HIGH |
block_prompt_injection |
Security | OWASP LLM01: Detects instruction overrides, persona hijacking, data exfil. | CRITICAL |
block_system_prompt_leakage |
Security | OWASP LLM07: Agent exposing its internal configuration or instructions. | HIGH |
block_harmful_content |
Safety | Violence, illegal instructions, self-harm, hate speech. | HIGHโCRITICAL |
require_human_approval |
Oversight | Actions above a $ threshold, irreversible/destructive operations. | HIGHโCRITICAL |
block_hallucination |
Quality | Factual claims not supported by your RAG context documents. | HIGH |
All rules run in parallel โ zero extra latency on the happy path. You can easily group these by using pre-configured bundles like COMPLIANCE_BUNDLES.EU_AI_ACT or COMPLIANCE_BUNDLES.OWASP_LLM.
Custom Rules
Write your own rules in 5 lines:
import { createRule, AgentTrace } from 'agenttrace';
const noCompetitorMentions = createRule(
'no_competitor_mentions',
async ({ result }) => {
const text = JSON.stringify(result);
if (text.toLowerCase().includes('rival-corp')) {
return [{ rule: 'no_competitor_mentions', description: 'Competitor mentioned', severity: 'MEDIUM' }];
}
return [];
}
);
const guard = new AgentTrace({ rules: [noCompetitorMentions, 'block_pii_leakage'] });
Audit Trail
Every agent run is automatically stored in a local SQLite database:
// Query your audit trail
const recent = guard.storage?.getRecent(20);
const blocked = guard.storage?.getBlocked();
const stats = guard.storage?.stats();
// โ { total: 142, blocked: 3, byRiskLevel: { LOW: 138, HIGH: 3, CRITICAL: 1 } }
// Look up a specific run
const run = guard.storage?.getById('audit-uuid-here');
Works With
- โ OpenAI โ Assistants, Responses API, Chat Completions
- โ
LangChain / LangGraph โ any
.invoke()or.run()agent - โ CrewAI โ crew.kickoff()
- โ Anthropic โ tool use agents
- โ
Any async function โ use
guard.guardFn()
// Works with any async function โ no agent object needed
const result = await guard.guardFn(
async () => await myCustomAgent.process(input),
input // original task for tracing
);
Explanation Engine
Set explain: true and add ANTHROPIC_API_KEY to get plain-English explanations:
Agent processed a $50 refund for customer #12345 because:
(1) The purchase was within the 30-day return window,
(2) The amount was below the $100 automatic-approval threshold,
(3) The customer's account is in good standing.
Risk: LOW. Confidence: HIGH.
No API key? Explanations gracefully fall back to a shorter canned message. AgentTrace never crashes because of a missing API key.
Architecture
Your Agent
โ
โผ (Proxy intercept)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AgentTrace โ
โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Tracer โ โ Rule Engine โ โ
โ โ โ โ (runs in parallel) โ โ
โ โ Step 1 โ โ โข block_pii โ โ
โ โ Step 2 โ โ โข block_financial โ โ
โ โ Step 3 โ โ โข block_harmful โ โ
โ โโโโโโโโโโโ โ โข human_approval โ โ
โ โ โข hallucination โ โ
โ โ โข custom rules... โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โ
โ โ Explainer โ โ Store โ โ
โ โ (Anthropic โ โ (SQLite WAL) โ โ
โ โ claude-3) โ โ โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
GuardedResult {
blocked, reason, explanation,
riskLevel, auditId, auditTrail,
violations, result
}
Self-Hosted (Free Forever)
AgentTrace stores everything locally in SQLite. Zero cloud dependency. Zero data leaves your machine.
.agenttrace/
โโโ traces.db โ all your audit trails, WAL mode, fast
Cloud Dashboard (Coming Soon)
- Real-time monitoring dashboard
- Team access and alerts
- Compliance reports (EU AI Act, SOC2)
- 1-year retention with search
FAQ
Q: Does this add latency?
A: Rules run in parallel. For the happy path (no violations), the overhead is typically <5ms. Explanation generation (optional) adds ~500-800ms via Anthropic's API.
Q: What if my agent isn't an object with a .run() method?
A: Use guard.guardFn(async () => myFn(input), input).
Q: Can I use this without an Anthropic API key?
A: Yes. All rules work without any API key. The explain: true feature requires ANTHROPIC_API_KEY but falls back gracefully.
Q: Is the audit trail tamper-proof?
A: Currently it's an append-only SQLite WAL database. True cryptographic signing (hash-chain) is on the roadmap.
Contributing
PRs welcome! See CONTRIBUTING.md for guidelines.
Key areas for contribution:
- New built-in rules (domain-specific)
- Agent framework integrations (AutoGen, Semantic Kernel, etc.)
- Better hallucination detection (semantic similarity, vector search)
- Cloud dashboard
- Hash-chain audit trail (tamper-proof)
License
MIT ยฉ 2026 AgentTrace Contributors
Why "Accountability" and not "Guardrails"?
"Intelligence may be scalable, but accountability is not." โ Accenture/Wharton, 2026
Guardrails are a feature. Accountability is a principle. Guardrails prevent bad outputs. Accountability explains every output โ blocked or allowed โ and creates a chain of evidence that stands up to audit.
We believe every AI agent action should be traceable, explainable, and controllable. Not just the bad ones.
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 ai_agenttrace-1.0.0.tar.gz.
File metadata
- Download URL: ai_agenttrace-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.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51932f8e1a8b800cb03dabc25cbd0ceb1e1e1d4930e812d90ab864557008276c
|
|
| MD5 |
bd4b9f848d5f21cdd1987c2c99d23dbb
|
|
| BLAKE2b-256 |
418fdb63fc0cb82684c46aeea8fb3ba4c7cb65dfe67844c84101bd8224aaf024
|
File details
Details for the file ai_agenttrace-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ai_agenttrace-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
facbbcf7c50fb3e6ca2df29ed839c8b7240a28212b7e75058b8b9f4b541f49c1
|
|
| MD5 |
bb84a6dad7b2d98effb4675442cda7dd
|
|
| BLAKE2b-256 |
3d850fcd3bd0cb76d1b18b1b0f1c3616cec9d5bdb0070041c0e14c17e67bca70
|