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.
pip install ahm-shield
# with FastAPI middleware support
pip install ahm-shield[fastapi]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@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.
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.
Every method has a sync and async variant:
result = shield.route("0xABC...") # sync
result = await shield.aroute("0xABC...") # asyncshield = 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.
| 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.
pip install -e ".[dev]"
pytest