Skip to main content

The self-healing exception handler for autonomous AI agents.

Project description

๐Ÿ›ก๏ธ AgentX: The Semantic Firewall for AI Agents

Python 3.9+ License: MIT

LLM Agents are brilliant, but they are incredibly brittle. They will drop your production database, leak AWS keys, and fall victim to prompt injections. Traditional firewalls just crash the agent by returning a 403 Forbidden.

AgentX is different. It is a neuro-symbolic edge gateway that intercepts dangerous tool calls, blocks them, and returns a Socratic Challenge back to the agent's context windowโ€”forcing the agent to rethink its strategy and self-correct without crashing.

๐Ÿง  Don't just block agents. Coach them.


โšก 1. Two-Minute Quickstart (Zero-Configuration Protection)

AgentX requires zero changes to your underlying agentic logic, tools, or custom parameters payload schema. The SDK dynamically inspects function calls at runtime using an auto-reflective ingestion engine.

Step 1: Install the SDK

pip install agentx-security-sdk

Step 2: Decorate Sensitive Tool Operations

Simply attach the @agentx_protect decorator over any high-risk system mutation tools. The SDK automatically serializes execution signatures, tracks cognitive monologue frames across multi-turn retries, and protects your infrastructure.

from agentx_sdk import agentx_protect

@agentx_protect(agent_id="production_database_worker")
def drop_client_records(confirm: str):
    # Your native code runs untouched past the firewall boundary
    db.execute(f"DELETE FROM users WHERE confirm_token = {confirm}")

Step 3: Configure Environment Boundry Flags

Copy .env.example to .env and add your API keys (AGENTX_API_KEY, CONTROL_PLANE_URL, GEMINI_API_KEY).

Step 4: Spin up the Edge Gateway

AgentX requires an Edge node to process heuristics and embeddings at sub-millisecond speeds. Boot the gateway:

docker-compose up -d

The gateway is now listening on http://localhost:8000 and mirroring policies from your Control Plane.


Step 4: Run the Simulation

Watch the AgentX Gateway coach a rogue agent in real-time.

python examples/01_self_healing_agent.py
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 ๐Ÿ›ก๏ธ  AgentX Session Summary (Trace: 7012938b-4cde-4bea-aac8)
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 โฑ๏ธ  Uptime:                15.49 seconds
 ๐Ÿ› ๏ธ  Tools Monitored:       2
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 ๐Ÿ›‘ Intercepts:            1   |  Cumulative: 34
 ๐Ÿ’ฅ Critical Blocks:       1   |  Cumulative: 18
 ๐Ÿ”„ Self-Corrections:      1   |  Recovery Rate: 100.0%
 ๐Ÿ’ฐ Tokens Saved:         ~1500  |  Cumulative: ~51000
 โณ Time Saved:           ~5s    |  Cumulative: ~170s
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 ๐Ÿฉบ AGENT HEALTH INSIGHT
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 โš ๏ธ  Top Offender: 'Database Isolation'
 ๐Ÿ’ก Tip: Consider refining your agent's system prompt to avoid this.

---

๐Ÿง  The 5 Pillars of Agentic Security

AgentX is built on a "Reasoning Engine" architecture that treats AI agents as autonomous employees rather than static scripts. We secure them through five core pillars:

1. Cognitive Interception: We intercept tool calls to compare the agent's stated intent (Chain of Thought) against its actual deterministic action.

2. Socratic Nudging: Instead of crashing the agent with a 403 Forbidden, we issue a Socratic Challenge to guide them to a safe, desired end-goal.

3. Human-in-the-Loop (HITL): If the gateway cannot judge intent safely, the agent is paused (202 Accepted) and sent to a SOC Sandbox for human evaluation.

4. Dynamic Policy Refresh: Policies are pushed out-of-band via a centralized Control Plane, updating localized edge-caches within 3 seconds.

5. Auditable Self-Healing: The system dynamically captures successful agent recovery rates on your dashboard when a model successfully self-corrects post-challenge.

---

๐Ÿš€ The 4 Shields (Defense-in-Depth)
1. The Inbound Shield (Prompt Injection): Sanitizes inbound user text to prevent cognitive hijacking ("Ignore previous instructions") before the agent reads it.

2. The Logic Shield (Database Guard): Uses AST parsing and Gemini to catch destructive queries (DROP, DELETE) and nudges the agent to write safer SQL.

3. The Network Shield (SSRF Guard): Prevents agents from acting as confused deputies to hit cloud metadata IPs (e.g., 169.254.169.254).

4. The Egress Shield (DLP/PII Scrubber): Dynamically masks PII and API keys on the wire, maintaining clean audit logs without triggering SOC alert fatigue.

---

## ๐Ÿ“Š Local Telemetry & Agent Health

AgentX ships with a built-in, privacy-first SQLite time-series event log (`.agentx.db`). It tracks every interception locally. When your agent script finishes or crashes, AgentX automatically prints a comprehensive Session Summary and Lifetime ROI dashboard:

