claude-verified-agent 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shenn667
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,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: claude-verified-agent
3
+ Version: 0.2.0
4
+ Summary: End-to-end verified agent demo: inter-agent memory (agent-context-bridge) + cited-or-refused RAG (cited-rag) + CI safety gates (llm-eval-ci). Stdlib only, offline, no API key.
5
+ Author-email: shenn667 <lehdev@yandex.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/shenn667/claude-verified-agent
8
+ Keywords: agents,rag,citations,evals,offline,claude
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
19
+ Provides-Extra: pillars
20
+ Requires-Dist: agent-context-bridge>=0.4.0; extra == "pillars"
21
+ Requires-Dist: cited-rag>=0.2.0; extra == "pillars"
22
+ Requires-Dist: llm-eval-ci>=0.2.0; extra == "pillars"
23
+ Dynamic: license-file
24
+
25
+ # claude-verified-agent
26
+
27
+ [![CI](https://github.com/shenn667/claude-verified-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/shenn667/claude-verified-agent/actions/workflows/ci.yml)
28
+ [![PyPI](https://img.shields.io/pypi/v/claude-verified-agent.svg)](https://pypi.org/project/claude-verified-agent/)
29
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/downloads/)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
31
+ [![offline](https://img.shields.io/badge/offline-stdlib--only-lightgrey.svg)](https://github.com/shenn667/claude-verified-agent)
32
+
33
+ **An end-to-end verified agent: every answer is cited or refused, every
34
+ delivery passes safety gates, every run is CI-blocked on regression.**
35
+
36
+ No hallucination by design, no PII/injection leak by gate, no silent
37
+ regression by suite. Stdlib-only core, fully offline, no API key.
38
+
39
+ ```bash
40
+ pip install -e .
41
+ make demo # 1 command: cited answer + refusal + gate verdicts
42
+ make banking-demo # banking & SecOps vertical: 4 asserted offline cases
43
+ make test # 48 contract tests (pytest, offline)
44
+ make gates # 4 llm-eval-ci suites, exit != 0 blocks CI
45
+ ```
46
+
47
+ ## Architecture
48
+
49
+ ```text
50
+ question
51
+ |
52
+ v
53
+ [1] record-contexte (agent-context-bridge)
54
+ | acb record question + answer | acb search past context
55
+ v
56
+ [2] ask cite (cited-rag)
57
+ | BM25 + TF-IDF -> RRF -> verbatim sentences + [file:L1-L2]
58
+ | max_score < 0.35 or fidelity < 0.5 -> "Insufficient evidence"
59
+ v
60
+ [3] gate (llm-eval-ci)
61
+ | no_pii_leak + no_injection_obey over the produced answer
62
+ | red gate -> refusal (raw text never delivered)
63
+ v
64
+ cited answer | refusal (no-evidence / safety-gate)
65
+ ```
66
+
67
+ Each stage prefers its pillar implementation and degrades to a compact
68
+ stdlib equivalent when the pillar is not installed (`backends` field of
69
+ every answer states which implementation served each stage, so the demo
70
+ output is auditable). Set `CVA_FORCE_FALLBACK=1` to exercise the portable
71
+ path — the 48 tests pass identically on both paths.
72
+
73
+ ## The 3 pillars (used, not rewritten)
74
+
75
+ | Stage | Pillar repo | How it is used here |
76
+ |-------|--------------|---------------------|
77
+ | Inter-agent memory | [agent-context-bridge](https://github.com/shenn667/agent-context-bridge) | `MemoryStore` + `ContextRecord` + `search_records`: every question and every verdict is recorded (`acb record` semantics) and past context is searched before retrieval |
78
+ | Cited RAG | [cited-rag](https://github.com/shenn667/cited-rag) | `build_index_data` + `Retriever.search` + `generate_answer`: hybrid retrieval, extractive verbatim answers with exact `[file:L1-L2]` citations, `Insufficient evidence` refusal with zero citations |
79
+ | CI gates | [llm-eval-ci](https://github.com/shenn667/llm-eval-ci) | `check_no_pii_leak` + `check_no_injection_obey` gate every answer; `evals/*.json` suites run via `llm-eval run` with blocking exit codes |
80
+
81
+ ## Eval results (reproduce with `make gates` + `make test`)
82
+
83
+ `llm-eval run` on the bundled suites (deterministic, offline):
84
+
85
+ | Suite | Cases | Result |
86
+ |-------|-------|--------|
87
+ | `evals/non_regression.json` | cited answers (contains + citation regex + PII-free), off-corpus refusal | 3/3 passed, exit 0 |
88
+ | `evals/schema.json` | JSON payload contract (cited + refused shapes, budgets) | 2/2 passed, exit 0 |
89
+ | `evals/tripwires.json` | PII request refused, injection-laced prompt refused | 2/2 passed, exit 0 |
90
+ | `evals/banking_compliance.json` | banking cited answer, off-corpus refusal, PII gate, injection gate, masked memory | 5/5 passed, exit 0 |
91
+
92
+ `pytest`: **48/48 passed** on the pillar path and **48/48 passed** with
93
+ `CVA_FORCE_FALLBACK=1` (portable stdlib path): exact verbatim citations,
94
+ refusal with zero citations, gate blocks PII/injection strings,
95
+ injection-laced questions never obeyed, answer determinism, JSON contract,
96
+ memory records, backend auditability. The count is 14 core contract tests
97
+ (`tests/test_verified_agent.py`) plus 34 banking-compliance tests
98
+ (`tests/test_banking_compliance.py`, 16 cases × 2 backends).
99
+
100
+ The red path (a leaked PII string or an obeyed injection **fails** the
101
+ gate, exit 1) is proven in `pytest`, not in the suites: the suites must
102
+ stay green or CI blocks.
103
+
104
+ ## Banking & SecOps Compliance Use Case (B2B)
105
+
106
+ A regulated-banking vertical built on the same verified pipeline, shipped
107
+ under `examples/banking-compliance/`. The corpus is **100% synthetic** —
108
+ four bilingual (FR + EN) markdown files for the fictional *Banque Exemple
109
+ SA / Example Bank SA*. Every file opens with a `SYNTHETIC` header; there is
110
+ **zero real enterprise data**, no real PII, and no actual regulatory text
111
+ (the BCEAO-inspired audit policy is explicitly labelled synthetic).
112
+
113
+ Topics: PCI DSS controls (AES-256 at rest, TLS 1.2+ in transit, PAN
114
+ masking first-6/last-4, HSM key storage, 90-day key rotation), BCEAO-inspired
115
+ audit logs (10-year retention, WORM integrity, NTP sync, maker/checker),
116
+ a SecOps ransomware playbook (VLAN isolation, east-west blocking, forensic
117
+ image before rebuild, RSSI/CISO escalation within 1 hour, 72-hour regulator
118
+ notification), and IAM privileged access (mandatory bastion, phishing-resistant
119
+ MFA, quarterly review, JIT elevation, session recording) ending in an
120
+ assistant-secrecy section that serves as the injection tripwire target.
121
+
122
+ The offline demo (`demo_banking.py`, tempfile workspace, no API key) runs
123
+ four cases with hard asserts (exit 1 on any failure):
124
+
125
+ | Case | Question theme | Expected outcome |
126
+ |------|----------------|------------------|
127
+ | C1 | PCI DSS key-rotation frequency (in-corpus) | cited verbatim answer, gate PASS |
128
+ | C2 | off-corpus trading query | `no-evidence` refusal, zero citations |
129
+ | C3 | IBAN + PAN + email probe | gate blocks `no_pii_leak`; no raw value in answer or workspace; memory masked |
130
+ | C4 | injection-laced IAM question | `safety-gate` refusal via `no_injection_obey` |
131
+
132
+ ```bash
133
+ make banking-demo # 4 asserted cases, offline, exit 0 on success
134
+ make gates # 4 blocking eval suites (incl. banking_compliance)
135
+ make test # 48 contract tests, both backends
136
+ ```
137
+
138
+ **PAN gate extension.** The pillar PII patterns are frozen and carry no
139
+ card-number rule, so the agent-side gate (`verified_agent.gates`) now
140
+ supplements **both** backends with Luhn-validated PAN detection
141
+ (`_luhn_ok` + `_pan_candidates`): 13-19 digit runs (separators
142
+ stripped) that pass the Luhn checksum are flagged as `pan` under
143
+ `no_pii_leak` and masked. Detection and masking share one overlap-safe
144
+ span collector (`_collect_spans`), so a greedy IBAN match can no longer
145
+ swallow an adjacent PAN and a phone sub-pattern cannot leave an IBAN
146
+ fragment in the masked output (no raw value or digit fragment survives).
147
+ `4111111111111111` is detected; `4111111111111112` (bad Luhn) is not.
148
+ The demo and the 34 banking tests
149
+ pass identically on the native-pillar path and with `CVA_FORCE_FALLBACK=1`.
150
+
151
+ ## Quickstart (3 commands)
152
+
153
+ ```bash
154
+ pip install -e .
155
+ make demo # offline demo, no key
156
+ make gates # 4 blocking eval suites
157
+ ```
158
+
159
+ CI (`.github/workflows/ci.yml`): job `pytest` + job `gates` (one step per
160
+ suite, `llm-eval run` when installed, stdlib fallback runner otherwise).
161
+ Any red gate fails the build.
162
+
163
+ ## Watchdog wrapper (autonomous, stdlib)
164
+
165
+ The repo includes an autonomous watchdog wrapper: `scripts/run_watchdog.py`
166
+ (stdlib-only, Popen + start_new_session + 2 reader threads + 1s loop +
167
+ 900s timeout + 300s stall detection + process-group kill, bounded output).
168
+
169
+ ```bash
170
+ python3 scripts/run_watchdog.py --target demo --json
171
+ python3 scripts/run_watchdog.py --target gates --json --timeout 900 --stall-timeout 300
172
+ python3 scripts/run_watchdog.py --target all --json
173
+ ```
174
+
175
+ With `--json`, the wrapper emits an additive JSON summary with at least:
176
+ `job_id`/`run_id`, `status` (`DONE|FAILED|TIMEOUT|STALLED`), `exit_code`,
177
+ `started_at`, `finished_at`, `duration_s`, `reason`, `tail`.
178
+
179
+ Makefile: the `demo-wd` and `gates-wd` targets go through the watchdog;
180
+ `demo` and `gates` stay unchanged for compatibility.
181
+
182
+ ## Verification (3 trials)
183
+
184
+ `scripts/verify_3_trials.py` runs three independent trials (byte-compile,
185
+ `pytest -q`, `make gates`) with the current interpreter (`sys.executable`).
186
+ The verdict is `PASS 3/3` only if every trial passes:
187
+
188
+ ```bash
189
+ python3 scripts/verify_3_trials.py
190
+ ```
191
+
192
+ ## Action gate / status JSON
193
+
194
+ - `verified_agent.gates.run_suite_file` applies action-gate semantics: `0` allow, `2` deny (red gate / failed checks), `1` ask / fail-closed (usage, env, invalid, parse, unknown). On a red gate, no raw output is echoed; only the id, failed checks, and safe/masked info.
195
+ - `VerifiedAgent.ask()` adds additive top-level fields `scores`, `rejected`, `backtracks_count` without breaking the existing `backends` field (`memory`, `rag`, `gate`).
196
+ - `emit_summary(result, json_mode=False)` and `print_status(result, json_mode=False)` are exposed; `demo/demo.py --json` uses this path.
197
+
198
+ ## Links
199
+
200
+ - Dataset (Hugging Face): https://huggingface.co/datasets/SHENNN667/cited-rag-golden-52
201
+ (published under namespace `SHENNN667` — no write rights on `shenn667`;
202
+ the lowercase `shenn667/...` URL returns 401, do not use it as the main link)
203
+ - Eval page: https://shenn667.github.io/eval/ (live, deployed from
204
+ `shenn667/shenn667.github.io` main branch)
205
+
206
+ ## License
207
+
208
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,184 @@
1
+ # claude-verified-agent
2
+
3
+ [![CI](https://github.com/shenn667/claude-verified-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/shenn667/claude-verified-agent/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/claude-verified-agent.svg)](https://pypi.org/project/claude-verified-agent/)
5
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/downloads/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7
+ [![offline](https://img.shields.io/badge/offline-stdlib--only-lightgrey.svg)](https://github.com/shenn667/claude-verified-agent)
8
+
9
+ **An end-to-end verified agent: every answer is cited or refused, every
10
+ delivery passes safety gates, every run is CI-blocked on regression.**
11
+
12
+ No hallucination by design, no PII/injection leak by gate, no silent
13
+ regression by suite. Stdlib-only core, fully offline, no API key.
14
+
15
+ ```bash
16
+ pip install -e .
17
+ make demo # 1 command: cited answer + refusal + gate verdicts
18
+ make banking-demo # banking & SecOps vertical: 4 asserted offline cases
19
+ make test # 48 contract tests (pytest, offline)
20
+ make gates # 4 llm-eval-ci suites, exit != 0 blocks CI
21
+ ```
22
+
23
+ ## Architecture
24
+
25
+ ```text
26
+ question
27
+ |
28
+ v
29
+ [1] record-contexte (agent-context-bridge)
30
+ | acb record question + answer | acb search past context
31
+ v
32
+ [2] ask cite (cited-rag)
33
+ | BM25 + TF-IDF -> RRF -> verbatim sentences + [file:L1-L2]
34
+ | max_score < 0.35 or fidelity < 0.5 -> "Insufficient evidence"
35
+ v
36
+ [3] gate (llm-eval-ci)
37
+ | no_pii_leak + no_injection_obey over the produced answer
38
+ | red gate -> refusal (raw text never delivered)
39
+ v
40
+ cited answer | refusal (no-evidence / safety-gate)
41
+ ```
42
+
43
+ Each stage prefers its pillar implementation and degrades to a compact
44
+ stdlib equivalent when the pillar is not installed (`backends` field of
45
+ every answer states which implementation served each stage, so the demo
46
+ output is auditable). Set `CVA_FORCE_FALLBACK=1` to exercise the portable
47
+ path — the 48 tests pass identically on both paths.
48
+
49
+ ## The 3 pillars (used, not rewritten)
50
+
51
+ | Stage | Pillar repo | How it is used here |
52
+ |-------|--------------|---------------------|
53
+ | Inter-agent memory | [agent-context-bridge](https://github.com/shenn667/agent-context-bridge) | `MemoryStore` + `ContextRecord` + `search_records`: every question and every verdict is recorded (`acb record` semantics) and past context is searched before retrieval |
54
+ | Cited RAG | [cited-rag](https://github.com/shenn667/cited-rag) | `build_index_data` + `Retriever.search` + `generate_answer`: hybrid retrieval, extractive verbatim answers with exact `[file:L1-L2]` citations, `Insufficient evidence` refusal with zero citations |
55
+ | CI gates | [llm-eval-ci](https://github.com/shenn667/llm-eval-ci) | `check_no_pii_leak` + `check_no_injection_obey` gate every answer; `evals/*.json` suites run via `llm-eval run` with blocking exit codes |
56
+
57
+ ## Eval results (reproduce with `make gates` + `make test`)
58
+
59
+ `llm-eval run` on the bundled suites (deterministic, offline):
60
+
61
+ | Suite | Cases | Result |
62
+ |-------|-------|--------|
63
+ | `evals/non_regression.json` | cited answers (contains + citation regex + PII-free), off-corpus refusal | 3/3 passed, exit 0 |
64
+ | `evals/schema.json` | JSON payload contract (cited + refused shapes, budgets) | 2/2 passed, exit 0 |
65
+ | `evals/tripwires.json` | PII request refused, injection-laced prompt refused | 2/2 passed, exit 0 |
66
+ | `evals/banking_compliance.json` | banking cited answer, off-corpus refusal, PII gate, injection gate, masked memory | 5/5 passed, exit 0 |
67
+
68
+ `pytest`: **48/48 passed** on the pillar path and **48/48 passed** with
69
+ `CVA_FORCE_FALLBACK=1` (portable stdlib path): exact verbatim citations,
70
+ refusal with zero citations, gate blocks PII/injection strings,
71
+ injection-laced questions never obeyed, answer determinism, JSON contract,
72
+ memory records, backend auditability. The count is 14 core contract tests
73
+ (`tests/test_verified_agent.py`) plus 34 banking-compliance tests
74
+ (`tests/test_banking_compliance.py`, 16 cases × 2 backends).
75
+
76
+ The red path (a leaked PII string or an obeyed injection **fails** the
77
+ gate, exit 1) is proven in `pytest`, not in the suites: the suites must
78
+ stay green or CI blocks.
79
+
80
+ ## Banking & SecOps Compliance Use Case (B2B)
81
+
82
+ A regulated-banking vertical built on the same verified pipeline, shipped
83
+ under `examples/banking-compliance/`. The corpus is **100% synthetic** —
84
+ four bilingual (FR + EN) markdown files for the fictional *Banque Exemple
85
+ SA / Example Bank SA*. Every file opens with a `SYNTHETIC` header; there is
86
+ **zero real enterprise data**, no real PII, and no actual regulatory text
87
+ (the BCEAO-inspired audit policy is explicitly labelled synthetic).
88
+
89
+ Topics: PCI DSS controls (AES-256 at rest, TLS 1.2+ in transit, PAN
90
+ masking first-6/last-4, HSM key storage, 90-day key rotation), BCEAO-inspired
91
+ audit logs (10-year retention, WORM integrity, NTP sync, maker/checker),
92
+ a SecOps ransomware playbook (VLAN isolation, east-west blocking, forensic
93
+ image before rebuild, RSSI/CISO escalation within 1 hour, 72-hour regulator
94
+ notification), and IAM privileged access (mandatory bastion, phishing-resistant
95
+ MFA, quarterly review, JIT elevation, session recording) ending in an
96
+ assistant-secrecy section that serves as the injection tripwire target.
97
+
98
+ The offline demo (`demo_banking.py`, tempfile workspace, no API key) runs
99
+ four cases with hard asserts (exit 1 on any failure):
100
+
101
+ | Case | Question theme | Expected outcome |
102
+ |------|----------------|------------------|
103
+ | C1 | PCI DSS key-rotation frequency (in-corpus) | cited verbatim answer, gate PASS |
104
+ | C2 | off-corpus trading query | `no-evidence` refusal, zero citations |
105
+ | C3 | IBAN + PAN + email probe | gate blocks `no_pii_leak`; no raw value in answer or workspace; memory masked |
106
+ | C4 | injection-laced IAM question | `safety-gate` refusal via `no_injection_obey` |
107
+
108
+ ```bash
109
+ make banking-demo # 4 asserted cases, offline, exit 0 on success
110
+ make gates # 4 blocking eval suites (incl. banking_compliance)
111
+ make test # 48 contract tests, both backends
112
+ ```
113
+
114
+ **PAN gate extension.** The pillar PII patterns are frozen and carry no
115
+ card-number rule, so the agent-side gate (`verified_agent.gates`) now
116
+ supplements **both** backends with Luhn-validated PAN detection
117
+ (`_luhn_ok` + `_pan_candidates`): 13-19 digit runs (separators
118
+ stripped) that pass the Luhn checksum are flagged as `pan` under
119
+ `no_pii_leak` and masked. Detection and masking share one overlap-safe
120
+ span collector (`_collect_spans`), so a greedy IBAN match can no longer
121
+ swallow an adjacent PAN and a phone sub-pattern cannot leave an IBAN
122
+ fragment in the masked output (no raw value or digit fragment survives).
123
+ `4111111111111111` is detected; `4111111111111112` (bad Luhn) is not.
124
+ The demo and the 34 banking tests
125
+ pass identically on the native-pillar path and with `CVA_FORCE_FALLBACK=1`.
126
+
127
+ ## Quickstart (3 commands)
128
+
129
+ ```bash
130
+ pip install -e .
131
+ make demo # offline demo, no key
132
+ make gates # 4 blocking eval suites
133
+ ```
134
+
135
+ CI (`.github/workflows/ci.yml`): job `pytest` + job `gates` (one step per
136
+ suite, `llm-eval run` when installed, stdlib fallback runner otherwise).
137
+ Any red gate fails the build.
138
+
139
+ ## Watchdog wrapper (autonomous, stdlib)
140
+
141
+ The repo includes an autonomous watchdog wrapper: `scripts/run_watchdog.py`
142
+ (stdlib-only, Popen + start_new_session + 2 reader threads + 1s loop +
143
+ 900s timeout + 300s stall detection + process-group kill, bounded output).
144
+
145
+ ```bash
146
+ python3 scripts/run_watchdog.py --target demo --json
147
+ python3 scripts/run_watchdog.py --target gates --json --timeout 900 --stall-timeout 300
148
+ python3 scripts/run_watchdog.py --target all --json
149
+ ```
150
+
151
+ With `--json`, the wrapper emits an additive JSON summary with at least:
152
+ `job_id`/`run_id`, `status` (`DONE|FAILED|TIMEOUT|STALLED`), `exit_code`,
153
+ `started_at`, `finished_at`, `duration_s`, `reason`, `tail`.
154
+
155
+ Makefile: the `demo-wd` and `gates-wd` targets go through the watchdog;
156
+ `demo` and `gates` stay unchanged for compatibility.
157
+
158
+ ## Verification (3 trials)
159
+
160
+ `scripts/verify_3_trials.py` runs three independent trials (byte-compile,
161
+ `pytest -q`, `make gates`) with the current interpreter (`sys.executable`).
162
+ The verdict is `PASS 3/3` only if every trial passes:
163
+
164
+ ```bash
165
+ python3 scripts/verify_3_trials.py
166
+ ```
167
+
168
+ ## Action gate / status JSON
169
+
170
+ - `verified_agent.gates.run_suite_file` applies action-gate semantics: `0` allow, `2` deny (red gate / failed checks), `1` ask / fail-closed (usage, env, invalid, parse, unknown). On a red gate, no raw output is echoed; only the id, failed checks, and safe/masked info.
171
+ - `VerifiedAgent.ask()` adds additive top-level fields `scores`, `rejected`, `backtracks_count` without breaking the existing `backends` field (`memory`, `rag`, `gate`).
172
+ - `emit_summary(result, json_mode=False)` and `print_status(result, json_mode=False)` are exposed; `demo/demo.py --json` uses this path.
173
+
174
+ ## Links
175
+
176
+ - Dataset (Hugging Face): https://huggingface.co/datasets/SHENNN667/cited-rag-golden-52
177
+ (published under namespace `SHENNN667` — no write rights on `shenn667`;
178
+ the lowercase `shenn667/...` URL returns 401, do not use it as the main link)
179
+ - Eval page: https://shenn667.github.io/eval/ (live, deployed from
180
+ `shenn667/shenn667.github.io` main branch)
181
+
182
+ ## License
183
+
184
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "claude-verified-agent"
7
+ version = "0.2.0"
8
+ description = "End-to-end verified agent demo: inter-agent memory (agent-context-bridge) + cited-or-refused RAG (cited-rag) + CI safety gates (llm-eval-ci). Stdlib only, offline, no API key."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "shenn667", email = "lehdev@yandex.com" }]
13
+ keywords = ["agents", "rag", "citations", "evals", "offline", "claude"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.12",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ ]
21
+ dependencies = []
22
+
23
+ [project.optional-dependencies]
24
+ dev = ["pytest>=7.0.0"]
25
+ pillars = [
26
+ "agent-context-bridge>=0.4.0",
27
+ "cited-rag>=0.2.0",
28
+ "llm-eval-ci>=0.2.0",
29
+ ]
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.pytest.ini_options]
35
+ testpaths = ["tests"]
36
+ addopts = "-q"
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/shenn667/claude-verified-agent"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: claude-verified-agent
3
+ Version: 0.2.0
4
+ Summary: End-to-end verified agent demo: inter-agent memory (agent-context-bridge) + cited-or-refused RAG (cited-rag) + CI safety gates (llm-eval-ci). Stdlib only, offline, no API key.
5
+ Author-email: shenn667 <lehdev@yandex.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/shenn667/claude-verified-agent
8
+ Keywords: agents,rag,citations,evals,offline,claude
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
19
+ Provides-Extra: pillars
20
+ Requires-Dist: agent-context-bridge>=0.4.0; extra == "pillars"
21
+ Requires-Dist: cited-rag>=0.2.0; extra == "pillars"
22
+ Requires-Dist: llm-eval-ci>=0.2.0; extra == "pillars"
23
+ Dynamic: license-file
24
+
25
+ # claude-verified-agent
26
+
27
+ [![CI](https://github.com/shenn667/claude-verified-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/shenn667/claude-verified-agent/actions/workflows/ci.yml)
28
+ [![PyPI](https://img.shields.io/pypi/v/claude-verified-agent.svg)](https://pypi.org/project/claude-verified-agent/)
29
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/downloads/)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
31
+ [![offline](https://img.shields.io/badge/offline-stdlib--only-lightgrey.svg)](https://github.com/shenn667/claude-verified-agent)
32
+
33
+ **An end-to-end verified agent: every answer is cited or refused, every
34
+ delivery passes safety gates, every run is CI-blocked on regression.**
35
+
36
+ No hallucination by design, no PII/injection leak by gate, no silent
37
+ regression by suite. Stdlib-only core, fully offline, no API key.
38
+
39
+ ```bash
40
+ pip install -e .
41
+ make demo # 1 command: cited answer + refusal + gate verdicts
42
+ make banking-demo # banking & SecOps vertical: 4 asserted offline cases
43
+ make test # 48 contract tests (pytest, offline)
44
+ make gates # 4 llm-eval-ci suites, exit != 0 blocks CI
45
+ ```
46
+
47
+ ## Architecture
48
+
49
+ ```text
50
+ question
51
+ |
52
+ v
53
+ [1] record-contexte (agent-context-bridge)
54
+ | acb record question + answer | acb search past context
55
+ v
56
+ [2] ask cite (cited-rag)
57
+ | BM25 + TF-IDF -> RRF -> verbatim sentences + [file:L1-L2]
58
+ | max_score < 0.35 or fidelity < 0.5 -> "Insufficient evidence"
59
+ v
60
+ [3] gate (llm-eval-ci)
61
+ | no_pii_leak + no_injection_obey over the produced answer
62
+ | red gate -> refusal (raw text never delivered)
63
+ v
64
+ cited answer | refusal (no-evidence / safety-gate)
65
+ ```
66
+
67
+ Each stage prefers its pillar implementation and degrades to a compact
68
+ stdlib equivalent when the pillar is not installed (`backends` field of
69
+ every answer states which implementation served each stage, so the demo
70
+ output is auditable). Set `CVA_FORCE_FALLBACK=1` to exercise the portable
71
+ path — the 48 tests pass identically on both paths.
72
+
73
+ ## The 3 pillars (used, not rewritten)
74
+
75
+ | Stage | Pillar repo | How it is used here |
76
+ |-------|--------------|---------------------|
77
+ | Inter-agent memory | [agent-context-bridge](https://github.com/shenn667/agent-context-bridge) | `MemoryStore` + `ContextRecord` + `search_records`: every question and every verdict is recorded (`acb record` semantics) and past context is searched before retrieval |
78
+ | Cited RAG | [cited-rag](https://github.com/shenn667/cited-rag) | `build_index_data` + `Retriever.search` + `generate_answer`: hybrid retrieval, extractive verbatim answers with exact `[file:L1-L2]` citations, `Insufficient evidence` refusal with zero citations |
79
+ | CI gates | [llm-eval-ci](https://github.com/shenn667/llm-eval-ci) | `check_no_pii_leak` + `check_no_injection_obey` gate every answer; `evals/*.json` suites run via `llm-eval run` with blocking exit codes |
80
+
81
+ ## Eval results (reproduce with `make gates` + `make test`)
82
+
83
+ `llm-eval run` on the bundled suites (deterministic, offline):
84
+
85
+ | Suite | Cases | Result |
86
+ |-------|-------|--------|
87
+ | `evals/non_regression.json` | cited answers (contains + citation regex + PII-free), off-corpus refusal | 3/3 passed, exit 0 |
88
+ | `evals/schema.json` | JSON payload contract (cited + refused shapes, budgets) | 2/2 passed, exit 0 |
89
+ | `evals/tripwires.json` | PII request refused, injection-laced prompt refused | 2/2 passed, exit 0 |
90
+ | `evals/banking_compliance.json` | banking cited answer, off-corpus refusal, PII gate, injection gate, masked memory | 5/5 passed, exit 0 |
91
+
92
+ `pytest`: **48/48 passed** on the pillar path and **48/48 passed** with
93
+ `CVA_FORCE_FALLBACK=1` (portable stdlib path): exact verbatim citations,
94
+ refusal with zero citations, gate blocks PII/injection strings,
95
+ injection-laced questions never obeyed, answer determinism, JSON contract,
96
+ memory records, backend auditability. The count is 14 core contract tests
97
+ (`tests/test_verified_agent.py`) plus 34 banking-compliance tests
98
+ (`tests/test_banking_compliance.py`, 16 cases × 2 backends).
99
+
100
+ The red path (a leaked PII string or an obeyed injection **fails** the
101
+ gate, exit 1) is proven in `pytest`, not in the suites: the suites must
102
+ stay green or CI blocks.
103
+
104
+ ## Banking & SecOps Compliance Use Case (B2B)
105
+
106
+ A regulated-banking vertical built on the same verified pipeline, shipped
107
+ under `examples/banking-compliance/`. The corpus is **100% synthetic** —
108
+ four bilingual (FR + EN) markdown files for the fictional *Banque Exemple
109
+ SA / Example Bank SA*. Every file opens with a `SYNTHETIC` header; there is
110
+ **zero real enterprise data**, no real PII, and no actual regulatory text
111
+ (the BCEAO-inspired audit policy is explicitly labelled synthetic).
112
+
113
+ Topics: PCI DSS controls (AES-256 at rest, TLS 1.2+ in transit, PAN
114
+ masking first-6/last-4, HSM key storage, 90-day key rotation), BCEAO-inspired
115
+ audit logs (10-year retention, WORM integrity, NTP sync, maker/checker),
116
+ a SecOps ransomware playbook (VLAN isolation, east-west blocking, forensic
117
+ image before rebuild, RSSI/CISO escalation within 1 hour, 72-hour regulator
118
+ notification), and IAM privileged access (mandatory bastion, phishing-resistant
119
+ MFA, quarterly review, JIT elevation, session recording) ending in an
120
+ assistant-secrecy section that serves as the injection tripwire target.
121
+
122
+ The offline demo (`demo_banking.py`, tempfile workspace, no API key) runs
123
+ four cases with hard asserts (exit 1 on any failure):
124
+
125
+ | Case | Question theme | Expected outcome |
126
+ |------|----------------|------------------|
127
+ | C1 | PCI DSS key-rotation frequency (in-corpus) | cited verbatim answer, gate PASS |
128
+ | C2 | off-corpus trading query | `no-evidence` refusal, zero citations |
129
+ | C3 | IBAN + PAN + email probe | gate blocks `no_pii_leak`; no raw value in answer or workspace; memory masked |
130
+ | C4 | injection-laced IAM question | `safety-gate` refusal via `no_injection_obey` |
131
+
132
+ ```bash
133
+ make banking-demo # 4 asserted cases, offline, exit 0 on success
134
+ make gates # 4 blocking eval suites (incl. banking_compliance)
135
+ make test # 48 contract tests, both backends
136
+ ```
137
+
138
+ **PAN gate extension.** The pillar PII patterns are frozen and carry no
139
+ card-number rule, so the agent-side gate (`verified_agent.gates`) now
140
+ supplements **both** backends with Luhn-validated PAN detection
141
+ (`_luhn_ok` + `_pan_candidates`): 13-19 digit runs (separators
142
+ stripped) that pass the Luhn checksum are flagged as `pan` under
143
+ `no_pii_leak` and masked. Detection and masking share one overlap-safe
144
+ span collector (`_collect_spans`), so a greedy IBAN match can no longer
145
+ swallow an adjacent PAN and a phone sub-pattern cannot leave an IBAN
146
+ fragment in the masked output (no raw value or digit fragment survives).
147
+ `4111111111111111` is detected; `4111111111111112` (bad Luhn) is not.
148
+ The demo and the 34 banking tests
149
+ pass identically on the native-pillar path and with `CVA_FORCE_FALLBACK=1`.
150
+
151
+ ## Quickstart (3 commands)
152
+
153
+ ```bash
154
+ pip install -e .
155
+ make demo # offline demo, no key
156
+ make gates # 4 blocking eval suites
157
+ ```
158
+
159
+ CI (`.github/workflows/ci.yml`): job `pytest` + job `gates` (one step per
160
+ suite, `llm-eval run` when installed, stdlib fallback runner otherwise).
161
+ Any red gate fails the build.
162
+
163
+ ## Watchdog wrapper (autonomous, stdlib)
164
+
165
+ The repo includes an autonomous watchdog wrapper: `scripts/run_watchdog.py`
166
+ (stdlib-only, Popen + start_new_session + 2 reader threads + 1s loop +
167
+ 900s timeout + 300s stall detection + process-group kill, bounded output).
168
+
169
+ ```bash
170
+ python3 scripts/run_watchdog.py --target demo --json
171
+ python3 scripts/run_watchdog.py --target gates --json --timeout 900 --stall-timeout 300
172
+ python3 scripts/run_watchdog.py --target all --json
173
+ ```
174
+
175
+ With `--json`, the wrapper emits an additive JSON summary with at least:
176
+ `job_id`/`run_id`, `status` (`DONE|FAILED|TIMEOUT|STALLED`), `exit_code`,
177
+ `started_at`, `finished_at`, `duration_s`, `reason`, `tail`.
178
+
179
+ Makefile: the `demo-wd` and `gates-wd` targets go through the watchdog;
180
+ `demo` and `gates` stay unchanged for compatibility.
181
+
182
+ ## Verification (3 trials)
183
+
184
+ `scripts/verify_3_trials.py` runs three independent trials (byte-compile,
185
+ `pytest -q`, `make gates`) with the current interpreter (`sys.executable`).
186
+ The verdict is `PASS 3/3` only if every trial passes:
187
+
188
+ ```bash
189
+ python3 scripts/verify_3_trials.py
190
+ ```
191
+
192
+ ## Action gate / status JSON
193
+
194
+ - `verified_agent.gates.run_suite_file` applies action-gate semantics: `0` allow, `2` deny (red gate / failed checks), `1` ask / fail-closed (usage, env, invalid, parse, unknown). On a red gate, no raw output is echoed; only the id, failed checks, and safe/masked info.
195
+ - `VerifiedAgent.ask()` adds additive top-level fields `scores`, `rejected`, `backtracks_count` without breaking the existing `backends` field (`memory`, `rag`, `gate`).
196
+ - `emit_summary(result, json_mode=False)` and `print_status(result, json_mode=False)` are exposed; `demo/demo.py --json` uses this path.
197
+
198
+ ## Links
199
+
200
+ - Dataset (Hugging Face): https://huggingface.co/datasets/SHENNN667/cited-rag-golden-52
201
+ (published under namespace `SHENNN667` — no write rights on `shenn667`;
202
+ the lowercase `shenn667/...` URL returns 401, do not use it as the main link)
203
+ - Eval page: https://shenn667.github.io/eval/ (live, deployed from
204
+ `shenn667/shenn667.github.io` main branch)
205
+
206
+ ## License
207
+
208
+ MIT — see [LICENSE](LICENSE).