Skip to main content

HTTP client for the AEGIS HITL Reliability Layer — exactly-once human-in-the-loop approvals for AI agents

Project description

aegis-idempotency

PyPI version Python versions License: MIT

Async Python client for the AEGIS HITL Reliability Layer — exactly-once human-in-the-loop approvals for AI agents.

What problem does it solve?

AI agents that take consequential actions (send emails, execute trades, modify databases) need a human checkpoint before acting. Naively calling an approval endpoint is unsafe: network retries and crashes can trigger the same action twice.

aegis-idempotency solves this with strict idempotency — every approve/reject call carries an Idempotency-Key that the server uses to deduplicate across retries. You can retry safely; the action executes exactly once.

Key guarantees:

  • Exactly-once execution — duplicate calls return 409 Conflict, never re-trigger the action.
  • Safe retries with exponential backoff — automatic retry on 5xx, no retry on 4xx.
  • Unique request tracing — every call gets an auto-generated X-Request-Id.

Installation

pip install aegis-idempotency

Note: The PyPI distribution is aegis-idempotency; the import name is aegis_hitl.

Quickstart

import asyncio
from aegis_hitl import AegisClient

async def main():
    async with AegisClient(
        base_url="http://localhost:8000",
        tenant_id="tenant-abc",
        thread_id="thread-xyz",
    ) as client:
        # Approve an agent action — idempotent, safe to retry
        response = await client.approve(
            "idempotency-key-2026-001",
            payload={"action": "send_email", "to": "user@example.com"},
        )

        if response.status_code == 202:
            print("Action approved and queued.")
        elif response.status_code == 409:
            print("Duplicate — action was already processed.")

asyncio.run(main())

API Reference

AegisClient constructor

Parameter Type Default Description
base_url str "http://localhost:8000" Base URL of the AEGIS server
tenant_id str | None None Default tenant ID (required per call if not set here)
thread_id str | None None Default thread/conversation ID
timeout float 10.0 HTTP timeout in seconds
max_retries int 3 Max retries on 5xx responses
api_prefix str "/api/v1" API prefix path
client httpx.AsyncClient | None None Inject an external httpx client (for testing)

Methods

Method Description Returns
approve(key, *, tenant_id, thread_id, payload) POST /hitl/approve with idempotency key httpx.Response
reject(key, *, tenant_id, thread_id, payload) POST /hitl/reject with idempotency key httpx.Response
execute(action, key, *, tenant_id, thread_id, payload) Dispatch to approve or reject based on action string httpx.Response
get_status(request_id) GET /hitl/status/{request_id} httpx.Response

Response status codes

Code Meaning
202 Action accepted and queued for processing
409 Duplicate key — action already processed (idempotency hit)
5xx Server error — client will retry up to max_retries times

Testing without a server

AegisClient accepts an injected httpx.AsyncClient, making it easy to test with httpx.MockTransport:

import httpx
import pytest
from aegis_hitl import AegisClient

@pytest.mark.asyncio
async def test_approve():
    def handler(request):
        return httpx.Response(202, json={"ok": True})

    mock_client = httpx.AsyncClient(
        transport=httpx.MockTransport(handler),
        base_url="http://test",
    )
    async with AegisClient(tenant_id="t1", thread_id="th1", client=mock_client) as client:
        r = await client.approve("key-001")
    assert r.status_code == 202

About AEGIS

aegis-idempotency is the client SDK for the AEGIS platform — a reliability layer for AI agents that ensures human approval, exactly-once execution, and full audit trail for any consequential agent action. The server/core component is a separate private service.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aegis_idempotency-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aegis_idempotency-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file aegis_idempotency-0.1.1.tar.gz.

File metadata

  • Download URL: aegis_idempotency-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aegis_idempotency-0.1.1.tar.gz
Algorithm Hash digest
SHA256 88bb7a82594116d8b0adeb9b1c53dc4498bad7ef20e7db171e766dee9de729ef
MD5 7b1fec715b18a33e2f3cab8cda59c907
BLAKE2b-256 36f36b44ec9676b3d2a38315c2619cfb46479290e77b098fecfbc951da930945

See more details on using hashes here.

File details

Details for the file aegis_idempotency-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aegis_idempotency-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fc1bf67e0e1130d5bff515139fe27c8a131240c587ff643a36538b4cdfb4cc8a
MD5 7594eaed93940e1ac0517da5614bc9c0
BLAKE2b-256 818da7dcf3756875bdfc5bb50a7e261e20a3e26a1e4df4eff0da3356c6bbb7ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page