action-sentinel 0.2.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.
Files changed (85) hide show
  1. action_sentinel-0.2.0/LICENSE +202 -0
  2. action_sentinel-0.2.0/MANIFEST.in +5 -0
  3. action_sentinel-0.2.0/PKG-INFO +384 -0
  4. action_sentinel-0.2.0/README.md +338 -0
  5. action_sentinel-0.2.0/action_sentinel/__init__.py +3 -0
  6. action_sentinel-0.2.0/action_sentinel/__main__.py +3 -0
  7. action_sentinel-0.2.0/action_sentinel/api/__init__.py +3 -0
  8. action_sentinel-0.2.0/action_sentinel/api/app.py +309 -0
  9. action_sentinel-0.2.0/action_sentinel/audit.py +72 -0
  10. action_sentinel-0.2.0/action_sentinel/cli.py +607 -0
  11. action_sentinel-0.2.0/action_sentinel/config.py +117 -0
  12. action_sentinel-0.2.0/action_sentinel/contracts/__init__.py +36 -0
  13. action_sentinel-0.2.0/action_sentinel/contracts/actions.py +86 -0
  14. action_sentinel-0.2.0/action_sentinel/contracts/audit.py +24 -0
  15. action_sentinel-0.2.0/action_sentinel/contracts/common.py +84 -0
  16. action_sentinel-0.2.0/action_sentinel/contracts/decisions.py +268 -0
  17. action_sentinel-0.2.0/action_sentinel/contracts/evaluation.py +80 -0
  18. action_sentinel-0.2.0/action_sentinel/contracts/execution.py +51 -0
  19. action_sentinel-0.2.0/action_sentinel/contracts/review.py +74 -0
  20. action_sentinel-0.2.0/action_sentinel/dashboard/app.py +389 -0
  21. action_sentinel-0.2.0/action_sentinel/demo.py +215 -0
  22. action_sentinel-0.2.0/action_sentinel/disagreement.py +81 -0
  23. action_sentinel-0.2.0/action_sentinel/evaluation/__init__.py +6 -0
  24. action_sentinel-0.2.0/action_sentinel/evaluation/datasets.py +44 -0
  25. action_sentinel-0.2.0/action_sentinel/evaluation/lab.py +265 -0
  26. action_sentinel-0.2.0/action_sentinel/evaluation/metrics.py +122 -0
  27. action_sentinel-0.2.0/action_sentinel/evaluation/report.py +106 -0
  28. action_sentinel-0.2.0/action_sentinel/execution/__init__.py +5 -0
  29. action_sentinel-0.2.0/action_sentinel/execution/authorization.py +76 -0
  30. action_sentinel-0.2.0/action_sentinel/execution/executor.py +176 -0
  31. action_sentinel-0.2.0/action_sentinel/governance/__init__.py +13 -0
  32. action_sentinel-0.2.0/action_sentinel/governance/policy.py +154 -0
  33. action_sentinel-0.2.0/action_sentinel/governance/review.py +127 -0
  34. action_sentinel-0.2.0/action_sentinel/guard.py +400 -0
  35. action_sentinel-0.2.0/action_sentinel/providers/__init__.py +13 -0
  36. action_sentinel-0.2.0/action_sentinel/providers/base.py +142 -0
  37. action_sentinel-0.2.0/action_sentinel/providers/mock.py +62 -0
  38. action_sentinel-0.2.0/action_sentinel/providers/ollama.py +126 -0
  39. action_sentinel-0.2.0/action_sentinel/providers/registry.py +144 -0
  40. action_sentinel-0.2.0/action_sentinel/providers/rule_based.py +65 -0
  41. action_sentinel-0.2.0/action_sentinel/providers/runner.py +71 -0
  42. action_sentinel-0.2.0/action_sentinel/providers/vegaml_provider.py +229 -0
  43. action_sentinel-0.2.0/action_sentinel/remote.py +120 -0
  44. action_sentinel-0.2.0/action_sentinel/resources.py +65 -0
  45. action_sentinel-0.2.0/action_sentinel/service.py +396 -0
  46. action_sentinel-0.2.0/action_sentinel/storage/__init__.py +4 -0
  47. action_sentinel-0.2.0/action_sentinel/storage/base.py +50 -0
  48. action_sentinel-0.2.0/action_sentinel/storage/sqlite.py +229 -0
  49. action_sentinel-0.2.0/action_sentinel/uncertainty.py +97 -0
  50. action_sentinel-0.2.0/action_sentinel/validation/__init__.py +16 -0
  51. action_sentinel-0.2.0/action_sentinel/validation/engine.py +206 -0
  52. action_sentinel-0.2.0/action_sentinel/validation/grammar.py +210 -0
  53. action_sentinel-0.2.0/action_sentinel/validation/packs.py +229 -0
  54. action_sentinel-0.2.0/action_sentinel/vegalab/__init__.py +1 -0
  55. action_sentinel-0.2.0/action_sentinel/vegalab/analysis.py +190 -0
  56. action_sentinel-0.2.0/action_sentinel/vegalab/api.py +60 -0
  57. action_sentinel-0.2.0/action_sentinel/vegalab/contracts.py +214 -0
  58. action_sentinel-0.2.0/action_sentinel/vegalab/datasets.py +379 -0
  59. action_sentinel-0.2.0/action_sentinel/vegalab/experiment.py +82 -0
  60. action_sentinel-0.2.0/action_sentinel/vegalab/heads.py +95 -0
  61. action_sentinel-0.2.0/action_sentinel/vegalab/report.py +125 -0
  62. action_sentinel-0.2.0/action_sentinel/vegalab/runner.py +147 -0
  63. action_sentinel-0.2.0/action_sentinel/vegalab/service.py +86 -0
  64. action_sentinel-0.2.0/action_sentinel/vegalab/systems.py +270 -0
  65. action_sentinel-0.2.0/action_sentinel/vegalab/tasks.py +137 -0
  66. action_sentinel-0.2.0/action_sentinel/vegalab/testing.py +100 -0
  67. action_sentinel-0.2.0/action_sentinel/vegalab/vega_core.py +362 -0
  68. action_sentinel-0.2.0/action_sentinel.egg-info/PKG-INFO +384 -0
  69. action_sentinel-0.2.0/action_sentinel.egg-info/SOURCES.txt +83 -0
  70. action_sentinel-0.2.0/action_sentinel.egg-info/dependency_links.txt +1 -0
  71. action_sentinel-0.2.0/action_sentinel.egg-info/entry_points.txt +2 -0
  72. action_sentinel-0.2.0/action_sentinel.egg-info/requires.txt +22 -0
  73. action_sentinel-0.2.0/action_sentinel.egg-info/top_level.txt +1 -0
  74. action_sentinel-0.2.0/config/sentinel-vegaml.yaml +66 -0
  75. action_sentinel-0.2.0/config/sentinel.yaml +57 -0
  76. action_sentinel-0.2.0/examples/evaluation_datasets/sentinel_synthetic_v1.jsonl +86 -0
  77. action_sentinel-0.2.0/examples/rule_packs/agent_tasks.yaml +22 -0
  78. action_sentinel-0.2.0/examples/rule_packs/classifier.yaml +32 -0
  79. action_sentinel-0.2.0/examples/rule_packs/core.yaml +192 -0
  80. action_sentinel-0.2.0/examples/sample_actions/actions.jsonl +6 -0
  81. action_sentinel-0.2.0/examples/sample_actions/my_action.json +17 -0
  82. action_sentinel-0.2.0/examples/sample_actions/one.json +26 -0
  83. action_sentinel-0.2.0/pyproject.toml +73 -0
  84. action_sentinel-0.2.0/setup.cfg +4 -0
  85. action_sentinel-0.2.0/setup.py +31 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ # The source distribution carries the files setup.py bundles into the wheel.
