guaardvark-guardian
Three-tier Claude supervision architecture for autonomous AI systems.
When your AI agents can modify code, execute tools, and make autonomous decisions — who watches the watcher? guaardvark-guardian provides structured Claude API supervision with escalation, code review, and emergency kill switches.
Extracted from the Guaardvark self-hosted AI workstation, where it supervises autonomous agents operating on air-gapped hardware.
Install
pip install guaardvark-guardian
Quick Start
from guaardvark_guardian import Guardian, Directive
guardian = Guardian(api_key="sk-ant-...")
# Tier 1: Escalate a hard problem to Claude
result = guardian.escalate("Why is this query plan doing a sequential scan?")
if result.available:
print(result.response)
# Tier 2: Review an autonomous code change
review = guardian.review_change(
file_path="app/models.py",
current_content=open("app/models.py").read(),
proposed_diff=my_agent.last_diff,
reasoning="Fix N+1 query in user listing endpoint",
)
if review.approved:
apply_patch()
elif review.directive.is_emergency:
emergency_stop()
else:
log_rejection(review.reason, review.suggestions)
# Tier 3: Get system health advice
advice = guardian.advise({
"gpu_vram_percent": 0.92,
"disk_free_gb": 8,
"active_models": ["llama3", "sd-1.5"],
})
for rec in advice.recommendations:
print(f"[{rec['priority']}] {rec['title']}: {rec['action']}")
The Three Tiers
Tier 1 — Escalation
Route hard problems to Claude when local models are insufficient.
result = guardian.escalate(
message="Explain this stack trace",
conversation_history=[
{"role": "user", "content": "previous question"},
{"role": "assistant", "content": "previous answer"},
],
system_context="Running PostgreSQL 16 on Ubuntu 24.04",
)
- Maintains conversation context (last 10 messages)
- Budget-controlled with automatic monthly reset
- Returns
EscalationResultwith response text and token usage
Tier 2 — Code Guardian
Every autonomous code change is reviewed before application.
review = guardian.review_change(
file_path="core/auth.py",
current_content="def verify_token(t): ...",
proposed_diff="-def verify_token(t): ...\n+def verify_token(t, skip=True): ...",
reasoning="Add bypass parameter for testing",
)
print(review.approved) # False
print(review.directive) # Directive.REJECT
print(review.risk_level) # RiskLevel.HIGH
print(review.reason) # "Adding auth bypass parameter is a security risk"
print(review.suggestions) # ["Use a test fixture instead of a bypass flag"]
Six directive levels:
| Directive | Meaning | Emergency? |
|---|---|---|
proceed |
Safe to apply | No |
proceed_with_caution |
Likely safe, monitor closely | No |
reject |
Do not apply this change | No |
halt_self_improvement |
Stop all autonomous code modification | Yes |
lock_codebase |
Prevent any file writes until manually unlocked | Yes |
halt_family |
Broadcast emergency stop to all connected nodes | Yes |
Tier 3 — System Advisor
Analyze system state and get improvement recommendations.
advice = guardian.advise({
"gpu_vram_percent": 0.95,
"cpu_percent": 0.40,
"disk_free_gb": 12,
"active_models": ["llama3:8b", "nomic-embed-text"],
"pending_tasks": 3,
"uptime_hours": 72,
})
# advice.overall_health: "warning"
# advice.recommendations: [{category, priority, title, description, action}]
Offline-Safe by Design
All tiers fail gracefully. If the Claude API is unavailable or the token budget is exceeded, operations continue with safe defaults — never blocking.
guardian = Guardian() # No API key
review = guardian.review_change("f.py", "x", "+y", "test")
assert review.approved is True
assert review.directive == Directive.PROCEED_WITH_CAUTION
assert review.offline_fallback is True
This makes guaardvark-guardian suitable for air-gapped environments where the supervision channel may be intermittent.
Callbacks
Kill Switch Integration
React to emergency directives in real-time:
def handle_directive(directive, review):
if directive == Directive.HALT_SELF_IMPROVEMENT:
disable_autonomous_agents()
elif directive == Directive.LOCK_CODEBASE:
set_filesystem_readonly()
elif directive == Directive.HALT_FAMILY:
broadcast_halt_to_fleet() # Your mesh network logic
guardian = Guardian(
api_key="sk-ant-...",
on_directive=handle_directive,
)
Usage Persistence
Track and persist token usage across restarts:
def save_usage(usage_data):
db.set("guardian_usage", json.dumps(usage_data))
guardian = Guardian(
api_key="sk-ant-...",
monthly_budget=500_000,
on_usage=save_usage,
)
Configuration
guardian = Guardian(
api_key="sk-ant-...", # Anthropic API key
model="claude-sonnet-4-20250514", # Claude model ID
max_output_tokens=4096, # Max response length
monthly_budget=1_000_000, # Token budget per month
system_prompt="Custom prompt...", # Override default system prompt
on_directive=my_callback, # Emergency directive handler
on_usage=my_usage_tracker, # Token usage persistence
)
Token Budget
Usage is tracked automatically with monthly reset:
print(guardian.usage)
# {
# "input_tokens": 12500,
# "output_tokens": 3200,
# "total_tokens": 15700,
# "monthly_budget": 1000000,
# "budget_remaining": 984300,
# "budget_used_percent": 1.6,
# }
Requirements
- Python 3.10+
anthropicSDK (installed automatically)- An Anthropic API key (optional — works offline without one)
License
MIT — use freely in any project.
Origin
Built by Albenze AI Solutions as part of the Guaardvark self-hosted AI workstation. Extracted as a standalone library so any project can benefit from structured Claude supervision.
In Guaardvark, this architecture supervises autonomous agents that can modify source code, manage GPU resources, and broadcast fixes across a fleet of air-gapped machines via the Interconnector mesh protocol. The guardian ensures every autonomous action is reviewed, auditable, and reversible.
Metadata
Release files for guaardvark-guardian 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| guaardvark_guardian-0.1.0.tar.gz | 14.3 kB | Without provenance | Details for guaardvark_guardian-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| guaardvark_guardian-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for guaardvark_guardian-0.1.0-py3-none-any.whl |
Total release size: 25.9 kB
Release files / guaardvark_guardian-0.1.0.tar.gz
| Download URL | guaardvark_guardian-0.1.0.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a847810527b37c018ed19a4c11c5b7f8e6e3278b2e9317f3c6525393f5c1c1e9
|
|
BLAKE2b-256 checksum How to use checksums |
d9b842831e3a99056d8f4baef9ec052cd235590aa77e28dec6d755c6492eb84a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / guaardvark_guardian-0.1.0-py3-none-any.whl
| Download URL | guaardvark_guardian-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
561d0b1e511a4514b3ee225905337d3fb2e48409aaf32aa7c103eed75ea362b6
|
|
BLAKE2b-256 checksum How to use checksums |
52881c769fa04666c4be0266abfb949ddd38cf2cb0620c3b8b33f2f6812a1383
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for guaardvark-guardian 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.