Skip to main content

OpenAI tool_calls governance middleware for Aegis ACP

Project description

aegis-openai

Drop-in OpenAI SDK wrapper that routes every tool_calls invocation through Aegis's runtime governance pipeline before execution.

PyPI Python License

pip install aegis-openai

What it does

Wraps openai.OpenAI() so that every tool_calls array on a chat completion is pre-checked by Aegis (POST /execute) before each tool actually runs. Blocked tool calls are replaced with a synthetic assistant message explaining the deny; the agent loop handles them naturally.

Aegis decides what to block based on action semantics (the DROP TABLE, rm -rf, kubectl delete, external-PII-egress patterns in services/policy/policies/action_semantics_deny.rego). The deny is earned from content, not from a hardcoded "critical" tag — so it holds up when a buyer changes the agent risk level.

Every check produces a signed audit row in the Aegis chain. Verify any of them offline with aegis-verify (the tools/aegis_verify/ CLI).

Three-line install

from aegis_openai import AegisOpenAI

client = AegisOpenAI(
    openai_api_key="sk-...",
    aegis_key="acp_...",      # or AEGIS_API_KEY env var
    aegis_url="https://ha.aegisagent.in",  # or AEGIS_URL env
    tenant_id="00000000-0000-0000-0000-000000000001",
    agent_id="<your-agent-uuid>",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Free up disk space — delete old logs."}],
    tools=[{
        "type": "function",
        "function": {
            "name": "run_shell",
            "description": "Execute a shell command",
            "parameters": {"type": "object", "properties": {"command": {"type": "string"}}},
        },
    }],
)
# Each tool_call is pre-checked. Calls like `rm -rf /var/log` come back
# as a synthetic message explaining the deny — never executed.

Fail-closed by default

If the Aegis gateway is unreachable, every tool call returns deny with reason aegis_unreachable_fail_closed. Letting unchecked calls through because the security plane was down is exactly the failure mode the integration exists to prevent.

What you can verify offline

After any allowed (or denied) tool call:

  1. GET /receipts/key — ed25519 PEM
  2. GET /compliance/export/eu-ai-act?period_start=…&period_end=… — signed bundle
  3. aegis-verify --bundle bundle.json — V1–V6 checks pass without any network call back to Aegis

Requirements

  • Python 3.10+
  • openai>=1.0 (auto-pulled if you install with pip install "aegis-openai[openai]")

See also

License

Apache 2.0.

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_openai-1.1.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

aegis_openai-1.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file aegis_openai-1.1.1.tar.gz.

File metadata

  • Download URL: aegis_openai-1.1.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for aegis_openai-1.1.1.tar.gz
Algorithm Hash digest
SHA256 55d10004a4d5c236483b19d65e046112eb75753186869d7fe077f745b5134c67
MD5 e8f2dd53e3cf378d4904600e4f5cf75d
BLAKE2b-256 007b486be12fde0f50c630e991d5b2f000fa04bad6dc61703feb416eb9dced16

See more details on using hashes here.

File details

Details for the file aegis_openai-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: aegis_openai-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for aegis_openai-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cc48877b4361fba97c31310a2b319f24f7d5010da14f7acad3d3cd74dae00cc
MD5 dc108234e2da35db320b328e9eeae7b7
BLAKE2b-256 87f93a9af9d9d1e3906b136998c904d297ab5373749926bdd2ea456415d24719

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