Python SDK for Agent Health Monitor — trust-routed agent payment decisions
Project description
ahm-shield
Python SDK for Agent Health Monitor — trust-routed agent payment decisions.
Sits in front of agent payment flows and automates trust-routed decisions using AHM's scoring API.
Install
pip install ahm-shield
# with FastAPI middleware support
pip install ahm-shield[fastapi]
Quick start
Pattern A — Explicit check
from ahm_shield import AHMShield
shield = AHMShield(api_key="ahm_live_...")
result = shield.route("0xABC...")
result.action # "instant_settle" | "escrow" | "reject"
result.grade # "A"–"F"
result.score # 0–100
result.confidence # 0.0–1.0
result.stale # bool
Pattern B — Guard decorator
@shield.guard(on_reject="raise", on_escrow="flag")
def process_payment(address: str, amount: float):
...
on_reject="raise"— raisesAHMRejectError(default)on_reject="return"— returnsNonewithout calling the functionon_escrow="flag"— proceeds, setsahm_decisioncontext var (default)on_escrow="raise"— raisesAHMEscrowFlagon_escrow="allow"— proceeds silently
Async functions are auto-detected and handled correctly.
Pattern C — FastAPI middleware
from ahm_shield.middleware import AHMShieldMiddleware
app.add_middleware(
AHMShieldMiddleware,
api_key="ahm_live_...",
address_extractor=lambda r: r.headers.get("x-agent-address"),
)
Rejected addresses receive a 403. Escrow-flagged requests pass through with x-ahm-action: escrow response headers. The RoutingDecision is available at request.state.ahm_decision.
Async support
Every method has a sync and async variant:
result = shield.route("0xABC...") # sync
result = await shield.aroute("0xABC...") # async
Partner / white-label support
shield = AHMShield(api_key="ahm_live_...", partner_id="partner_42")
The partner_id is sent as an x-partner-id header on every request for backend attribution.
Exceptions
| Exception | When |
|---|---|
AHMRejectError |
Address scored as reject |
AHMEscrowFlag |
Address routed to escrow (when on_escrow="raise") |
AHMAuthError |
Invalid or missing API key (401/403) |
AHMConnectionError |
API unreachable or timed out |
All inherit from AHMError.
Development
pip install -e ".[dev]"
pytest
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 ahm_shield-0.1.0.tar.gz.
File metadata
- Download URL: ahm_shield-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7acca46d8c0f4ebfc36f2906e4b7fe282187455e222e75e70e9dcd943dabd4f9
|
|
| MD5 |
213e1fbce6a5418bc83b5cec6ea96375
|
|
| BLAKE2b-256 |
3ffab1f193bc3a78509ed3751a503bc2527b9d791c9caf13da436c45e1bd9811
|
File details
Details for the file ahm_shield-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ahm_shield-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1feb60f7cdd6d10ee3e232f1821869e268abfd3a6aeb5b8af3a0eae4da5a8136
|
|
| MD5 |
d9d384650982c269e66348837743735a
|
|
| BLAKE2b-256 |
b4650dfa8e0f4d1f07e2a68bf9c1b2adf0fe84310d5451c0a9b39b35eeeb28e9
|