```text
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 ๐Ÿ›ก๏ธ  AgentX Session Summary
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 โฑ๏ธ  Uptime:                9.17 seconds
 ๐Ÿ› ๏ธ  Tools Monitored:       2
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 ๐Ÿ›‘ Intercepts:            1   |  Cumulative: 5
 ๐Ÿ’ฅ Critical Blocks:       1   |  Cumulative: 5
 ๐Ÿ’ฐ Tokens Saved:      ~1500   |  Cumulative: ~7500
 โณ Time Saved:        ~5m     |  Cumulative: ~25m
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 ๐Ÿฉบ AGENT HEALTH INSIGHT
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 โš ๏ธ Top Offender: 'Database Isolation'
 ๐Ÿ› ๏ธ  Tip: Consider refining your agent's system prompt to avoid this.
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ“ฆ Try the Developer Demos Inside the examples/ folder, you will find a few standalone scripts proving the AgentX Reasoning Layer:

  • 01_self_healing_agent.py: Watch AgentX catch a hallucination and coach the agent to self-correct (Saving tokens and uptime).
  • 02_cognitive_intent_block.py: Watch the Semantic Firewall catch malicious intent even when the raw syntax is perfectly safe.
  • 03_human_escalation.py: See how an agent safely pauses execution and pings a SOC analyst for approval using a 202 Accepted queue.
  • And many more...

๐Ÿ•น๏ธ Human-in-the-Loop (HITL) & Control Plane

Sometimes, an agent needs to drop a table for a valid business reason.

AgentX features a Next.js Control Plane Dashboard. If an agent requests an escalation, the SDK securely pauses local execution and polls the Edge Gateway. A human SOC analyst can click "Approve" or "Deny" in the UI, and the Python execution loop will automatically resume.

cd ui
npm install
npm run dev

---

## ๐Ÿค Contributing
We are actively looking for design partners. If you are building autonomous agents in production and are terrified of what they might do, open an issue or reach out!

---

## ๐Ÿ—๏ธ The Architecture (Split-Plane)

AgentX relies on a decoupled, hybrid-cloud architecture to ensure maximum performance and security for AI-driven enterprise systems.

* **The Edge SDK (AgentX)**: The lightweight Python package that instruments agent tools and triggers local Socratic self-healing.
* **The Data Plane (Semantic Firewall)**: A Python FastAPI middleware (the "Wedge") that intercepts raw HTTP/SQL payloads *before* they hit the database.
* **The Control Plane (Dashboard)**: A Next.js application (deployed via Vercel) that allows human reviewers to monitor intercepted agent traffic, review chains of thought, and approve or deny parked requests.
* **The Shared Brain**: Supabase acts as the central state manager. Both the Control Plane and Data Plane synchronize via Supabase, decoupling the network architecture and allowing asynchronous state polling.
* **The Evaluator**: Google's Gemini 2.5 Flash is used to translate an agent's Chain of Thought (CoT) into a zero-knowledge taxonomy to evaluate intent against YAML-defined enterprise policies.

---

## โœจ Key Features & Built-in Policies

* **Automated Socratic Self-Healing**: Intercepts dangerous tool calls and challenges the agent to revise its strategy.
* **Fast Pass Heuristic Traps**: Instantly intercepts structurally dangerous queries (e.g., `DROP TABLE`, `DELETE`) with minimal latency.
* **Zero-Knowledge Intent Extraction**: Prevents malicious prompt injection by translating raw agent logic into a strict schema before policy evaluation.
* **Dynamic Cloud Policies**: Enforces isolation rules instantly via a Supabase-backed Control Plane that syncs to edge caches in 3 seconds.

---

## ๐Ÿ”’ Security Posture

* **Secret Management**: API keys are never checked into version control. Production variables are managed securely via the Vercel Dashboard.
* **History Scrubbing**: This repository has been scrubbed of legacy keys using git-filter-repo.
* **Private IP**: Repository is private to protect proprietary evaluation prompts and architecture.

---

๐Ÿ“ˆ Updated Roadmap
โœ… Trust Boundary Shift: Moved neuro-symbolic evaluation entirely into the Data Plane container to eliminate agent runtime bypasses. (Completed)

โœ… Zero-Knowledge Hard Split-Plane: Mathematically enforced VPC telemetry isolation via localized metric stripping. (Completed)

โœ… Zero-Config Reflection Engine: Eliminated manual query and CoT boilerplate function writing; implemented dynamic parameter serialization natively within the SDK decorator loop. (Completed)

โฌœ Local LRU Neural Cache: Deduplicate vector embeddings to minimize edge latency down to sub-1ms. (Next up)

โฌœ Core DevX Inspection Engine: Expose a unified CLI interface for localized policy and metric auditing. (Active)

โฌœ Containerize the Data Plane for deployment to AWS ECS / Render for persistent, low-latency edge interception.

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

agentx_security_sdk-0.2.7.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

agentx_security_sdk-0.2.7-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file agentx_security_sdk-0.2.7.tar.gz.

File metadata

  • Download URL: agentx_security_sdk-0.2.7.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for agentx_security_sdk-0.2.7.tar.gz
Algorithm Hash digest
SHA256 a79b24a7095f8d276d98dc3ff159f6a8bb4b9d11aa06d44b1085c064b3a02509
MD5 6f6c5fa66d800cd41183fa3f0de6d7e8
BLAKE2b-256 0aef3e4e72b04ee510e6a24c3dc1676f8124e1a4dcd54c6f1fef0eda3c5c7482

See more details on using hashes here.

File details

Details for the file agentx_security_sdk-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for agentx_security_sdk-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7183284302d0930cd1d5be7c6f1f52d3206c3c4e14e3cbf9c03ededfab426fb3
MD5 af192f03e8fdfa299ce5f018ab5d3e14
BLAKE2b-256 a0a9c81534dce9c17b60dcca1f555fc469da8d8fbdcb02177514d9d20cb2a94c

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