Metadata-Version: 2.4
Name: praesidias
Version: 0.1.0
Summary: Check every agent action with Praesidias before it runs.
Author: Praesidias
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/sowainat/praesidias-kit
Project-URL: Repository, https://github.com/sowainat/praesidias-kit
Project-URL: Issues, https://github.com/sowainat/praesidias-kit/issues
Project-URL: Changelog, https://github.com/sowainat/praesidias-kit/blob/main/CHANGELOG.md
Keywords: praesidias,ai-agents,governance,authorization,guardrails
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
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: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: verify
Requires-Dist: cryptography>=42; extra == "verify"
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.2; extra == "openai-agents"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.40; extra == "anthropic"
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == "langchain"
Provides-Extra: crewai
Requires-Dist: crewai>=0.80; extra == "crewai"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: cryptography>=42; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Dynamic: license-file

# praesidias (Python)

Check every agent action with Praesidias before it runs. Not published yet. No dependencies; Python 3.9 or newer.

```python
from praesidias import Praesidias

# The key comes from PRAESIDIAS_API_KEY and the address from PRAESIDIAS_URL. Never put a key in code.
praesidias = Praesidias(system="payments")

result = praesidias.guard(
    "TRANSFER_10K_TO_250K",
    {"type": "payment", "id": "pay_123"},
    lambda ctx: bank.transfer("pay_123", authorization=ctx.proof),
)

if result.status == "executed":
    print(result.value)
elif result.status == "blocked":
    print(result.reason.message)
else:  # "needs_approval"
    print(f"Waiting for approval: {result.console_url}")
```

## What `guard` does

1. **Asks** Praesidias whether this agent may do this action on this resource.
2. **Allowed:** gets Praesidias's signed authorization, and only then calls your function. The authorization is `ctx.proof`. Your function may take the context, or no argument.
3. **Blocked:** your function is not called. `result.reason` has the code and a plain sentence.
4. **Needs approval:** by default it waits (up to 15 minutes), then runs. With `on_approval="return"` it returns at once, and `result.resume()` waits again later.
5. **Reports** what happened: succeeded, or failed with the exception's class name. Never its message.

## If anything is unclear, your function is not called

| Situation                                      | What happens                                                       |
| ---------------------------------------------- | ------------------------------------------------------------------ |
| Praesidias unreachable, slow, or answering 5xx | raises `PraesidiasUnavailableError`                                |
| The key is refused                             | raises `PraesidiasAuthError`; not retried                          |
| The authorization cannot be obtained           | raises; your function has not run                                  |
| Your function raises                           | the failure is reported, and your exception is raised on unchanged |
| Your function ran but reporting failed         | `status == "executed"` with `outcome_recorded` false               |

Policy answers are results, not exceptions. No exception, log line or `repr` ever contains the key. Retries happen only on network failures and 429/502/503/504, with the same idempotency key.

## Options

```python
Praesidias(
    system="payments",        # or PRAESIDIAS_SYSTEM
    console_url="https://…",  # or PRAESIDIAS_CONSOLE_URL
    on_approval="wait",       # or "return"
    approval_timeout=900,     # seconds
    timeout=10,               # seconds, per request
    retries=2,
    logger=print,             # method, path, status, correlation id; never the key or a body
    workload_token_file="/var/run/secrets/praesidias/token",  # or PRAESIDIAS_WORKLOAD_TOKEN_FILE
)

praesidias.guard(action, resource, fn,
    context={"amount": 12000},   # recorded with the decision; no secrets
    idempotency_key="order-77",  # makes repeating this exact call safe
    correlation_id=request_id,
)
```

**Workload binding.** When an Admin binds this agent to its workload in the Console, its key works only together with the identity token its platform gives the workload (for Kubernetes, a projected service account token with the audience set for Praesidias). Point `workload_token_file` (or `PRAESIDIAS_WORKLOAD_TOKEN_FILE`) at the file the platform keeps it in: it is read on every request, so a rotated token is used. `workload_token` takes the token itself, or a function returning a fresh one. The token is sent as `x-praesidias-workload-token` and never logged. A token that cannot be read stops the request (`WORKLOAD_TOKEN_UNREADABLE`); a refused one is a `PraesidiasAuthError` with a `WORKLOAD_*` code.

`decide(action, resource)` and `commit(decision)` are there if you want the steps yourself.

It is synchronous and safe to share between threads. There is no async client yet: in async code, call `guard` with `asyncio.to_thread`.

Audit mode, the limits and what must be enabled are the same as for the Node SDK; see `packages/sdk-node/README.md`.

## Tests

```sh
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/pytest                      # unit tests, against a scripted stand-in
PRAESIDIAS_E2E_CORE_ENV=/path/to/praesidias/.env .venv/bin/pytest -m e2e   # against a core on this machine
```
