haltstate-sdk 0.6.0__tar.gz
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.
- haltstate_sdk-0.6.0/LICENSE +21 -0
- haltstate_sdk-0.6.0/PKG-INFO +185 -0
- haltstate_sdk-0.6.0/README.md +137 -0
- haltstate_sdk-0.6.0/haltstate/__init__.py +66 -0
- haltstate_sdk-0.6.0/haltstate_sdk.egg-info/PKG-INFO +185 -0
- haltstate_sdk-0.6.0/haltstate_sdk.egg-info/SOURCES.txt +17 -0
- haltstate_sdk-0.6.0/haltstate_sdk.egg-info/dependency_links.txt +1 -0
- haltstate_sdk-0.6.0/haltstate_sdk.egg-info/requires.txt +1 -0
- haltstate_sdk-0.6.0/haltstate_sdk.egg-info/top_level.txt +2 -0
- haltstate_sdk-0.6.0/janus/__init__.py +43 -0
- haltstate_sdk-0.6.0/janus/async_client.py +340 -0
- haltstate_sdk-0.6.0/janus/client.py +733 -0
- haltstate_sdk-0.6.0/janus/decorators.py +88 -0
- haltstate_sdk-0.6.0/janus/exceptions.py +69 -0
- haltstate_sdk-0.6.0/janus/models.py +80 -0
- haltstate_sdk-0.6.0/pyproject.toml +37 -0
- haltstate_sdk-0.6.0/setup.cfg +4 -0
- haltstate_sdk-0.6.0/tests/test_client.py +84 -0
- haltstate_sdk-0.6.0/tests/test_import.py +8 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Krystal Unity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: haltstate-sdk
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: HaltState Sentinel Python SDK - Compliance & Policy Checks for AI Agents
|
|
5
|
+
Author-email: Krystal Unity <support@krystalunity.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Krystal Unity
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://haltstate.ai
|
|
29
|
+
Project-URL: Repository, https://github.com/StartKrystal/krystal-unity-core
|
|
30
|
+
Project-URL: Issues, https://github.com/StartKrystal/krystal-unity-core/issues
|
|
31
|
+
Project-URL: Documentation, https://haltstate.ai/docs
|
|
32
|
+
Keywords: haltstate,janus,sentinel,ai,compliance,policy,sdk,safety
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
42
|
+
Classifier: Topic :: Security
|
|
43
|
+
Requires-Python: >=3.9
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
License-File: LICENSE
|
|
46
|
+
Requires-Dist: httpx>=0.24
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# HaltState Sentinel SDK
|
|
50
|
+
|
|
51
|
+
[](https://pypi.org/project/haltstate-sdk/)
|
|
52
|
+
|
|
53
|
+
Compliance & policy checks for AI agents. Perform pre-action checks, approvals, and post-action reporting with minimal code.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
```bash
|
|
57
|
+
pip install haltstate-sdk
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quickstart (sync)
|
|
61
|
+
```python
|
|
62
|
+
from haltstate import HaltStateClient
|
|
63
|
+
|
|
64
|
+
client = HaltStateClient(tenant_id="your_tenant_id", api_key="janus_xyz", fail_open=False)
|
|
65
|
+
|
|
66
|
+
decision = client.check(
|
|
67
|
+
action="payment.process",
|
|
68
|
+
params={"amount": 5000, "currency": "USD"},
|
|
69
|
+
agent_id="payment-bot-01",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if decision.allowed:
|
|
73
|
+
process_payment(...)
|
|
74
|
+
client.report(decision, status="success", result={"transaction_id": "tx_123"}, action="payment.process", agent_id="payment-bot-01")
|
|
75
|
+
elif decision.requires_approval:
|
|
76
|
+
print(f"Approval required: {decision.reason}")
|
|
77
|
+
else:
|
|
78
|
+
print(f"Action denied: {decision.reason}")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Backward Compatibility
|
|
82
|
+
|
|
83
|
+
Existing code using `janus` imports continues to work:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from janus import JanusClient # Still works!
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Guard Pattern (SDK 0.5.0+)
|
|
90
|
+
|
|
91
|
+
For actions requiring human approval, use the idempotent guard pattern:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from haltstate import AsyncHaltStateClient, ActionPending, ActionRejected
|
|
95
|
+
|
|
96
|
+
async def process_high_value_payment(invoice_id: str, amount: float):
|
|
97
|
+
client = AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx")
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
async with client.guard(
|
|
101
|
+
action="payment.process",
|
|
102
|
+
agent_id="payment-bot",
|
|
103
|
+
params={"invoice_id": invoice_id, "amount": amount},
|
|
104
|
+
idempotency_key=f"payment-{invoice_id}", # Retry-safe
|
|
105
|
+
timeout_seconds=300
|
|
106
|
+
) as permit:
|
|
107
|
+
# Only executes after human approval
|
|
108
|
+
result = await execute_payment(amount)
|
|
109
|
+
print(f"Approved by {permit.approver} at {permit.approved_at}")
|
|
110
|
+
return result
|
|
111
|
+
|
|
112
|
+
except ActionPending:
|
|
113
|
+
print("Awaiting human approval...")
|
|
114
|
+
return {"status": "pending"}
|
|
115
|
+
|
|
116
|
+
except ActionRejected as e:
|
|
117
|
+
print(f"Rejected by {e.rejected_by}: {e.reason}")
|
|
118
|
+
raise
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Key features:
|
|
122
|
+
- **Idempotency keys**: Same key = same approval request, safe for retries
|
|
123
|
+
- **Process restart safety**: Approved actions can be executed after restart
|
|
124
|
+
- **Audit trail**: Full record of who approved and when
|
|
125
|
+
|
|
126
|
+
## Decorators
|
|
127
|
+
```python
|
|
128
|
+
from haltstate import HaltStateClient, haltstate_guard
|
|
129
|
+
|
|
130
|
+
client = HaltStateClient(tenant_id="acme", api_key="janus_xxx")
|
|
131
|
+
|
|
132
|
+
@haltstate_guard(client, action="email.send", agent_id="email-bot")
|
|
133
|
+
def send_email(to, subject, body):
|
|
134
|
+
return mailer.send(to, subject, body)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Async
|
|
138
|
+
```python
|
|
139
|
+
from haltstate import AsyncHaltStateClient
|
|
140
|
+
|
|
141
|
+
async def main():
|
|
142
|
+
async with AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx") as client:
|
|
143
|
+
res = await client.check("database.drop", params={"table": "users"})
|
|
144
|
+
if res.allowed:
|
|
145
|
+
await client.report(res, status="success", action="database.drop", agent_id="ops-bot")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Exceptions
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from haltstate import (
|
|
152
|
+
HaltStateError, # Base error
|
|
153
|
+
HaltStateAuthError, # Invalid API key
|
|
154
|
+
HaltStateConnectionError, # Network/timeout
|
|
155
|
+
ActionPending, # Awaiting approval (guard pattern)
|
|
156
|
+
ActionRejected, # Human rejected (guard pattern)
|
|
157
|
+
ActionTimeout, # Approval expired (guard pattern)
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Docs
|
|
162
|
+
|
|
163
|
+
Full documentation at [haltstate.ai/docs](https://haltstate.ai/docs):
|
|
164
|
+
- Quickstart - 5-minute setup
|
|
165
|
+
- Guard Pattern - HITL approval flow
|
|
166
|
+
- API Reference - All methods
|
|
167
|
+
- Error Handling - Exception handling
|
|
168
|
+
- SB-53 Compliance - Regulatory mapping
|
|
169
|
+
|
|
170
|
+
## Migration from janus-sdk
|
|
171
|
+
|
|
172
|
+
If upgrading from `janus-sdk`:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# Old (still works)
|
|
176
|
+
from janus import JanusClient, janus_guard
|
|
177
|
+
|
|
178
|
+
# New
|
|
179
|
+
from haltstate import HaltStateClient, haltstate_guard
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Both import styles work - no code changes required for existing users.
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
MIT
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# HaltState Sentinel SDK
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/haltstate-sdk/)
|
|
4
|
+
|
|
5
|
+
Compliance & policy checks for AI agents. Perform pre-action checks, approvals, and post-action reporting with minimal code.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
```bash
|
|
9
|
+
pip install haltstate-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quickstart (sync)
|
|
13
|
+
```python
|
|
14
|
+
from haltstate import HaltStateClient
|
|
15
|
+
|
|
16
|
+
client = HaltStateClient(tenant_id="your_tenant_id", api_key="janus_xyz", fail_open=False)
|
|
17
|
+
|
|
18
|
+
decision = client.check(
|
|
19
|
+
action="payment.process",
|
|
20
|
+
params={"amount": 5000, "currency": "USD"},
|
|
21
|
+
agent_id="payment-bot-01",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
if decision.allowed:
|
|
25
|
+
process_payment(...)
|
|
26
|
+
client.report(decision, status="success", result={"transaction_id": "tx_123"}, action="payment.process", agent_id="payment-bot-01")
|
|
27
|
+
elif decision.requires_approval:
|
|
28
|
+
print(f"Approval required: {decision.reason}")
|
|
29
|
+
else:
|
|
30
|
+
print(f"Action denied: {decision.reason}")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Backward Compatibility
|
|
34
|
+
|
|
35
|
+
Existing code using `janus` imports continues to work:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from janus import JanusClient # Still works!
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Guard Pattern (SDK 0.5.0+)
|
|
42
|
+
|
|
43
|
+
For actions requiring human approval, use the idempotent guard pattern:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from haltstate import AsyncHaltStateClient, ActionPending, ActionRejected
|
|
47
|
+
|
|
48
|
+
async def process_high_value_payment(invoice_id: str, amount: float):
|
|
49
|
+
client = AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx")
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
async with client.guard(
|
|
53
|
+
action="payment.process",
|
|
54
|
+
agent_id="payment-bot",
|
|
55
|
+
params={"invoice_id": invoice_id, "amount": amount},
|
|
56
|
+
idempotency_key=f"payment-{invoice_id}", # Retry-safe
|
|
57
|
+
timeout_seconds=300
|
|
58
|
+
) as permit:
|
|
59
|
+
# Only executes after human approval
|
|
60
|
+
result = await execute_payment(amount)
|
|
61
|
+
print(f"Approved by {permit.approver} at {permit.approved_at}")
|
|
62
|
+
return result
|
|
63
|
+
|
|
64
|
+
except ActionPending:
|
|
65
|
+
print("Awaiting human approval...")
|
|
66
|
+
return {"status": "pending"}
|
|
67
|
+
|
|
68
|
+
except ActionRejected as e:
|
|
69
|
+
print(f"Rejected by {e.rejected_by}: {e.reason}")
|
|
70
|
+
raise
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Key features:
|
|
74
|
+
- **Idempotency keys**: Same key = same approval request, safe for retries
|
|
75
|
+
- **Process restart safety**: Approved actions can be executed after restart
|
|
76
|
+
- **Audit trail**: Full record of who approved and when
|
|
77
|
+
|
|
78
|
+
## Decorators
|
|
79
|
+
```python
|
|
80
|
+
from haltstate import HaltStateClient, haltstate_guard
|
|
81
|
+
|
|
82
|
+
client = HaltStateClient(tenant_id="acme", api_key="janus_xxx")
|
|
83
|
+
|
|
84
|
+
@haltstate_guard(client, action="email.send", agent_id="email-bot")
|
|
85
|
+
def send_email(to, subject, body):
|
|
86
|
+
return mailer.send(to, subject, body)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Async
|
|
90
|
+
```python
|
|
91
|
+
from haltstate import AsyncHaltStateClient
|
|
92
|
+
|
|
93
|
+
async def main():
|
|
94
|
+
async with AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx") as client:
|
|
95
|
+
res = await client.check("database.drop", params={"table": "users"})
|
|
96
|
+
if res.allowed:
|
|
97
|
+
await client.report(res, status="success", action="database.drop", agent_id="ops-bot")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Exceptions
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from haltstate import (
|
|
104
|
+
HaltStateError, # Base error
|
|
105
|
+
HaltStateAuthError, # Invalid API key
|
|
106
|
+
HaltStateConnectionError, # Network/timeout
|
|
107
|
+
ActionPending, # Awaiting approval (guard pattern)
|
|
108
|
+
ActionRejected, # Human rejected (guard pattern)
|
|
109
|
+
ActionTimeout, # Approval expired (guard pattern)
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Docs
|
|
114
|
+
|
|
115
|
+
Full documentation at [haltstate.ai/docs](https://haltstate.ai/docs):
|
|
116
|
+
- Quickstart - 5-minute setup
|
|
117
|
+
- Guard Pattern - HITL approval flow
|
|
118
|
+
- API Reference - All methods
|
|
119
|
+
- Error Handling - Exception handling
|
|
120
|
+
- SB-53 Compliance - Regulatory mapping
|
|
121
|
+
|
|
122
|
+
## Migration from janus-sdk
|
|
123
|
+
|
|
124
|
+
If upgrading from `janus-sdk`:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# Old (still works)
|
|
128
|
+
from janus import JanusClient, janus_guard
|
|
129
|
+
|
|
130
|
+
# New
|
|
131
|
+
from haltstate import HaltStateClient, haltstate_guard
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Both import styles work - no code changes required for existing users.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# HaltState SDK - re-exports from janus for new branding
|
|
2
|
+
# Backward compatible: both `from haltstate import HaltStateClient` and
|
|
3
|
+
# `from janus import JanusClient` continue to work.
|
|
4
|
+
|
|
5
|
+
from janus.client import JanusClient as HaltStateClient, Permit
|
|
6
|
+
from janus.async_client import AsyncJanusClient as AsyncHaltStateClient
|
|
7
|
+
from janus.models import CheckResult, Decision, ApprovalDecision, ApprovalStatus
|
|
8
|
+
from janus.decorators import janus_guard as haltstate_guard, openai_guard
|
|
9
|
+
from janus.exceptions import (
|
|
10
|
+
JanusError as HaltStateError,
|
|
11
|
+
JanusConnectionError as HaltStateConnectionError,
|
|
12
|
+
JanusAuthError as HaltStateAuthError,
|
|
13
|
+
JanusRateLimitError as HaltStateRateLimitError,
|
|
14
|
+
JanusApprovalTimeoutError as HaltStateApprovalTimeoutError,
|
|
15
|
+
ApprovalPending,
|
|
16
|
+
ActionDenied,
|
|
17
|
+
ActionExpired,
|
|
18
|
+
KillSwitchTriggered,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# Keep Janus names as aliases for full backward compatibility
|
|
22
|
+
from janus import (
|
|
23
|
+
JanusClient,
|
|
24
|
+
AsyncJanusClient,
|
|
25
|
+
janus_guard,
|
|
26
|
+
JanusError,
|
|
27
|
+
JanusConnectionError,
|
|
28
|
+
JanusAuthError,
|
|
29
|
+
JanusRateLimitError,
|
|
30
|
+
JanusApprovalTimeoutError,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
# HaltState branded names (new)
|
|
35
|
+
"HaltStateClient",
|
|
36
|
+
"AsyncHaltStateClient",
|
|
37
|
+
"haltstate_guard",
|
|
38
|
+
"HaltStateError",
|
|
39
|
+
"HaltStateConnectionError",
|
|
40
|
+
"HaltStateAuthError",
|
|
41
|
+
"HaltStateRateLimitError",
|
|
42
|
+
"HaltStateApprovalTimeoutError",
|
|
43
|
+
# Janus names (backward compatible)
|
|
44
|
+
"JanusClient",
|
|
45
|
+
"AsyncJanusClient",
|
|
46
|
+
"janus_guard",
|
|
47
|
+
"JanusError",
|
|
48
|
+
"JanusConnectionError",
|
|
49
|
+
"JanusAuthError",
|
|
50
|
+
"JanusRateLimitError",
|
|
51
|
+
"JanusApprovalTimeoutError",
|
|
52
|
+
# Shared models
|
|
53
|
+
"CheckResult",
|
|
54
|
+
"Decision",
|
|
55
|
+
"ApprovalDecision",
|
|
56
|
+
"ApprovalStatus",
|
|
57
|
+
"Permit",
|
|
58
|
+
"openai_guard",
|
|
59
|
+
# Control flow exceptions
|
|
60
|
+
"ApprovalPending",
|
|
61
|
+
"ActionDenied",
|
|
62
|
+
"ActionExpired",
|
|
63
|
+
"KillSwitchTriggered",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
__version__ = "0.5.0"
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: haltstate-sdk
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: HaltState Sentinel Python SDK - Compliance & Policy Checks for AI Agents
|
|
5
|
+
Author-email: Krystal Unity <support@krystalunity.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Krystal Unity
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://haltstate.ai
|
|
29
|
+
Project-URL: Repository, https://github.com/StartKrystal/krystal-unity-core
|
|
30
|
+
Project-URL: Issues, https://github.com/StartKrystal/krystal-unity-core/issues
|
|
31
|
+
Project-URL: Documentation, https://haltstate.ai/docs
|
|
32
|
+
Keywords: haltstate,janus,sentinel,ai,compliance,policy,sdk,safety
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
42
|
+
Classifier: Topic :: Security
|
|
43
|
+
Requires-Python: >=3.9
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
License-File: LICENSE
|
|
46
|
+
Requires-Dist: httpx>=0.24
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# HaltState Sentinel SDK
|
|
50
|
+
|
|
51
|
+
[](https://pypi.org/project/haltstate-sdk/)
|
|
52
|
+
|
|
53
|
+
Compliance & policy checks for AI agents. Perform pre-action checks, approvals, and post-action reporting with minimal code.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
```bash
|
|
57
|
+
pip install haltstate-sdk
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quickstart (sync)
|
|
61
|
+
```python
|
|
62
|
+
from haltstate import HaltStateClient
|
|
63
|
+
|
|
64
|
+
client = HaltStateClient(tenant_id="your_tenant_id", api_key="janus_xyz", fail_open=False)
|
|
65
|
+
|
|
66
|
+
decision = client.check(
|
|
67
|
+
action="payment.process",
|
|
68
|
+
params={"amount": 5000, "currency": "USD"},
|
|
69
|
+
agent_id="payment-bot-01",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if decision.allowed:
|
|
73
|
+
process_payment(...)
|
|
74
|
+
client.report(decision, status="success", result={"transaction_id": "tx_123"}, action="payment.process", agent_id="payment-bot-01")
|
|
75
|
+
elif decision.requires_approval:
|
|
76
|
+
print(f"Approval required: {decision.reason}")
|
|
77
|
+
else:
|
|
78
|
+
print(f"Action denied: {decision.reason}")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Backward Compatibility
|
|
82
|
+
|
|
83
|
+
Existing code using `janus` imports continues to work:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from janus import JanusClient # Still works!
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Guard Pattern (SDK 0.5.0+)
|
|
90
|
+
|
|
91
|
+
For actions requiring human approval, use the idempotent guard pattern:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from haltstate import AsyncHaltStateClient, ActionPending, ActionRejected
|
|
95
|
+
|
|
96
|
+
async def process_high_value_payment(invoice_id: str, amount: float):
|
|
97
|
+
client = AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx")
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
async with client.guard(
|
|
101
|
+
action="payment.process",
|
|
102
|
+
agent_id="payment-bot",
|
|
103
|
+
params={"invoice_id": invoice_id, "amount": amount},
|
|
104
|
+
idempotency_key=f"payment-{invoice_id}", # Retry-safe
|
|
105
|
+
timeout_seconds=300
|
|
106
|
+
) as permit:
|
|
107
|
+
# Only executes after human approval
|
|
108
|
+
result = await execute_payment(amount)
|
|
109
|
+
print(f"Approved by {permit.approver} at {permit.approved_at}")
|
|
110
|
+
return result
|
|
111
|
+
|
|
112
|
+
except ActionPending:
|
|
113
|
+
print("Awaiting human approval...")
|
|
114
|
+
return {"status": "pending"}
|
|
115
|
+
|
|
116
|
+
except ActionRejected as e:
|
|
117
|
+
print(f"Rejected by {e.rejected_by}: {e.reason}")
|
|
118
|
+
raise
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Key features:
|
|
122
|
+
- **Idempotency keys**: Same key = same approval request, safe for retries
|
|
123
|
+
- **Process restart safety**: Approved actions can be executed after restart
|
|
124
|
+
- **Audit trail**: Full record of who approved and when
|
|
125
|
+
|
|
126
|
+
## Decorators
|
|
127
|
+
```python
|
|
128
|
+
from haltstate import HaltStateClient, haltstate_guard
|
|
129
|
+
|
|
130
|
+
client = HaltStateClient(tenant_id="acme", api_key="janus_xxx")
|
|
131
|
+
|
|
132
|
+
@haltstate_guard(client, action="email.send", agent_id="email-bot")
|
|
133
|
+
def send_email(to, subject, body):
|
|
134
|
+
return mailer.send(to, subject, body)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Async
|
|
138
|
+
```python
|
|
139
|
+
from haltstate import AsyncHaltStateClient
|
|
140
|
+
|
|
141
|
+
async def main():
|
|
142
|
+
async with AsyncHaltStateClient(tenant_id="acme", api_key="janus_xxx") as client:
|
|
143
|
+
res = await client.check("database.drop", params={"table": "users"})
|
|
144
|
+
if res.allowed:
|
|
145
|
+
await client.report(res, status="success", action="database.drop", agent_id="ops-bot")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Exceptions
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from haltstate import (
|
|
152
|
+
HaltStateError, # Base error
|
|
153
|
+
HaltStateAuthError, # Invalid API key
|
|
154
|
+
HaltStateConnectionError, # Network/timeout
|
|
155
|
+
ActionPending, # Awaiting approval (guard pattern)
|
|
156
|
+
ActionRejected, # Human rejected (guard pattern)
|
|
157
|
+
ActionTimeout, # Approval expired (guard pattern)
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Docs
|
|
162
|
+
|
|
163
|
+
Full documentation at [haltstate.ai/docs](https://haltstate.ai/docs):
|
|
164
|
+
- Quickstart - 5-minute setup
|
|
165
|
+
- Guard Pattern - HITL approval flow
|
|
166
|
+
- API Reference - All methods
|
|
167
|
+
- Error Handling - Exception handling
|
|
168
|
+
- SB-53 Compliance - Regulatory mapping
|
|
169
|
+
|
|
170
|
+
## Migration from janus-sdk
|
|
171
|
+
|
|
172
|
+
If upgrading from `janus-sdk`:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# Old (still works)
|
|
176
|
+
from janus import JanusClient, janus_guard
|
|
177
|
+
|
|
178
|
+
# New
|
|
179
|
+
from haltstate import HaltStateClient, haltstate_guard
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Both import styles work - no code changes required for existing users.
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
haltstate/__init__.py
|
|
5
|
+
haltstate_sdk.egg-info/PKG-INFO
|
|
6
|
+
haltstate_sdk.egg-info/SOURCES.txt
|
|
7
|
+
haltstate_sdk.egg-info/dependency_links.txt
|
|
8
|
+
haltstate_sdk.egg-info/requires.txt
|
|
9
|
+
haltstate_sdk.egg-info/top_level.txt
|
|
10
|
+
janus/__init__.py
|
|
11
|
+
janus/async_client.py
|
|
12
|
+
janus/client.py
|
|
13
|
+
janus/decorators.py
|
|
14
|
+
janus/exceptions.py
|
|
15
|
+
janus/models.py
|
|
16
|
+
tests/test_client.py
|
|
17
|
+
tests/test_import.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
httpx>=0.24
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from .client import JanusClient, Permit
|
|
2
|
+
from .async_client import AsyncJanusClient
|
|
3
|
+
from .models import CheckResult, Decision, ApprovalDecision, ApprovalStatus
|
|
4
|
+
from .decorators import janus_guard, openai_guard
|
|
5
|
+
from .exceptions import (
|
|
6
|
+
JanusError,
|
|
7
|
+
JanusConnectionError,
|
|
8
|
+
JanusAuthError,
|
|
9
|
+
JanusRateLimitError,
|
|
10
|
+
JanusApprovalTimeoutError,
|
|
11
|
+
ApprovalPending,
|
|
12
|
+
ActionDenied,
|
|
13
|
+
ActionExpired,
|
|
14
|
+
KillSwitchTriggered,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
# Clients
|
|
19
|
+
"JanusClient",
|
|
20
|
+
"AsyncJanusClient",
|
|
21
|
+
# Models
|
|
22
|
+
"CheckResult",
|
|
23
|
+
"Decision",
|
|
24
|
+
"ApprovalDecision",
|
|
25
|
+
"ApprovalStatus",
|
|
26
|
+
"Permit",
|
|
27
|
+
# Decorators
|
|
28
|
+
"janus_guard",
|
|
29
|
+
"openai_guard",
|
|
30
|
+
# Exceptions
|
|
31
|
+
"JanusError",
|
|
32
|
+
"JanusConnectionError",
|
|
33
|
+
"JanusAuthError",
|
|
34
|
+
"JanusRateLimitError",
|
|
35
|
+
"JanusApprovalTimeoutError",
|
|
36
|
+
# Guard pattern exceptions (control flow)
|
|
37
|
+
"ApprovalPending",
|
|
38
|
+
"ActionDenied",
|
|
39
|
+
"ActionExpired",
|
|
40
|
+
"KillSwitchTriggered",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
__version__ = "0.5.0" # Idempotent Guard pattern for autonomous agents
|