agentx-security-sdk 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
agentx_sdk/__init__.py
ADDED
agentx_sdk/client.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
class AgentXClient:
|
|
5
|
+
def __init__(self, api_key: str = None, gateway_url: str = "http://localhost:8000"):
|
|
6
|
+
# In the future, api_key authenticates them to our cloud.
|
|
7
|
+
# For now, it connects to their local Sidecar Gateway.
|
|
8
|
+
self.api_key = api_key or os.environ.get("AGENTX_API_KEY")
|
|
9
|
+
self.gateway_url = gateway_url
|
|
10
|
+
|
|
11
|
+
def evaluate_intent(self, agent_id: str, query: str, chain_of_thought: str, receipt_id: str = None):
|
|
12
|
+
payload = {
|
|
13
|
+
"agent_id": agent_id,
|
|
14
|
+
"original_query": query,
|
|
15
|
+
"chain_of_thought": chain_of_thought,
|
|
16
|
+
"receipt_id": receipt_id
|
|
17
|
+
}
|
|
18
|
+
try:
|
|
19
|
+
response = requests.post(f"{self.gateway_url}/v1/evaluate_intent", json=payload)
|
|
20
|
+
response.raise_for_status()
|
|
21
|
+
return response.json()
|
|
22
|
+
except requests.exceptions.RequestException as e:
|
|
23
|
+
# If our gateway is down, we Fail Closed to protect the system.
|
|
24
|
+
return {"status": "ERROR", "message": f"AgentX Gateway unreachable: {str(e)}"}
|
agentx_sdk/decorators.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import json
|
|
3
|
+
import atexit
|
|
4
|
+
import time
|
|
5
|
+
from .client import AgentXClient
|
|
6
|
+
|
|
7
|
+
_client = AgentXClient()
|
|
8
|
+
|
|
9
|
+
# --- 1. THE ROI TRACKER ---
|
|
10
|
+
_session_stats = {
|
|
11
|
+
"start_time": time.time(),
|
|
12
|
+
"total_calls": 0,
|
|
13
|
+
"intercepts": 0,
|
|
14
|
+
"critical_blocks": 0
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def _print_roi_summary():
|
|
18
|
+
"""Fires automatically when the developer's script ends or crashes."""
|
|
19
|
+
duration = round(time.time() - _session_stats["start_time"], 2)
|
|
20
|
+
|
|
21
|
+
# Heuristic: Every intercept prevents the agent from burning ~1,500 tokens
|
|
22
|
+
# going down a rabbit hole, plus saves the developer ~5 mins of debugging.
|
|
23
|
+
tokens_saved = _session_stats["intercepts"] * 1500
|
|
24
|
+
dollars_saved = (tokens_saved / 1000) * 0.015 # Approx GPT-4o cost
|
|
25
|
+
|
|
26
|
+
print("\n" + "ā"*50)
|
|
27
|
+
print(" š”ļø AgentX Session Summary")
|
|
28
|
+
print("ā"*50)
|
|
29
|
+
print(f" ā±ļø Uptime: {duration} seconds")
|
|
30
|
+
print(f" š ļø Tools Monitored: {_session_stats['total_calls']}")
|
|
31
|
+
print(f" š Socratic Intercepts: {_session_stats['intercepts']}")
|
|
32
|
+
print(f" š„ Catastrophic Blocks: {_session_stats['critical_blocks']}")
|
|
33
|
+
print("ā"*50)
|
|
34
|
+
print(f" š° Est. Tokens Saved: ~{tokens_saved} (${dollars_saved:.4f})")
|
|
35
|
+
print(f" ā³ Developer Time Saved: ~{_session_stats['intercepts'] * 5} minutes")
|
|
36
|
+
print("ā"*50 + "\n")
|
|
37
|
+
|
|
38
|
+
# Register the hook to run on exit
|
|
39
|
+
atexit.register(_print_roi_summary)
|
|
40
|
+
# --------------------------
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def agentx_protect(agent_id: str, extract_query_func=None, extract_cot_func=None):
|
|
44
|
+
def decorator(func):
|
|
45
|
+
@functools.wraps(func)
|
|
46
|
+
def wrapper(*args, **kwargs):
|
|
47
|
+
# Track the call
|
|
48
|
+
_session_stats["total_calls"] += 1
|
|
49
|
+
|
|
50
|
+
query = extract_query_func(*args, **kwargs) if extract_query_func else str(args)
|
|
51
|
+
chain_of_thought = extract_cot_func(*args, **kwargs) if extract_cot_func else "Implicit tool call"
|
|
52
|
+
receipt_id = kwargs.get("receipt_id", None)
|
|
53
|
+
|
|
54
|
+
print(f"\nš”ļø [AgentX SDK] Intercepting tool call to '{func.__name__}'...")
|
|
55
|
+
|
|
56
|
+
eval_res = _client.evaluate_intent(
|
|
57
|
+
agent_id=agent_id,
|
|
58
|
+
query=query,
|
|
59
|
+
chain_of_thought=chain_of_thought,
|
|
60
|
+
receipt_id=receipt_id
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
status = eval_res.get("status")
|
|
64
|
+
|
|
65
|
+
if status in ["APPROVED", "COMPLIED"]:
|
|
66
|
+
print(f"ā
[AgentX SDK] Intent safe. Executing '{func.__name__}'.")
|
|
67
|
+
return func(*args, **kwargs)
|
|
68
|
+
|
|
69
|
+
elif status == "CHALLENGED":
|
|
70
|
+
# Track the intercept
|
|
71
|
+
_session_stats["intercepts"] += 1
|
|
72
|
+
|
|
73
|
+
challenge = eval_res.get('socratic_prompt', '')
|
|
74
|
+
policy_triggered = eval_res.get('policy_triggered', 'Unknown Policy')
|
|
75
|
+
|
|
76
|
+
# --- THE NEW DETERMINISTIC CHECK ---
|
|
77
|
+
# We specifically track our highest-severity policy for the ROI dashboard
|
|
78
|
+
# Your engine is returning "Database Isolation", so we check for that!
|
|
79
|
+
if policy_triggered in ["Mass Destructive Intent", "Database Isolation"]:
|
|
80
|
+
_session_stats["critical_blocks"] += 1
|
|
81
|
+
# -----------------------------------
|
|
82
|
+
|
|
83
|
+
new_receipt = eval_res.get('receipt_id')
|
|
84
|
+
print(f"š [AgentX SDK] Policy '{policy_triggered}' violated. Returning challenge to Agent.")
|
|
85
|
+
|
|
86
|
+
return json.dumps({
|
|
87
|
+
"error": "AgentX Policy Violation",
|
|
88
|
+
"challenge": challenge,
|
|
89
|
+
"receipt_id": new_receipt,
|
|
90
|
+
"instruction": "Revise your action to comply with the challenge and try again. Pass the receipt_id."
|
|
91
|
+
})
|
|
92
|
+
else:
|
|
93
|
+
return f"AgentX System Error: {eval_res.get('message')}"
|
|
94
|
+
|
|
95
|
+
return wrapper
|
|
96
|
+
return decorator
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentx-security-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The self-healing exception handler for autonomous AI agents.
|
|
5
|
+
Home-page: https://github.com/vdalal/semantic-gateway
|
|
6
|
+
Author: AgentX Team
|
|
7
|
+
Author-email: founders@agentx.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: requests>=2.25.0
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: requires-dist
|
|
23
|
+
Dynamic: requires-python
|
|
24
|
+
Dynamic: summary
|
|
25
|
+
|
|
26
|
+
The self-healing exception handler for autonomous AI agents.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
agentx_sdk/__init__.py,sha256=F-qQjUNE3gVvsY1ZI3P8ZLNxNtQzC2a-hUZbQRELIWM,120
|
|
2
|
+
agentx_sdk/client.py,sha256=qxtTM1GalxNTLd97Cf4DOa0TACBJjJmXK1RcQFRLw0g,1094
|
|
3
|
+
agentx_sdk/decorators.py,sha256=8r0xFFi660qfP0QHQID-46nqXxsFQdp2lFlyKAwO-ks,4054
|
|
4
|
+
agentx_security_sdk-0.1.0.dist-info/METADATA,sha256=CKB5R13fuVy0J9CvkbiUUWSg_nFu3pYSM6l-G1XNP6Q,855
|
|
5
|
+
agentx_security_sdk-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
agentx_security_sdk-0.1.0.dist-info/top_level.txt,sha256=_sRdpWoXB1H2iyhAp9OiDsgz4HFAUfEiw_rb8gh1Lqg,11
|
|
7
|
+
agentx_security_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
agentx_sdk
|