Metadata-Version: 2.5
Name: wardenloop
Version: 0.1.0
Summary: Human oversight for AI agents — guard, approve, and audit agent actions.
Project-URL: Homepage, https://wardenloopai.com
Project-URL: Documentation, https://docs.wardenloopai.com
Project-URL: Repository, https://github.com/wardenloop/wardenloop-python
Project-URL: Bug Tracker, https://github.com/wardenloop/wardenloop-python/issues
License: MIT
Keywords: agents,ai,guardrails,llm,oversight,safety
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Provides-Extra: dev
Requires-Dist: httpx>=0.24.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: responses>=0.23; extra == 'dev'
Provides-Extra: httpx
Requires-Dist: httpx>=0.24.0; extra == 'httpx'
Description-Content-Type: text/markdown

# WardenLoop Python SDK

Add human oversight to your AI agents in minutes.

```bash
pip install wardenloop
```

## Quickstart

```python
from wardenloop import Warden

warden = Warden(api_key="wl_...")

# Your agent wants to delete files
result = warden.guard(
    action="delete_files",
    payload={"path": "/user/documents/invoices/", "count": 47},
    risk="critical",
)

if result.approved:
    delete_files("/user/documents/invoices/")
else:
    print(f"Action blocked: {result.reason}")
```

When `.guard()` is called with `risk="critical"`, WardenLoop:
1. Logs the action to your dashboard
2. Sends a Slack message to your operator: *"Agent wants to delete 47 files — Approve / Deny"*
3. Waits for the human response (up to 5 minutes by default)
4. Returns the result to your agent

Low-risk actions are auto-approved instantly with no waiting.

---

## Risk levels

| Level | Behaviour |
|-------|-----------|
| `low` | Auto-approved immediately |
| `medium` | Notifies operator, waits for approval |
| `high` | Notifies operator, waits for approval |
| `critical` | Notifies operator, waits for approval |

---

## Examples

### Send email (medium risk)

```python
result = warden.guard(
    action="send_email",
    payload={"to": "ceo@acme.com", "subject": "Q4 Report"},
    risk="medium",
    message="Agent wants to send the quarterly report to the CEO.",
)

if result:   # GuardResult is truthy when approved
    send_email(...)
```

### Execute payment (critical)

```python
result = warden.guard(
    action="execute_payment",
    payload={"amount": 15000, "currency": "USD", "recipient": "vendor@example.com"},
    risk="critical",
)

if result.approved:
    process_payment(...)
elif result.status == "timeout":
    print("No operator response — payment skipped.")
else:
    print(f"Payment denied: {result.reason}")
```

### Fire-and-forget audit log

```python
# Log what your agent did without waiting for approval
action_id = warden.log(
    action="read_database",
    payload={"table": "users", "rows_read": 1200},
    risk="low",
)
```

---

## Configuration

```python
warden = Warden(
    api_key="wl_...",           # or set WARDENLOOP_API_KEY env var
    timeout=600,                # seconds to wait for approval (default: 300)
    poll_interval=5,            # seconds between status checks (default: 3)
    raise_on_denied=True,       # raise ActionDeniedError instead of returning False
    raise_on_timeout=True,      # raise ActionTimeoutError instead of returning False
    fail_closed=True,           # block actions if backend is unreachable (default)
)
```

### Environment variable

```bash
export WARDENLOOP_API_KEY=wl_your_key_here
```

```python
warden = Warden()  # picks up key automatically
```

---

## Error handling

```python
from wardenloop import (
    ActionDeniedError,
    ActionTimeoutError,
    BackendUnavailableError,
    LimitExceededError,
    AuthenticationError,
)

warden = Warden(api_key="wl_...", raise_on_denied=True, raise_on_timeout=True)

try:
    result = warden.guard("delete_all_records", risk="critical")
except ActionDeniedError as e:
    print(f"Denied: {e.reason}")
except ActionTimeoutError as e:
    print(f"No response after {e.timeout}s")
except BackendUnavailableError:
    print("WardenLoop is unreachable — action blocked")
except LimitExceededError as e:
    print(f"Action budget exceeded: {e.used}/{e.limit}")
except AuthenticationError:
    print("Invalid API key")
```

---

## Fail-closed by default

If the WardenLoop backend is unreachable, `guard()` raises `BackendUnavailableError`
and the action is **blocked** — this is the safe default.

To allow actions when the backend is down (fail-open):

```python
warden = Warden(api_key="wl_...", fail_closed=False)
```

---

## Dependencies

The SDK has **zero required dependencies** and works with Python's built-in `urllib`.

Install `httpx` for better performance and connection pooling:

```bash
pip install wardenloop[httpx]
```

---

## Get your API key

Sign up at [app.wardenloopai.com](https://app.wardenloopai.com)

---

## License

MIT
