Metadata-Version: 2.4
Name: aisley
Version: 0.1.0
Summary: Sign tamper-evident receipts for AI agent actions. Byte-identical canonicalization with the Aisley server, CLI, and verifier.
Author: Aisley
License-Expression: MIT
Keywords: aisley,ai,agent,audit,receipt,ed25519,verification,provenance,evidence
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
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 :: Cryptography
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Dynamic: license-file

# aisley

Sign tamper-evident **receipts** for AI agent actions. Each receipt records a
specific model call, tool call, policy decision, and approval state as signed,
hash-only evidence (no raw prompts, model outputs, or tool arguments are stored).
Anyone can later verify a receipt — schema, canonical hash, Ed25519 signature, key
trust, and timestamp — with **no Aisley account**.

The SDK's canonicalization is **byte-identical** to the Aisley server, CLI,
verifier, and the TypeScript `aisley` package, so a receipt re-derives the same
hash anywhere, in any language.

> Aisley records the policy decision **your** system made as evidence. It does not
> run a policy engine and does not decide whether an action is allowed or block
> execution — your application makes and enforces those decisions.

## Install

```bash
pip install aisley
```

Requires Python ≥ 3.10. Pure standard library — no third-party dependencies. Typed
(`py.typed`).

## Quick start

```python
import os

from aisley import AisleySdk, create_http_receipt_creator

aisley = AisleySdk(
    agent={"name": "RefundAgent", "version": "v1.0.0"},
    model={"provider": "OpenAI", "name": "gpt-4.1", "version": "2026-06-01"},
    receipt_creator=create_http_receipt_creator(
        endpoint="https://app.aisley.example/api/receipts",
        organization_id="org_123",
        api_key=os.environ["AISLEY_RECEIPT_API_KEY"],
    ),
)

# 1. Wrap the model call — captures hash-only evidence of the prompt/input/output.
model_call = aisley.call_model(
    prompt={"system_prompt": system_prompt, "template_version": "refund-agent-v3"},
    input=customer_request,
    call=lambda input: call_model_provider(input),
)

# 2. Wrap the tool call — builds, signs, submits, and returns the receipt.
tool_call = aisley.call_tool(
    model_call=model_call,
    tool={"name": "stripe.refunds.create", "version": "2026-05-18"},
    action_name="refund.create",
    args=refund_args,
    risk_level="high",
    call=lambda args: stripe_refunds_create(**args),
)

print(tool_call.receipt["receipt_id"])  # the signed receipt id
print(tool_call.output)                 # your tool's real return value
```

Open the receipt in the dashboard, or paste it into the `/verify` page to confirm
it independently.

## Fail-open by default

Receipt submission is decoupled from your action. If recording a receipt fails
(outage, 5xx, timeout), the SDK still runs your real business action and returns a
result with `receipt=None` and `receipt_error` set — the audit logger can never
take down your production path. Pass `on_receipt_error="fail-closed"` to gate
execution on a durable receipt instead.

## Key exports

| Export | Purpose |
| --- | --- |
| `AisleySdk` / `create_aisley_sdk` | Wrap model and tool calls; build, sign, and submit receipts. |
| `create_http_receipt_creator` | Submit receipts to an Aisley server over HTTP (deterministic idempotency key, timeout). |
| `build_receipt_input` | Build a receipt input without executing a call. |
| `create_evidence_hash` | The canonical, cross-language evidence hash. |
| `canonicalize_json` | The canonical JSON form used for hashing and signing. |
| `AisleyReceiptApiError` / `AisleyReceiptTimeoutError` / `AisleyReceiptTransportError` | Typed errors. |

## License

MIT — see [LICENSE](LICENSE).
