trustandverify 0.1.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.
- trustandverify-0.1.0/LICENSE +21 -0
- trustandverify-0.1.0/PKG-INFO +195 -0
- trustandverify-0.1.0/README.md +131 -0
- trustandverify-0.1.0/pyproject.toml +127 -0
- trustandverify-0.1.0/src/trustandverify/__init__.py +68 -0
- trustandverify-0.1.0/src/trustandverify/_version.py +1 -0
- trustandverify-0.1.0/src/trustandverify/cache/__init__.py +6 -0
- trustandverify-0.1.0/src/trustandverify/cache/protocol.py +41 -0
- trustandverify-0.1.0/src/trustandverify/cli/__init__.py +0 -0
- trustandverify-0.1.0/src/trustandverify/cli/main.py +166 -0
- trustandverify-0.1.0/src/trustandverify/core/__init__.py +27 -0
- trustandverify-0.1.0/src/trustandverify/core/agent.py +83 -0
- trustandverify-0.1.0/src/trustandverify/core/config.py +47 -0
- trustandverify-0.1.0/src/trustandverify/core/models.py +114 -0
- trustandverify-0.1.0/src/trustandverify/core/pipeline.py +368 -0
- trustandverify-0.1.0/src/trustandverify/export/__init__.py +6 -0
- trustandverify-0.1.0/src/trustandverify/export/jsonld.py +100 -0
- trustandverify-0.1.0/src/trustandverify/export/protocol.py +38 -0
- trustandverify-0.1.0/src/trustandverify/llm/__init__.py +21 -0
- trustandverify-0.1.0/src/trustandverify/llm/gemini.py +146 -0
- trustandverify-0.1.0/src/trustandverify/llm/prompts.py +96 -0
- trustandverify-0.1.0/src/trustandverify/llm/protocol.py +53 -0
- trustandverify-0.1.0/src/trustandverify/scoring/__init__.py +37 -0
- trustandverify-0.1.0/src/trustandverify/scoring/algebra.py +91 -0
- trustandverify-0.1.0/src/trustandverify/scoring/conflict.py +72 -0
- trustandverify-0.1.0/src/trustandverify/scoring/fusion.py +42 -0
- trustandverify-0.1.0/src/trustandverify/scoring/opinions.py +96 -0
- trustandverify-0.1.0/src/trustandverify/scoring/trust.py +76 -0
- trustandverify-0.1.0/src/trustandverify/search/__init__.py +6 -0
- trustandverify-0.1.0/src/trustandverify/search/protocol.py +38 -0
- trustandverify-0.1.0/src/trustandverify/search/tavily.py +74 -0
- trustandverify-0.1.0/src/trustandverify/storage/__init__.py +6 -0
- trustandverify-0.1.0/src/trustandverify/storage/memory.py +51 -0
- trustandverify-0.1.0/src/trustandverify/storage/protocol.py +56 -0
- trustandverify-0.1.0/src/trustandverify/ui/__init__.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Muntaser Syed
|
|
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,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trustandverify
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Agentic knowledge verification using Subjective Logic confidence algebra
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: knowledge-verification,subjective-logic,confidence-algebra,agentic-ai,hallucination-detection,provenance,json-ld,uncertainty-quantification,fact-checking
|
|
8
|
+
Author: Muntaser Syed
|
|
9
|
+
Author-email: jemsbhai@gmail.com
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Provides-Extra: anthropic
|
|
29
|
+
Provides-Extra: bing
|
|
30
|
+
Provides-Extra: brave
|
|
31
|
+
Provides-Extra: cli
|
|
32
|
+
Provides-Extra: gemini
|
|
33
|
+
Provides-Extra: mongo
|
|
34
|
+
Provides-Extra: neo4j
|
|
35
|
+
Provides-Extra: ollama
|
|
36
|
+
Provides-Extra: openai
|
|
37
|
+
Provides-Extra: pdf
|
|
38
|
+
Provides-Extra: postgres
|
|
39
|
+
Provides-Extra: redis
|
|
40
|
+
Provides-Extra: serpapi
|
|
41
|
+
Provides-Extra: sqlite
|
|
42
|
+
Provides-Extra: tavily
|
|
43
|
+
Provides-Extra: ui
|
|
44
|
+
Requires-Dist: anthropic (>=0.25) ; extra == "anthropic" or extra == "all"
|
|
45
|
+
Requires-Dist: asyncpg (>=0.28) ; extra == "postgres" or extra == "all"
|
|
46
|
+
Requires-Dist: httpx (>=0.24)
|
|
47
|
+
Requires-Dist: jsonld-ex (>=0.6)
|
|
48
|
+
Requires-Dist: litellm (>=1.0) ; extra == "gemini" or extra == "all"
|
|
49
|
+
Requires-Dist: motor (>=3.0) ; extra == "mongo" or extra == "all"
|
|
50
|
+
Requires-Dist: neo4j (>=5.0) ; extra == "neo4j" or extra == "all"
|
|
51
|
+
Requires-Dist: ollama (>=0.1) ; extra == "ollama" or extra == "all"
|
|
52
|
+
Requires-Dist: openai (>=1.0) ; extra == "openai" or extra == "all"
|
|
53
|
+
Requires-Dist: redis (>=5.0) ; extra == "redis" or extra == "all"
|
|
54
|
+
Requires-Dist: rich (>=13.0) ; extra == "cli" or extra == "all"
|
|
55
|
+
Requires-Dist: streamlit (>=1.30) ; extra == "ui" or extra == "all"
|
|
56
|
+
Requires-Dist: tavily-python (>=0.3) ; extra == "tavily" or extra == "all"
|
|
57
|
+
Requires-Dist: typer (>=0.9) ; extra == "cli" or extra == "all"
|
|
58
|
+
Requires-Dist: weasyprint (>=60) ; extra == "pdf" or extra == "all"
|
|
59
|
+
Project-URL: Documentation, https://github.com/jemsbhai/trustandverify#readme
|
|
60
|
+
Project-URL: Homepage, https://github.com/jemsbhai/trustandverify
|
|
61
|
+
Project-URL: Repository, https://github.com/jemsbhai/trustandverify
|
|
62
|
+
Description-Content-Type: text/markdown
|
|
63
|
+
|
|
64
|
+
# 🔍 trustandverify
|
|
65
|
+
|
|
66
|
+
[](https://pypi.org/project/trustandverify/)
|
|
67
|
+
[](https://pypi.org/project/trustandverify/)
|
|
68
|
+
[](LICENSE)
|
|
69
|
+
[](https://github.com/jemsbhai/trustandverify/actions)
|
|
70
|
+
|
|
71
|
+
**Agentic knowledge verification using Subjective Logic confidence algebra.**
|
|
72
|
+
|
|
73
|
+
`trustandverify` decomposes research questions into verifiable claims, gathers evidence from multiple search backends, scores confidence using formal Subjective Logic mathematics (Jøsang 2016), and produces provenance-rich reports with per-claim uncertainty quantification.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## The Problem
|
|
78
|
+
|
|
79
|
+
Every major AI system treats confidence as a single scalar — or ignores it entirely. A `confidence = 0.5` is meaningless: it could mean "strong evidence that the probability is 50%", or "we have literally no evidence and are guessing." These require fundamentally different downstream decisions.
|
|
80
|
+
|
|
81
|
+
`trustandverify` uses **Subjective Logic opinion tuples** `(belief, disbelief, uncertainty, base_rate)` so you always know *not just what the AI thinks, but how much evidence it has.*
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Quick Start
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install trustandverify[tavily,gemini]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import asyncio
|
|
93
|
+
from trustandverify import verify
|
|
94
|
+
|
|
95
|
+
report = asyncio.run(verify("Is remote work more productive than office work?"))
|
|
96
|
+
print(report.summary)
|
|
97
|
+
for claim in report.claims:
|
|
98
|
+
op = claim.opinion
|
|
99
|
+
print(f" [{claim.verdict}] {claim.text}")
|
|
100
|
+
print(f" P={op.projected_probability():.3f} b={op.belief:.3f} d={op.disbelief:.3f} u={op.uncertainty:.3f}")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Configured Usage
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from trustandverify import TrustAgent, TrustConfig
|
|
109
|
+
from trustandverify.search import TavilySearch
|
|
110
|
+
from trustandverify.llm import GeminiBackend
|
|
111
|
+
from trustandverify.storage import SQLiteStorage
|
|
112
|
+
from trustandverify.export import JsonLdExporter, MarkdownExporter
|
|
113
|
+
|
|
114
|
+
config = TrustConfig(num_claims=5, max_sources_per_claim=3)
|
|
115
|
+
|
|
116
|
+
agent = TrustAgent(
|
|
117
|
+
config=config,
|
|
118
|
+
search=TavilySearch(),
|
|
119
|
+
llm=GeminiBackend(),
|
|
120
|
+
storage=SQLiteStorage("reports.db"),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
report = await agent.verify("Is nuclear energy safer than solar?")
|
|
124
|
+
|
|
125
|
+
JsonLdExporter().render_to_file(report, "report.jsonld")
|
|
126
|
+
MarkdownExporter().render_to_file(report, "report.md")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## CLI
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
trustandverify "Is coffee healthy?"
|
|
135
|
+
trustandverify "Is coffee healthy?" --claims 5 --llm gemini --format markdown
|
|
136
|
+
trustandverify ui # Launch Streamlit dashboard
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Why Subjective Logic?
|
|
142
|
+
|
|
143
|
+
| Scenario | Scalar Confidence | `trustandverify` Opinion |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| Strong evidence it's 50/50 | 0.5 | `b=0.45, d=0.45, u=0.10` |
|
|
146
|
+
| No evidence at all | 0.5 | `b=0.00, d=0.00, u=1.00` |
|
|
147
|
+
| Sources violently disagree | 0.5 | `b=0.40, d=0.40, u=0.20` |
|
|
148
|
+
|
|
149
|
+
Confidence algebra (from [`jsonld-ex`](https://pypi.org/project/jsonld-ex/)):
|
|
150
|
+
- **Cumulative fusion** — more independent agreeing sources → lower uncertainty
|
|
151
|
+
- **Trust discount** — `.gov`/`.edu` sources weighted higher than Reddit
|
|
152
|
+
- **Pairwise conflict detection** — surfaces where sources disagree, quantified
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Install Options
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
pip install trustandverify # core only
|
|
160
|
+
pip install trustandverify[tavily,gemini] # minimal working setup
|
|
161
|
+
pip install trustandverify[tavily,brave,openai,sqlite] # typical setup
|
|
162
|
+
pip install trustandverify[all] # everything
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Architecture
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
trustandverify/
|
|
171
|
+
├── core/ — TrustAgent, pipeline, models, config
|
|
172
|
+
├── scoring/ — Subjective Logic algebra (wraps jsonld-ex)
|
|
173
|
+
├── search/ — SearchBackend protocol + Tavily, Brave, Bing, SerpAPI
|
|
174
|
+
├── llm/ — LLMBackend protocol + Gemini, OpenAI, Anthropic, Ollama
|
|
175
|
+
├── storage/ — StorageBackend protocol + memory, SQLite, Postgres, Neo4j
|
|
176
|
+
├── cache/ — CacheBackend protocol + file cache, Redis
|
|
177
|
+
├── export/ — ExportBackend protocol + JSON-LD, Markdown, HTML, PDF
|
|
178
|
+
├── cli/ — Typer CLI
|
|
179
|
+
└── ui/ — Streamlit dashboard
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## References
|
|
185
|
+
|
|
186
|
+
- Jøsang, A. (2016). *Subjective Logic: A Formalism for Reasoning Under Uncertainty.* Springer.
|
|
187
|
+
- [`jsonld-ex`](https://pypi.org/project/jsonld-ex/) — JSON-LD 1.2 extensions with Subjective Logic confidence algebra
|
|
188
|
+
- W3C [PROV-O](https://www.w3.org/TR/prov-o/) — Provenance Ontology
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT — see [LICENSE](LICENSE).
|
|
195
|
+
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# 🔍 trustandverify
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/trustandverify/)
|
|
4
|
+
[](https://pypi.org/project/trustandverify/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/jemsbhai/trustandverify/actions)
|
|
7
|
+
|
|
8
|
+
**Agentic knowledge verification using Subjective Logic confidence algebra.**
|
|
9
|
+
|
|
10
|
+
`trustandverify` decomposes research questions into verifiable claims, gathers evidence from multiple search backends, scores confidence using formal Subjective Logic mathematics (Jøsang 2016), and produces provenance-rich reports with per-claim uncertainty quantification.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## The Problem
|
|
15
|
+
|
|
16
|
+
Every major AI system treats confidence as a single scalar — or ignores it entirely. A `confidence = 0.5` is meaningless: it could mean "strong evidence that the probability is 50%", or "we have literally no evidence and are guessing." These require fundamentally different downstream decisions.
|
|
17
|
+
|
|
18
|
+
`trustandverify` uses **Subjective Logic opinion tuples** `(belief, disbelief, uncertainty, base_rate)` so you always know *not just what the AI thinks, but how much evidence it has.*
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install trustandverify[tavily,gemini]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import asyncio
|
|
30
|
+
from trustandverify import verify
|
|
31
|
+
|
|
32
|
+
report = asyncio.run(verify("Is remote work more productive than office work?"))
|
|
33
|
+
print(report.summary)
|
|
34
|
+
for claim in report.claims:
|
|
35
|
+
op = claim.opinion
|
|
36
|
+
print(f" [{claim.verdict}] {claim.text}")
|
|
37
|
+
print(f" P={op.projected_probability():.3f} b={op.belief:.3f} d={op.disbelief:.3f} u={op.uncertainty:.3f}")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Configured Usage
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from trustandverify import TrustAgent, TrustConfig
|
|
46
|
+
from trustandverify.search import TavilySearch
|
|
47
|
+
from trustandverify.llm import GeminiBackend
|
|
48
|
+
from trustandverify.storage import SQLiteStorage
|
|
49
|
+
from trustandverify.export import JsonLdExporter, MarkdownExporter
|
|
50
|
+
|
|
51
|
+
config = TrustConfig(num_claims=5, max_sources_per_claim=3)
|
|
52
|
+
|
|
53
|
+
agent = TrustAgent(
|
|
54
|
+
config=config,
|
|
55
|
+
search=TavilySearch(),
|
|
56
|
+
llm=GeminiBackend(),
|
|
57
|
+
storage=SQLiteStorage("reports.db"),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
report = await agent.verify("Is nuclear energy safer than solar?")
|
|
61
|
+
|
|
62
|
+
JsonLdExporter().render_to_file(report, "report.jsonld")
|
|
63
|
+
MarkdownExporter().render_to_file(report, "report.md")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## CLI
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
trustandverify "Is coffee healthy?"
|
|
72
|
+
trustandverify "Is coffee healthy?" --claims 5 --llm gemini --format markdown
|
|
73
|
+
trustandverify ui # Launch Streamlit dashboard
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Why Subjective Logic?
|
|
79
|
+
|
|
80
|
+
| Scenario | Scalar Confidence | `trustandverify` Opinion |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| Strong evidence it's 50/50 | 0.5 | `b=0.45, d=0.45, u=0.10` |
|
|
83
|
+
| No evidence at all | 0.5 | `b=0.00, d=0.00, u=1.00` |
|
|
84
|
+
| Sources violently disagree | 0.5 | `b=0.40, d=0.40, u=0.20` |
|
|
85
|
+
|
|
86
|
+
Confidence algebra (from [`jsonld-ex`](https://pypi.org/project/jsonld-ex/)):
|
|
87
|
+
- **Cumulative fusion** — more independent agreeing sources → lower uncertainty
|
|
88
|
+
- **Trust discount** — `.gov`/`.edu` sources weighted higher than Reddit
|
|
89
|
+
- **Pairwise conflict detection** — surfaces where sources disagree, quantified
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Install Options
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install trustandverify # core only
|
|
97
|
+
pip install trustandverify[tavily,gemini] # minimal working setup
|
|
98
|
+
pip install trustandverify[tavily,brave,openai,sqlite] # typical setup
|
|
99
|
+
pip install trustandverify[all] # everything
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Architecture
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
trustandverify/
|
|
108
|
+
├── core/ — TrustAgent, pipeline, models, config
|
|
109
|
+
├── scoring/ — Subjective Logic algebra (wraps jsonld-ex)
|
|
110
|
+
├── search/ — SearchBackend protocol + Tavily, Brave, Bing, SerpAPI
|
|
111
|
+
├── llm/ — LLMBackend protocol + Gemini, OpenAI, Anthropic, Ollama
|
|
112
|
+
├── storage/ — StorageBackend protocol + memory, SQLite, Postgres, Neo4j
|
|
113
|
+
├── cache/ — CacheBackend protocol + file cache, Redis
|
|
114
|
+
├── export/ — ExportBackend protocol + JSON-LD, Markdown, HTML, PDF
|
|
115
|
+
├── cli/ — Typer CLI
|
|
116
|
+
└── ui/ — Streamlit dashboard
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## References
|
|
122
|
+
|
|
123
|
+
- Jøsang, A. (2016). *Subjective Logic: A Formalism for Reasoning Under Uncertainty.* Springer.
|
|
124
|
+
- [`jsonld-ex`](https://pypi.org/project/jsonld-ex/) — JSON-LD 1.2 extensions with Subjective Logic confidence algebra
|
|
125
|
+
- W3C [PROV-O](https://www.w3.org/TR/prov-o/) — Provenance Ontology
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "trustandverify"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Agentic knowledge verification using Subjective Logic confidence algebra"
|
|
5
|
+
authors = ["Muntaser Syed <jemsbhai@gmail.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
homepage = "https://github.com/jemsbhai/trustandverify"
|
|
9
|
+
repository = "https://github.com/jemsbhai/trustandverify"
|
|
10
|
+
documentation = "https://github.com/jemsbhai/trustandverify#readme"
|
|
11
|
+
keywords = [
|
|
12
|
+
"knowledge-verification", "subjective-logic", "confidence-algebra",
|
|
13
|
+
"agentic-ai", "hallucination-detection", "provenance", "json-ld",
|
|
14
|
+
"uncertainty-quantification", "fact-checking",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Natural Language :: English",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
]
|
|
32
|
+
packages = [{include = "trustandverify", from = "src"}]
|
|
33
|
+
|
|
34
|
+
# ── Core dependencies (always installed) ──────────────────────────────────────
|
|
35
|
+
[tool.poetry.dependencies]
|
|
36
|
+
python = "^3.10"
|
|
37
|
+
jsonld-ex = ">=0.6" # Subjective Logic confidence algebra
|
|
38
|
+
httpx = ">=0.24" # Async HTTP client for search backends
|
|
39
|
+
|
|
40
|
+
# ── Optional extras ───────────────────────────────────────────────────────────
|
|
41
|
+
# Search backends
|
|
42
|
+
tavily-python = {version = ">=0.3", optional = true}
|
|
43
|
+
|
|
44
|
+
# LLM backends
|
|
45
|
+
openai = {version = ">=1.0", optional = true}
|
|
46
|
+
anthropic = {version = ">=0.25", optional = true}
|
|
47
|
+
litellm = {version = ">=1.0", optional = true} # gemini + many others
|
|
48
|
+
ollama = {version = ">=0.1", optional = true}
|
|
49
|
+
|
|
50
|
+
# Storage backends
|
|
51
|
+
asyncpg = {version = ">=0.28", optional = true} # postgres
|
|
52
|
+
neo4j = {version = ">=5.0", optional = true}
|
|
53
|
+
motor = {version = ">=3.0", optional = true} # mongodb async
|
|
54
|
+
redis = {version = ">=5.0", optional = true}
|
|
55
|
+
|
|
56
|
+
# Export
|
|
57
|
+
weasyprint = {version = ">=60", optional = true} # pdf
|
|
58
|
+
|
|
59
|
+
# CLI
|
|
60
|
+
typer = {version = ">=0.9", optional = true}
|
|
61
|
+
rich = {version = ">=13.0", optional = true}
|
|
62
|
+
|
|
63
|
+
# UI
|
|
64
|
+
streamlit = {version = ">=1.30", optional = true}
|
|
65
|
+
|
|
66
|
+
[tool.poetry.extras]
|
|
67
|
+
tavily = ["tavily-python"]
|
|
68
|
+
serpapi = [] # uses httpx directly
|
|
69
|
+
brave = [] # uses httpx directly
|
|
70
|
+
bing = [] # uses httpx directly
|
|
71
|
+
openai = ["openai"]
|
|
72
|
+
anthropic = ["anthropic"]
|
|
73
|
+
gemini = ["litellm"]
|
|
74
|
+
ollama = ["ollama"]
|
|
75
|
+
sqlite = [] # stdlib, no extra dep
|
|
76
|
+
postgres = ["asyncpg"]
|
|
77
|
+
neo4j = ["neo4j"]
|
|
78
|
+
mongo = ["motor"]
|
|
79
|
+
redis = ["redis"]
|
|
80
|
+
ui = ["streamlit"]
|
|
81
|
+
cli = ["typer", "rich"]
|
|
82
|
+
pdf = ["weasyprint"]
|
|
83
|
+
all = [
|
|
84
|
+
"tavily-python", "openai", "anthropic", "litellm", "ollama",
|
|
85
|
+
"asyncpg", "neo4j", "motor", "redis",
|
|
86
|
+
"weasyprint", "typer", "rich", "streamlit",
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
# ── Dev dependencies ───────────────────────────────────────────────────────────
|
|
90
|
+
[tool.poetry.group.dev.dependencies]
|
|
91
|
+
pytest = "^8.0"
|
|
92
|
+
pytest-asyncio = "^0.24"
|
|
93
|
+
pytest-cov = "^6.0"
|
|
94
|
+
ruff = ">=0.2"
|
|
95
|
+
mypy = ">=1.8"
|
|
96
|
+
|
|
97
|
+
# ── Entry points ───────────────────────────────────────────────────────────────
|
|
98
|
+
[tool.poetry.scripts]
|
|
99
|
+
trustandverify = "trustandverify.cli.main:main"
|
|
100
|
+
|
|
101
|
+
# ── Build ──────────────────────────────────────────────────────────────────────
|
|
102
|
+
[build-system]
|
|
103
|
+
requires = ["poetry-core"]
|
|
104
|
+
build-backend = "poetry.core.masonry.api"
|
|
105
|
+
|
|
106
|
+
# ── Pytest ─────────────────────────────────────────────────────────────────────
|
|
107
|
+
[tool.pytest.ini_options]
|
|
108
|
+
testpaths = ["tests"]
|
|
109
|
+
asyncio_mode = "auto"
|
|
110
|
+
markers = [
|
|
111
|
+
"integration: requires external API keys or services",
|
|
112
|
+
"slow: takes more than 5 seconds",
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
# ── Ruff ───────────────────────────────────────────────────────────────────────
|
|
116
|
+
[tool.ruff]
|
|
117
|
+
target-version = "py310"
|
|
118
|
+
line-length = 100
|
|
119
|
+
|
|
120
|
+
[tool.ruff.lint]
|
|
121
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
122
|
+
|
|
123
|
+
# ── Mypy ───────────────────────────────────────────────────────────────────────
|
|
124
|
+
[tool.mypy]
|
|
125
|
+
python_version = "3.10"
|
|
126
|
+
strict = true
|
|
127
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""trustandverify — Agentic knowledge verification using Subjective Logic.
|
|
2
|
+
|
|
3
|
+
Quick start::
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from trustandverify import verify
|
|
7
|
+
|
|
8
|
+
report = asyncio.run(verify("Is remote work more productive than office work?"))
|
|
9
|
+
print(report.summary)
|
|
10
|
+
for claim in report.claims:
|
|
11
|
+
print(f" [{claim.verdict}] {claim.text}")
|
|
12
|
+
print(f" P={claim.opinion.projected_probability():.3f}")
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from trustandverify._version import __version__
|
|
18
|
+
from trustandverify.core.agent import TrustAgent
|
|
19
|
+
from trustandverify.core.config import TrustConfig
|
|
20
|
+
from trustandverify.core.models import Claim, Conflict, Evidence, Report, Source, Verdict
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def verify(
|
|
24
|
+
query: str,
|
|
25
|
+
*,
|
|
26
|
+
num_claims: int = 0,
|
|
27
|
+
verbose: bool = False,
|
|
28
|
+
) -> Report:
|
|
29
|
+
"""One-liner verification using auto-configured backends from env vars.
|
|
30
|
+
|
|
31
|
+
Requires ``GEMINI_API_KEY`` and ``TAVILY_API_KEY`` environment variables.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
query: The research question or claim to verify.
|
|
35
|
+
num_claims: Number of claims to decompose into (0 = LLM decides).
|
|
36
|
+
verbose: Print step-by-step progress to stdout.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
A fully populated Report.
|
|
40
|
+
|
|
41
|
+
Example::
|
|
42
|
+
|
|
43
|
+
import asyncio
|
|
44
|
+
report = asyncio.run(verify("Is coffee healthy?"))
|
|
45
|
+
"""
|
|
46
|
+
from trustandverify.llm.gemini import GeminiBackend
|
|
47
|
+
from trustandverify.search.tavily import TavilySearch
|
|
48
|
+
|
|
49
|
+
agent = TrustAgent(
|
|
50
|
+
config=TrustConfig(num_claims=num_claims),
|
|
51
|
+
search=TavilySearch(),
|
|
52
|
+
llm=GeminiBackend(),
|
|
53
|
+
)
|
|
54
|
+
return await agent.verify(query, verbose=verbose)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
"__version__",
|
|
59
|
+
"verify",
|
|
60
|
+
"TrustAgent",
|
|
61
|
+
"TrustConfig",
|
|
62
|
+
"Report",
|
|
63
|
+
"Claim",
|
|
64
|
+
"Conflict",
|
|
65
|
+
"Evidence",
|
|
66
|
+
"Source",
|
|
67
|
+
"Verdict",
|
|
68
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""CacheBackend protocol — caching layer for search results and LLM responses."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Protocol, runtime_checkable
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@runtime_checkable
|
|
9
|
+
class CacheBackend(Protocol):
|
|
10
|
+
"""Structural protocol for cache providers.
|
|
11
|
+
|
|
12
|
+
The cache sits between the agent and the search/LLM backends.
|
|
13
|
+
Same query + same backend = cached result. Configurable TTL.
|
|
14
|
+
Saves API quota and speeds up repeated demos.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
async def get(self, key: str) -> Any | None:
|
|
18
|
+
"""Retrieve a cached value, or None if missing/expired.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
key: Cache key.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
The cached value, or None.
|
|
25
|
+
"""
|
|
26
|
+
...
|
|
27
|
+
|
|
28
|
+
async def set(self, key: str, value: Any, ttl: int | None = None) -> None:
|
|
29
|
+
"""Store a value in the cache.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
key: Cache key.
|
|
33
|
+
value: Value to store (must be JSON-serialisable for
|
|
34
|
+
file/Redis backends).
|
|
35
|
+
ttl: Time-to-live in seconds. None = use backend default.
|
|
36
|
+
"""
|
|
37
|
+
...
|
|
38
|
+
|
|
39
|
+
async def invalidate(self, key: str) -> None:
|
|
40
|
+
"""Remove a specific key from the cache."""
|
|
41
|
+
...
|
|
File without changes
|