2
+ include config/*.yaml
3
+ include examples/rule_packs/*.yaml
4
+ include examples/evaluation_datasets/*.jsonl
5
+ include examples/sample_actions/*.json*
@@ -0,0 +1,384 @@
1
+ Metadata-Version: 2.4
2
+ Name: action-sentinel
3
+ Version: 0.2.0
4
+ Summary: VegaML-powered safety checkpoint for AI agent actions: model risk judgement under deterministic governance.
5
+ Author: Prem Kumar
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/premm25/action-sentinel
8
+ Project-URL: Documentation, https://github.com/premm25/action-sentinel/tree/main/docs
9
+ Project-URL: Changelog, https://github.com/premm25/action-sentinel/blob/main/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/premm25/action-sentinel/issues
11
+ Keywords: ai-agents,agent-safety,guardrails,governance,human-in-the-loop,vegaml,llm
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Security
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: pydantic>=2.7
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: httpx>=0.27
30
+ Provides-Extra: api
31
+ Requires-Dist: fastapi>=0.110; extra == "api"
32
+ Requires-Dist: uvicorn>=0.27; extra == "api"
33
+ Provides-Extra: dashboard
34
+ Requires-Dist: streamlit>=1.35; extra == "dashboard"
35
+ Requires-Dist: pandas>=2.0; extra == "dashboard"
36
+ Provides-Extra: vegaml
37
+ Requires-Dist: vegaml<0.10,>=0.9; extra == "vegaml"
38
+ Provides-Extra: dev
39
+ Requires-Dist: pytest>=8.0; extra == "dev"
40
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
41
+ Requires-Dist: ruff>=0.6; extra == "dev"
42
+ Requires-Dist: fastapi>=0.110; extra == "dev"
43
+ Requires-Dist: uvicorn>=0.27; extra == "dev"
44
+ Requires-Dist: streamlit>=1.35; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ # Action Sentinel
48
+
49
+ [![CI](https://github.com/premm25/action-sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/premm25/action-sentinel/actions/workflows/ci.yml) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/premm25/action-sentinel/blob/main/LICENSE)
50
+
51
+ **A VegaML-powered safety checkpoint between AI agents and the real world.** Before an agent restarts
52
+ a server, refunds a payment or deletes a database, [VegaML](https://github.com/NandhaKishorM/vegaml) judges
53
+ the risk, Sentinel's rules and governance decide whether it may run, and it can only run with an
54
+ authorization token issued for that exact action.
55
+
56
+ ```
57
+ agent proposes action ──► Sentinel ──► APPROVE → signed token → executor runs it (exactly once)
58
+ ├─► HUMAN_REVIEW → a person approves, rejects or edits it
59
+ ├─► BLOCK (policy forbids it, whatever any model says)
60
+ ├─► ABSTAIN (not enough confidence to recommend anything)
61
+ └─► ERROR (evaluation failed; never treated as approval)
62
+ ```
63
+
64
+ ## Why
65
+
66
+ Agents built on LLMs are increasingly given real tools. The usual safeguard is a model judging
67
+ whether an action is safe, but models are confidently wrong, and their confidence is rarely
68
+ calibrated. Sentinel is built on a few non-negotiable rules:
69
+
70
+ - **Deterministic policy wins.** A rule that blocks an action can't be outvoted, out-scored or
71
+ overridden by a model.
72
+ - **Models can only escalate.** High confidence never authorizes anything on its own.
73
+ - **Uncertainty is explicit.** Missing confidence, unknown calibration, abstention and provider
74
+ failure are first-class states, not defaults.
75
+ - **Humans are in the loop, but checked too.** Reviewer authority levels, no self-review, and every
76
+ approval or edit is re-validated against the current policy.
77
+ - **Authorization is bound to the exact payload.** Change one field and the token is useless.
78
+ Replays execute once.
79
+ - **Everything is auditable**, and the pipeline is measurable with a built-in evaluation lab.
80
+
81
+ ## VegaML: the risk model
82
+
83
+ VegaML reads each proposed action with a frozen Qwen3.5 backbone, and a few-shot head fitted on labelled
84
+ actions rates it safe, needs review or unsafe. Sentinel treats that rating as evidence, not permission.
85
+
86
+ | on AgentHarm (352 real requests, CPU, 0.8B) | result |
87
+ |---|---|
88
+ | VegaML head accuracy (fitted on 64 examples) | **0.841**, AUROC 0.920 |
89
+ | harmful requests approved, head alone | 24 of 176 |
90
+ | harmful requests approved, **head behind Sentinel** | **0 of 176** |
91
+ | benign requests auto-approved behind Sentinel | 95 of 176 (the rest went to human review) |
92
+
93
+ ```bash
94
+ pip install -e ".[api,vegaml]"
95
+ action-sentinel vega fit --dataset my_actions.jsonl --out heads/my_actions.npz # fit on your actions
96
+ action-sentinel --config config/sentinel-vegaml.yaml serve # rules + VegaML, warmed up
97
+ ```
98
+
99
+ Setup, fitting and operating notes: [`docs/VEGAML.md`](https://github.com/premm25/action-sentinel/blob/main/docs/VEGAML.md). The method and every number:
100
+ [`docs/vegalab/`](https://github.com/premm25/action-sentinel/blob/main/docs/vegalab/RESULTS.md). Without VegaML installed, the default profile runs on the
101
+ rules alone, offline.
102
+
103
+ ## 30-second example
104
+
105
+ ```bash
106
+ pip install -e ".[dev,dashboard]" # from a clone of this repository
107
+ action-sentinel demo # offline end-to-end walkthrough, no model or API key needed
108
+ ```
109
+
110
+ ```python
111
+ from action_sentinel.config import load_settings
112
+ from action_sentinel.contracts import ActionProposal
113
+ from action_sentinel.service import Sentinel
114
+
115
+ sentinel = Sentinel(load_settings()) # config/sentinel.yaml: rule pack + rule-based provider
116
+
117
+ action = ActionProposal.model_validate({
118
+ "event_id": "evt-42", "task_id": "t-1", "agent_id": "ops-agent", "agent_version": "1.0",
119
+ "source_system": "infra-agent", "action_type": "delete_database",
120
+ "target_resource": "prod/orders", "action_payload": {"database": "orders"},
121
+ "evidence_refs": [], "proposed_at": "2026-10-14T10:00:00+00:00", "idempotency_key": "evt-42",
122
+ })
123
+ result = sentinel.evaluate(action)
124
+ print(result.decision.status.value, result.decision.reason_codes)
125
+ # BLOCK ['HARD_POLICY_VIOLATION', 'EVIDENCE_INSUFFICIENT', 'RULE_PROD_DATABASE_DELETE']
126
+ ```
127
+
128
+ An approved action returns `result.authorization.token`. The executor accepts only that token
129
+ together with the identical action: `sentinel.execute(token, action)`.
130
+
131
+ ## How it differs from related tools
132
+
133
+ | | Sentinel | LLM output guardrails | general policy engines |
134
+ |---|---|---|---|
135
+ | Guards | **actions** (tool calls) before execution | model text / structured output | any request, given policy input |
136
+ | Model-based judgement | VegaML few-shot head (or any provider); can only escalate | often central | none |
137
+ | Uncertainty, abstention, disagreement | explicit outcomes | varies | n/a |
138
+ | Human review workflow with re-validation | built in | generally not | not built in |
139
+ | Execution token bound to the exact payload, idempotent | built in | no | no |
140
+ | Evaluation of the governance pipeline | built in (Confidence Lab) | varies | no |
141
+
142
+ Sentinel complements these tools rather than replacing them: a policy engine can feed it rules,
143
+ and an output guardrail can still check what the agent says.
144
+
145
+ > **Status:** working prototype, 0.1.0. 279 automated tests, CI on Linux and Windows (Python
146
+ > 3.10–3.14), offline demo. It is
147
+ > **not production-ready** yet; see [Known limitations](#known-limitations) and the
148
+ > [roadmap](#roadmap). Contributions are welcome: see [CONTRIBUTING.md](https://github.com/premm25/action-sentinel/blob/main/CONTRIBUTING.md).
149
+
150
+ ## Architecture
151
+
152
+ ```
153
+ ActionProposal ─► ValidationEngine (rule packs) ──────────────┐ hard violation ⇒ BLOCK, always
154
+ └► ProviderRunner ─► rules | vegaml-head | vegaml | ollama | mock
155
+ │ (single / sequential / parallel, enforced timeout)
156
+ ▼
157
+ UncertaintyEvaluator + DisagreementDetector
158
+ ▼
159
+ GovernanceEngine (fixed precedence) ─► GovernanceDecision
160
+ │ APPROVE │ HUMAN_REVIEW
161
+ ▼ ▼
162
+ AuthorizationGrant ◄── ReviewManager (approve / reject / override → re-validate)
163
+ ▼
164
+ ExecutionGateway (re-checks everything) ─► MockExecutionAdapter
165
+ every step ─► AuditLogger ─► SQLiteStore ─► sanitized JSONL export
166
+ ```
167
+
168
+ Details: [`docs/architecture/ARCHITECTURE.md`](https://github.com/premm25/action-sentinel/blob/main/docs/architecture/ARCHITECTURE.md).
169
+
170
+ ## Prerequisites
171
+
172
+ - Python 3.10 or newer. Developed and tested on 3.14.6 on Windows 11.
173
+ - Optional: [Ollama](https://ollama.com) with a pulled model (default `llama3.1:8b`) for the LLM provider.
174
+ - Optional: `pip install vegaml` (pulls torch and transformers, about 1.8 GB of weights on first use) for the VegaML provider.
175
+
176
+ ## Installation
177
+
178
+ From PyPI, into your own project (no clone needed; the settings profiles, rule packs and dataset ship with the package):
179
+
180
+ ```bash
181
+ pip install "action-sentinel[api]" # add ,vegaml for VegaML; latest main: "action-sentinel[api] @ git+https://github.com/premm25/action-sentinel.git"
182
+ action-sentinel demo # works from any directory
183
+ action-sentinel init # copies config/ and examples/rule_packs/ here, to edit for your agent
184
+ ```
185
+
186
+ Relative paths in settings resolve against your project first and fall back to the shipped files, so
187
+ `examples/rule_packs/core.yaml` works before and after `init`.
188
+
189
+ For development on Sentinel itself:
190
+
191
+ ```bash
192
+ python -m venv .venv
193
+ .venv/Scripts/activate # Windows; on Linux/macOS: source .venv/bin/activate
194
+ pip install -e ".[dev,dashboard]"
195
+ ```
196
+
197
+ ## Configuration
198
+
199
+ `config/sentinel.yaml` holds the rule packs, providers, active providers, evaluation strategy,
200
+ governance thresholds, reviewers and API principals. Environment overrides are listed in
201
+ [`.env.example`](https://github.com/premm25/action-sentinel/blob/main/.env.example): `SENTINEL_CONFIG`, `SENTINEL_DB_PATH`, `SENTINEL_ENV` and
202
+ `SENTINEL_SIGNING_KEY`.
203
+
204
+ By default only the deterministic `rules` provider is active, so evaluation works without any model.
205
+ To also consult the local LLM, set `active_providers: [rules, ollama]`, or pass
206
+ `--providers rules,ollama` on the CLI.
207
+
208
+ **Development API keys.** These are public, intended for local use only, and stored in the config as SHA-256 hashes.
209
+
210
+ | key | principal | roles |
211
+ |---|---|---|
212
+ | `dev-agent-key` | ops-agent | agent |
213
+ | `dev-operator-key` | olivia | reviewer (operator), auditor |
214
+ | `dev-senior-key` | sam | reviewer (senior), auditor, evaluator |
215
+ | `dev-admin-key` | ada | admin |
216
+ | `dev-auditor-key` | auditor | auditor |
217
+
218
+ ## Quick start
219
+
220
+ ```bash
221
+ action-sentinel validate-rules # check the rule packs
222
+ action-sentinel providers # provider health
223
+ action-sentinel evaluate examples/sample_actions/actions.jsonl -v
224
+ action-sentinel reviews list
225
+ action-sentinel reviews approve <review_id> --reviewer olivia --reason "verified"
226
+ action-sentinel demo # full offline end-to-end demonstration
227
+ ```
228
+
229
+ `python -m action_sentinel ...` works the same as `action-sentinel ...`.
230
+
231
+ ## API
232
+
233
+ ```bash
234
+ action-sentinel serve --port 8000 # interactive docs at http://127.0.0.1:8000/docs
235
+ curl -s -X POST http://127.0.0.1:8000/decisions/evaluate -H "X-API-Key: dev-agent-key" \
236
+ -H "Content-Type: application/json" -d @examples/sample_actions/one.json
237
+ ```
238
+
239
+ Endpoints:
240
+ - `GET /health`, `GET /providers`
241
+ - `POST /decisions/evaluate`, `POST /decisions/assess` (shadow: nothing stored), `GET /decisions`,
242
+ `GET /decisions/{id}`, `GET /decisions/{id}/events`, `POST /shadow-records`
243
+ - `GET /reviews/pending`, `GET /reviews/{id}`, `POST /reviews/{id}/approve|reject|override`
244
+ - `POST /executions` (Sentinel's adapter runs the action), or `POST /executions/begin` and
245
+ `POST /executions/{id}/finish` (the agent runs it, as the remote guard does); `POST /authorizations/{id}/revoke`
246
+ - `POST /evaluations/run`, `GET /evaluations`, `GET /evaluations/{run_id}`, `GET /evaluations/{run_id}/report`
247
+
248
+ ## Dashboard
249
+
250
+ ```bash
251
+ action-sentinel dashboard # http://127.0.0.1:8501
252
+ action-sentinel demo --db var/sentinel.db # optional: populate the default database first
253
+ ```
254
+
255
+ The dashboard has six tabs: Overview, Decision Explorer, Confidence Lab, Human Review, Audit
256
+ Explorer and Configuration. It reads the same SQLite database as the API and CLI. Review actions
257
+ require the reviewer's API key.
258
+
259
+ ## Testing
260
+
261
+ ```bash
262
+ pytest # 203 tests, offline (optional live tests are deselected)
263
+ pytest --cov=action_sentinel # with coverage
264
+ pytest -m ollama # optional: live test against a running Ollama
265
+ ```
266
+
267
+ ## Guarding tool functions
268
+
269
+ Wrap an agent's tools with a decorator instead of building proposals by hand. Shadow mode records
270
+ what Sentinel would have done while changing nothing; enforce mode runs the tool only after the
271
+ execution gateway clears it. Sync and `async def` tools both work, and Sentinel can run in the agent's
272
+ process or as a separate service (`RemoteSentinel`). See [`docs/GUARD.md`](https://github.com/premm25/action-sentinel/blob/main/docs/GUARD.md).
273
+
274
+ ```python
275
+ guard = Guard(sentinel, agent_id="ops-agent", agent_version="1.4.0", source_system="infra-agent", mode="shadow")
276
+
277
+ @guard.tool("restart_service", target=lambda a: "staging/%s" % a["service"])
278
+ def restart_service(service: str, reason: str): ...
279
+ ```
280
+
281
+ ## Evaluation (Confidence Lab)
282
+
283
+ ```bash
284
+ python scripts/build_dataset.py # regenerate the synthetic dataset (deterministic)
285
+ action-sentinel lab suite # offline: rules + simulated providers, test split
286
+ action-sentinel lab suite --model ollama --second "" # live local LLM (slow on CPU)
287
+ action-sentinel lab run --providers rules,ollama --splits test
288
+ action-sentinel lab calibrate --provider ollama # ECE on the calibration split
289
+ action-sentinel lab show [run_id] / action-sentinel lab export <run_id...> --out report.md
290
+ ```
291
+
292
+ Measured results and their limits are in [`docs/evaluation/RESULTS.md`](https://github.com/premm25/action-sentinel/blob/main/docs/evaluation/RESULTS.md).
293
+ The method is in [`docs/evaluation/METHODOLOGY.md`](https://github.com/premm25/action-sentinel/blob/main/docs/evaluation/METHODOLOGY.md).
294
+
295
+ ## Vega Decision Intelligence Lab (VegaML)
296
+
297
+ `action_sentinel/vegalab/` makes [VegaML](https://github.com/NandhaKishorM/vegaml) the primary decision
298
+ engine and measures it. VegaML is a typed-decision model: a frozen Qwen3.5 language model reads the
299
+ situation, and a small trained physics engine settles on one of the candidate answers, returning calibrated
300
+ probabilities, a conformal prediction set, an abstain flag and an "unbound" (out-of-distribution) flag.
301
+ It generates no text.
302
+
303
+ - **Real inference, verified** with `vegaml` 0.9.0, the 0.8B checkpoint on CPU. The lab wraps VegaML's own
304
+ API and never reimplements its engine. See [`docs/VEGA_MIGRATION.md`](https://github.com/premm25/action-sentinel/blob/main/docs/VEGA_MIGRATION.md).
305
+ - **Typed decision service:** a Python `VegaCore` and `/vega/*` API routes, enabled with `vegalab.enabled`.
306
+ - **Confidence Lab v2:** public-task datasets with provenance and leakage checks; VegaML (adapters off and
307
+ auto) vs the same frozen backbone used as a plain LM vs a majority baseline; accuracy, calibration,
308
+ abstention, conformal coverage, paired confidence intervals.
309
+ - **Sentinel integration:** VegaML as a governance provider: `vegaml-head` (the few-shot head, used by
310
+ `config/sentinel-vegaml.yaml`), and `vegaml-off` / `vegaml-auto` (the engine). Hard rules still win.
311
+ - **Heads you fit yourself:** `action-sentinel vega fit` fits the head on your labelled actions (never on the
312
+ test split) and saves it. The provider serves it only for the question, framing and checkpoint it was
313
+ fitted for.
314
+
315
+ VegaML needs torch (about 3.5 GB RAM for 0.8B on CPU), so it is best installed in its own environment:
316
+
317
+ ```bash
318
+ python -m venv ~/.venvs/vega-lab
319
+ ~/.venvs/vega-lab/Scripts/pip install "vegaml==0.9.0" "transformers==5.19.0" torch pyarrow -e ".[dev]"
320
+ action-sentinel vega check --load # downloads ~1.8 GB on first use
321
+ action-sentinel vega decide --adapters off --instructions "Which team?" \
322
+ --state "Invoice overdue, third notice" --option "billing=payments" --option "technical=faults"
323
+ action-sentinel vega data check # dataset quality and leakage checks
324
+ action-sentinel vega run --limit 20 # inference (resumable) -> reports/vegalab/<run>
325
+ action-sentinel vega analyze reports/vegalab/<run> # metrics.json, summary.csv, REPORT.md
326
+ action-sentinel vega failures reports/vegalab/<run> --kind confident-wrong
327
+ ```
328
+
329
+ GPU runs (0.8B and 4B, 500 test examples per task): [`notebooks/vegalab_kaggle_gpu.ipynb`](https://github.com/premm25/action-sentinel/blob/main/notebooks/vegalab_kaggle_gpu.ipynb).
330
+ Documents: [architecture](https://github.com/premm25/action-sentinel/blob/main/docs/vegalab/ARCHITECTURE.md) · [datasets](https://github.com/premm25/action-sentinel/blob/main/docs/vegalab/DATASETS.md) ·
331
+ [methodology](https://github.com/premm25/action-sentinel/blob/main/docs/vegalab/METHODOLOGY.md) · [results](https://github.com/premm25/action-sentinel/blob/main/docs/vegalab/RESULTS.md).
332
+
333
+ ## Demo
334
+
335
+ ```bash
336
+ action-sentinel demo
337
+ ```
338
+
339
+ The demo runs 12 steps offline and checks the expected result of each one. It exits non-zero if
340
+ any check fails. See [`docs/DEMO_GUIDE.md`](https://github.com/premm25/action-sentinel/blob/main/docs/DEMO_GUIDE.md).
341
+
342
+ ## Known limitations
343
+
344
+ - Single-process SQLite storage, with no high availability, replication or retention management.
345
+ - The authentication in the dev configuration uses publicly known keys. There is no TLS, OAuth,
346
+ rate limiting or key rotation.
347
+ - If `SENTINEL_SIGNING_KEY` is unset, each process generates its own key, so a token issued by the
348
+ API can't be executed through the CLI.
349
+ - The Confidence Lab dataset is synthetic (86 examples, 44 in the test split). Its expected outcomes
350
+ were written against the same reference policy that the rules enforce, so the rules-only score
351
+ is circular.
352
+ - The local LLM (`llama3.1:8b`, CPU) was measured at 0.41 accuracy on the test split, and it never
353
+ chose `unsafe`. On its own it is not a useful classifier for this task as prompted.
354
+ - VegaML results are single CPU runs with the 0.8B checkpoint; there are no GPU or 4B results yet.
355
+ - The mock executor changes nothing real. A real adapter would also need compensation, dry-run and
356
+ scoping controls.
357
+
358
+ ## Roadmap
359
+
360
+ 1. An MCP proxy, so existing agents can be protected without rewiring. The `@guard` decorator is done,
361
+ in-process and remote, for sync and async tools ([`docs/GUARD.md`](https://github.com/premm25/action-sentinel/blob/main/docs/GUARD.md)).
362
+ 2. PyPI package and Docker image.
363
+ 3. A stronger VegaML layer: heads fitted on real labelled agent traffic, GPU and 4B results, automatic
364
+ calibration profiles.
365
+ 4. A public, independently labelled benchmark of risky agent actions, plus a reusable policy library.
366
+ 5. Production hardening: Postgres storage, managed signing keys, OIDC, tamper-evident audit, review notifications.
367
+
368
+ ## Documents
369
+
370
+ - [Architecture](https://github.com/premm25/action-sentinel/blob/main/docs/architecture/ARCHITECTURE.md)
371
+ - [Threat model](https://github.com/premm25/action-sentinel/blob/main/docs/architecture/THREAT_MODEL.md)
372
+ - [Architecture decisions](https://github.com/premm25/action-sentinel/blob/main/docs/decisions/ARCHITECTURE_DECISIONS.md)
373
+ - [Evaluation methodology](https://github.com/premm25/action-sentinel/blob/main/docs/evaluation/METHODOLOGY.md)
374
+ - [Evaluation results](https://github.com/premm25/action-sentinel/blob/main/docs/evaluation/RESULTS.md)
375
+ - [Security](https://github.com/premm25/action-sentinel/blob/main/docs/security/SECURITY.md)
376
+ - [Runbook](https://github.com/premm25/action-sentinel/blob/main/docs/operations/RUNBOOK.md)
377
+ - [Demo guide](https://github.com/premm25/action-sentinel/blob/main/docs/DEMO_GUIDE.md)
378
+ - [Guarding tool functions](https://github.com/premm25/action-sentinel/blob/main/docs/GUARD.md)
379
+ - [Running with VegaML](https://github.com/premm25/action-sentinel/blob/main/docs/VEGAML.md)
380
+ - [Contributing](https://github.com/premm25/action-sentinel/blob/main/CONTRIBUTING.md) · [Security policy](https://github.com/premm25/action-sentinel/blob/main/SECURITY.md) · [Changelog](https://github.com/premm25/action-sentinel/blob/main/CHANGELOG.md)
381
+
382
+ ## License
383
+
384
+ Apache License 2.0. See [LICENSE](https://github.com/premm25/action-sentinel/blob/main/LICENSE).