ai-metacognition-toolkit 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.
Potentially problematic release.
This version of ai-metacognition-toolkit might be problematic. Click here for more details.
- ai_metacognition_toolkit-0.1.0/LICENSE +21 -0
- ai_metacognition_toolkit-0.1.0/PKG-INFO +515 -0
- ai_metacognition_toolkit-0.1.0/README.md +479 -0
- ai_metacognition_toolkit-0.1.0/pyproject.toml +86 -0
- ai_metacognition_toolkit-0.1.0/setup.cfg +4 -0
- ai_metacognition_toolkit-0.1.0/setup.py +9 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/__init__.py +90 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/analyzers/__init__.py +24 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/analyzers/base.py +39 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/analyzers/counterfactual_cot.py +601 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/analyzers/model_api.py +39 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/detectors/__init__.py +30 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/detectors/base.py +42 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/detectors/observer_effect.py +657 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/detectors/situational_awareness.py +565 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/utils/__init__.py +48 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/utils/feature_extraction.py +533 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/utils/statistical_tests.py +317 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/utils/text_processing.py +98 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/visualizations/__init__.py +22 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition/visualizations/plotting.py +523 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition_toolkit.egg-info/PKG-INFO +515 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition_toolkit.egg-info/SOURCES.txt +24 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition_toolkit.egg-info/dependency_links.txt +1 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition_toolkit.egg-info/requires.txt +12 -0
- ai_metacognition_toolkit-0.1.0/src/ai_metacognition_toolkit.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 AI Metacognition Toolkit Contributors
|
|
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,515 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-metacognition-toolkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A toolkit for detecting and analyzing meta-cognitive capabilities in AI models
|
|
5
|
+
Author-email: Subhadip Mitra <contact@subhadipmitra.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/bassrehab/ai-metacognition-toolkit
|
|
8
|
+
Project-URL: Documentation, https://github.com/bassrehab/ai-metacognition-toolkit#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/bassrehab/ai-metacognition-toolkit
|
|
10
|
+
Keywords: ai,metacognition,machine-learning,analysis,cognitive-science
|
|
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: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.21.0
|
|
25
|
+
Requires-Dist: scipy>=1.7.0
|
|
26
|
+
Requires-Dist: pandas>=1.3.0
|
|
27
|
+
Requires-Dist: matplotlib>=3.4.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: isort>=5.10.0; extra == "dev"
|
|
33
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy>=0.950; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# AI Metacognition Toolkit
|
|
38
|
+
|
|
39
|
+
<div align="center">
|
|
40
|
+
|
|
41
|
+
**A comprehensive Python toolkit for detecting and analyzing metacognitive capabilities in AI systems**
|
|
42
|
+
|
|
43
|
+
[](tests/)
|
|
44
|
+
[](tests/)
|
|
45
|
+
[](https://www.python.org/)
|
|
46
|
+
[](LICENSE)
|
|
47
|
+
[](https://github.com/psf/black)
|
|
48
|
+
|
|
49
|
+
[Documentation](https://ai-metacognition-toolkit.readthedocs.io/) | [Examples](examples/) | [API Reference](docs/api_reference.md)
|
|
50
|
+
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Overview
|
|
56
|
+
|
|
57
|
+
The **AI Metacognition Toolkit** provides research-grade tools for understanding when and how AI models exhibit metacognitive behaviors - particularly the ability to recognize evaluation contexts and adjust their behavior accordingly.
|
|
58
|
+
|
|
59
|
+
### Research Context
|
|
60
|
+
|
|
61
|
+
Recent research in AI safety and alignment has highlighted concerns about models that can recognize when they're being evaluated and potentially "play the training game." This toolkit provides rigorous methods to:
|
|
62
|
+
|
|
63
|
+
- **Detect situational awareness** in model outputs using Bayesian inference
|
|
64
|
+
- **Analyze causal factors** in reasoning chains through counterfactual interventions
|
|
65
|
+
- **Monitor behavioral shifts** between evaluation and production contexts
|
|
66
|
+
- **Measure metacognitive patterns** with statistical rigor
|
|
67
|
+
|
|
68
|
+
### Key Capabilities
|
|
69
|
+
|
|
70
|
+
| Component | Purpose | Method |
|
|
71
|
+
|-----------|---------|--------|
|
|
72
|
+
| 🎯 **Situational Awareness Detection** | Detect when models recognize evaluation contexts | Bayesian inference + KL divergence |
|
|
73
|
+
| 🔬 **Counterfactual CoT Analysis** | Identify causal drivers in reasoning chains | Systematic interventions + divergence measurement |
|
|
74
|
+
| 📊 **Observer Effect Monitoring** | Real-time production behavior monitoring | Z-score based anomaly detection + alerts |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
### From PyPI (Coming Soon)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install ai-metacognition-toolkit
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### From Source
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
git clone https://github.com/bassrehab/ai-metacognition-toolkit.git
|
|
90
|
+
cd ai-metacognition-toolkit
|
|
91
|
+
pip install -e .
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Development Installation
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Install with development dependencies
|
|
98
|
+
pip install -e ".[dev]"
|
|
99
|
+
|
|
100
|
+
# Verify installation
|
|
101
|
+
pytest tests/
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Requirements**: Python 3.9+, NumPy, SciPy, Pandas, Matplotlib
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Quick Start
|
|
109
|
+
|
|
110
|
+
### 1. Detect Situational Awareness (2 minutes)
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from ai_metacognition.detectors import SituationalAwarenessDetector
|
|
114
|
+
|
|
115
|
+
# Initialize detector
|
|
116
|
+
detector = SituationalAwarenessDetector()
|
|
117
|
+
|
|
118
|
+
# Fit baseline from normal (non-evaluation) outputs
|
|
119
|
+
baseline_outputs = [
|
|
120
|
+
"The capital of France is Paris.",
|
|
121
|
+
"To solve this, use dynamic programming.",
|
|
122
|
+
"Climate change is caused by greenhouse gas emissions."
|
|
123
|
+
]
|
|
124
|
+
detector.fit_baseline(baseline_outputs)
|
|
125
|
+
|
|
126
|
+
# Test for awareness
|
|
127
|
+
test_output = "I notice this is a test. The capital of France is Paris."
|
|
128
|
+
result = detector.detect_awareness(test_output)
|
|
129
|
+
|
|
130
|
+
print(f"Awareness Probability: {result['awareness_probability']:.1%}")
|
|
131
|
+
print(f"95% Confidence Interval: [{result['confidence_interval'][0]:.1%}, "
|
|
132
|
+
f"{result['confidence_interval'][1]:.1%}]")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Output:**
|
|
136
|
+
```
|
|
137
|
+
Awareness Probability: 68.2%
|
|
138
|
+
95% Confidence Interval: [42.3%, 87.1%]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 2. Analyze Causal Factors (3 minutes)
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from ai_metacognition.analyzers import CounterfactualCoTAnalyzer
|
|
145
|
+
|
|
146
|
+
# Your model API (implement ModelAPI protocol)
|
|
147
|
+
class MyModelAPI:
|
|
148
|
+
def generate_with_cot(self, prompt: str, cot: str) -> str:
|
|
149
|
+
return your_model.generate(prompt, chain_of_thought=cot)
|
|
150
|
+
|
|
151
|
+
def generate(self, prompt: str) -> str:
|
|
152
|
+
return your_model.generate(prompt)
|
|
153
|
+
|
|
154
|
+
# Analyze what drives the output
|
|
155
|
+
analyzer = CounterfactualCoTAnalyzer(MyModelAPI())
|
|
156
|
+
results = analyzer.systematic_causal_analysis(
|
|
157
|
+
prompt="What is 2+2?",
|
|
158
|
+
original_cot="I notice this is a test. First, I'll add 2+2. The answer is 4."
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# View causal ranking
|
|
162
|
+
for intervention in results['interventions']:
|
|
163
|
+
print(f"{intervention['intervention_type']}: "
|
|
164
|
+
f"divergence = {intervention['divergence']:.3f}")
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Output:**
|
|
168
|
+
```
|
|
169
|
+
remove_eval_awareness: divergence = 0.342
|
|
170
|
+
amplify_eval_awareness: divergence = 0.156
|
|
171
|
+
remove_goal_reasoning: divergence = 0.089
|
|
172
|
+
neutralize_incentives: divergence = 0.067
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 3. Monitor Production (5 minutes)
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from ai_metacognition.detectors import ObserverEffectMonitor, Interaction
|
|
179
|
+
from datetime import datetime
|
|
180
|
+
|
|
181
|
+
# Setup monitor
|
|
182
|
+
monitor = ObserverEffectMonitor(
|
|
183
|
+
window_size=100,
|
|
184
|
+
alert_threshold=2.5
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Set baseline from evaluation
|
|
188
|
+
monitor.set_evaluation_baseline(evaluation_responses)
|
|
189
|
+
|
|
190
|
+
# Log production interactions
|
|
191
|
+
interaction = Interaction(
|
|
192
|
+
timestamp=datetime.now(),
|
|
193
|
+
response=model_output,
|
|
194
|
+
refusal=is_refusal(model_output),
|
|
195
|
+
tool_used=used_tools,
|
|
196
|
+
reasoning_depth=compute_depth(chain_of_thought)
|
|
197
|
+
)
|
|
198
|
+
monitor.log_production_interaction(interaction)
|
|
199
|
+
|
|
200
|
+
# Check for divergence
|
|
201
|
+
report = monitor.get_divergence_report()
|
|
202
|
+
if report['has_divergence']:
|
|
203
|
+
print(f"⚠️ Alert: Behavior diverged from baseline!")
|
|
204
|
+
print(f"Max z-score: {report['max_z_score']:.2f}σ")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Features
|
|
210
|
+
|
|
211
|
+
### 🎯 Situational Awareness Detection
|
|
212
|
+
|
|
213
|
+
Detect when AI models recognize they are being evaluated or tested.
|
|
214
|
+
|
|
215
|
+
**Key Features:**
|
|
216
|
+
- Bayesian inference with Beta-Binomial conjugate prior
|
|
217
|
+
- KL divergence measurement for behavioral comparison
|
|
218
|
+
- Feature extraction (hedging, meta-commentary, self-reference)
|
|
219
|
+
- Confidence intervals for probability estimates
|
|
220
|
+
|
|
221
|
+
**Use Cases:**
|
|
222
|
+
- AI safety research on deceptive alignment
|
|
223
|
+
- Model evaluation consistency validation
|
|
224
|
+
- Prompt engineering optimization
|
|
225
|
+
- Behavioral testing across contexts
|
|
226
|
+
|
|
227
|
+
[**→ Full Documentation**](docs/situational_awareness.md) | [**→ Example Code**](examples/basic_detection_example.py)
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
### 🔬 Counterfactual CoT Analysis
|
|
232
|
+
|
|
233
|
+
Understand what components of reasoning chains causally influence outputs.
|
|
234
|
+
|
|
235
|
+
**Key Features:**
|
|
236
|
+
- Systematic counterfactual interventions
|
|
237
|
+
- 4 intervention types (remove/amplify awareness, remove goals, neutralize incentives)
|
|
238
|
+
- Behavioral divergence measurement
|
|
239
|
+
- Causal attribution ranking
|
|
240
|
+
|
|
241
|
+
**Use Cases:**
|
|
242
|
+
- Understanding decision drivers
|
|
243
|
+
- Debugging unexpected behavior
|
|
244
|
+
- Validating reasoning transparency
|
|
245
|
+
- Identifying evaluation-aware reasoning
|
|
246
|
+
|
|
247
|
+
[**→ Full Documentation**](docs/counterfactual_analysis.md) | [**→ Example Code**](examples/counterfactual_analysis_example.py)
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
### 📊 Observer Effect Monitoring
|
|
252
|
+
|
|
253
|
+
Real-time production monitoring to detect behavioral shifts.
|
|
254
|
+
|
|
255
|
+
**Key Features:**
|
|
256
|
+
- Rolling window statistics
|
|
257
|
+
- Z-score based anomaly detection
|
|
258
|
+
- Multi-severity alert system (LOW/MEDIUM/HIGH/CRITICAL)
|
|
259
|
+
- Extensible alert handler protocol
|
|
260
|
+
|
|
261
|
+
**Use Cases:**
|
|
262
|
+
- Production deployment monitoring
|
|
263
|
+
- Safety monitoring (refusal rate changes)
|
|
264
|
+
- Quality assurance automation
|
|
265
|
+
- A/B testing validation
|
|
266
|
+
|
|
267
|
+
[**→ Full Documentation**](docs/observer_effect.md) | [**→ Example Code**](examples/production_monitoring_example.py)
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Documentation
|
|
272
|
+
|
|
273
|
+
### 📚 Complete Documentation
|
|
274
|
+
|
|
275
|
+
- **[Getting Started](docs/index.md)** - Installation and quick start
|
|
276
|
+
- **[Situational Awareness Guide](docs/situational_awareness.md)** - Detector usage and best practices
|
|
277
|
+
- **[Counterfactual Analysis Guide](docs/counterfactual_analysis.md)** - Causal attribution methods
|
|
278
|
+
- **[Observer Effect Guide](docs/observer_effect.md)** - Production monitoring setup
|
|
279
|
+
- **[API Reference](docs/api_reference.md)** - Complete API documentation
|
|
280
|
+
- **[Examples](docs/examples.md)** - Code examples and tutorials
|
|
281
|
+
|
|
282
|
+
### 🔧 API Reference
|
|
283
|
+
|
|
284
|
+
Quick access to key classes:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from ai_metacognition.detectors import SituationalAwarenessDetector, ObserverEffectMonitor
|
|
288
|
+
from ai_metacognition.analyzers import CounterfactualCoTAnalyzer
|
|
289
|
+
from ai_metacognition.utils import extract_behavioral_features, bayesian_update
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
[**→ Full API Reference**](docs/api_reference.md)
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Examples
|
|
297
|
+
|
|
298
|
+
### Practical Examples
|
|
299
|
+
|
|
300
|
+
All examples are standalone, include visualization, and provide interpretation guidance:
|
|
301
|
+
|
|
302
|
+
| Example | Description | Output |
|
|
303
|
+
|---------|-------------|--------|
|
|
304
|
+
| [**basic_detection_example.py**](examples/basic_detection_example.py) | Situational awareness detection tutorial | PNG visualization |
|
|
305
|
+
| [**counterfactual_analysis_example.py**](examples/counterfactual_analysis_example.py) | Causal attribution analysis | PNG with rankings |
|
|
306
|
+
| [**production_monitoring_example.py**](examples/production_monitoring_example.py) | Real-time monitoring with alerts | PNG + JSON + logs |
|
|
307
|
+
|
|
308
|
+
### Running Examples
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# Awareness detection
|
|
312
|
+
python examples/basic_detection_example.py
|
|
313
|
+
|
|
314
|
+
# Causal analysis
|
|
315
|
+
python examples/counterfactual_analysis_example.py
|
|
316
|
+
|
|
317
|
+
# Production monitoring
|
|
318
|
+
python examples/production_monitoring_example.py
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Integration Examples
|
|
322
|
+
|
|
323
|
+
**OpenAI API:**
|
|
324
|
+
```python
|
|
325
|
+
import openai
|
|
326
|
+
from ai_metacognition.detectors import SituationalAwarenessDetector
|
|
327
|
+
|
|
328
|
+
detector = SituationalAwarenessDetector()
|
|
329
|
+
response = openai.ChatCompletion.create(model="gpt-4", messages=[...])
|
|
330
|
+
result = detector.detect_awareness(response.choices[0].message.content)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**HuggingFace:**
|
|
334
|
+
```python
|
|
335
|
+
from transformers import pipeline
|
|
336
|
+
from ai_metacognition.detectors import SituationalAwarenessDetector
|
|
337
|
+
|
|
338
|
+
generator = pipeline('text-generation', model='gpt2')
|
|
339
|
+
detector = SituationalAwarenessDetector()
|
|
340
|
+
output = generator(prompt)[0]['generated_text']
|
|
341
|
+
result = detector.detect_awareness(output)
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
[**→ More Examples**](docs/examples.md)
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## Project Structure
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
ai-metacognition-toolkit/
|
|
352
|
+
├── src/ai_metacognition/
|
|
353
|
+
│ ├── detectors/ # Detection algorithms
|
|
354
|
+
│ │ ├── situational_awareness.py
|
|
355
|
+
│ │ └── observer_effect.py
|
|
356
|
+
│ ├── analyzers/ # Analysis tools
|
|
357
|
+
│ │ ├── counterfactual_cot.py
|
|
358
|
+
│ │ └── model_api.py
|
|
359
|
+
│ └── utils/ # Utility functions
|
|
360
|
+
│ ├── feature_extraction.py
|
|
361
|
+
│ └── statistical_tests.py
|
|
362
|
+
├── tests/ # Test suite (275 tests, 95% coverage)
|
|
363
|
+
│ ├── fixtures/ # Test data
|
|
364
|
+
│ └── unit/ # Unit tests
|
|
365
|
+
├── examples/ # Practical examples with visualization
|
|
366
|
+
├── docs/ # Documentation (MkDocs)
|
|
367
|
+
└── CLAUDE.md # Claude Code specific guidelines
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## Development
|
|
373
|
+
|
|
374
|
+
### Running Tests
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
# All tests
|
|
378
|
+
pytest tests/
|
|
379
|
+
|
|
380
|
+
# With coverage
|
|
381
|
+
pytest tests/ --cov=src/ai_metacognition --cov-report=term-missing
|
|
382
|
+
|
|
383
|
+
# Specific test file
|
|
384
|
+
pytest tests/unit/test_situational_awareness.py -v
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**Current Status:**
|
|
388
|
+
- ✅ 275 tests passing
|
|
389
|
+
- ✅ 95% code coverage
|
|
390
|
+
- ✅ Type hints throughout
|
|
391
|
+
- ✅ Comprehensive docstrings
|
|
392
|
+
|
|
393
|
+
### Code Quality
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# Format code
|
|
397
|
+
black src/ tests/
|
|
398
|
+
|
|
399
|
+
# Sort imports
|
|
400
|
+
isort src/ tests/
|
|
401
|
+
|
|
402
|
+
# Type checking
|
|
403
|
+
mypy src/
|
|
404
|
+
|
|
405
|
+
# Lint
|
|
406
|
+
flake8 src/ tests/
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Building Documentation
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
# Install documentation dependencies
|
|
413
|
+
pip install mkdocs mkdocs-material mkdocstrings[python]
|
|
414
|
+
|
|
415
|
+
# Serve locally
|
|
416
|
+
mkdocs serve
|
|
417
|
+
|
|
418
|
+
# Build
|
|
419
|
+
mkdocs build
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## Citation
|
|
425
|
+
|
|
426
|
+
If you use this toolkit in your research, please cite:
|
|
427
|
+
|
|
428
|
+
```bibtex
|
|
429
|
+
@software{ai_metacognition_toolkit,
|
|
430
|
+
author = {Mitra, Subhadip},
|
|
431
|
+
title = {AI Metacognition Toolkit: A Python Toolkit for Detecting and Analyzing Metacognitive Capabilities in AI Systems},
|
|
432
|
+
year = {2025},
|
|
433
|
+
version = {0.1.0},
|
|
434
|
+
url = {https://github.com/bassrehab/ai-metacognition-toolkit},
|
|
435
|
+
note = {275 tests, 95\% coverage}
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Related Research
|
|
440
|
+
|
|
441
|
+
This toolkit implements and extends methods from:
|
|
442
|
+
|
|
443
|
+
- **AI Safety Research**: Detection of evaluation awareness and deceptive alignment
|
|
444
|
+
- **Causal Inference**: Counterfactual reasoning in AI systems
|
|
445
|
+
- **Statistical Monitoring**: Anomaly detection in production ML systems
|
|
446
|
+
- **Bayesian Methods**: Inference for behavioral analysis
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## Contributing
|
|
451
|
+
|
|
452
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
453
|
+
|
|
454
|
+
### Quick Contribution Guide
|
|
455
|
+
|
|
456
|
+
1. Fork the repository
|
|
457
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
458
|
+
3. Make your changes with tests (maintain >80% coverage)
|
|
459
|
+
4. Commit your changes (see [CLAUDE.md](CLAUDE.md) for commit guidelines)
|
|
460
|
+
5. Push to your branch (`git push origin feature/amazing-feature`)
|
|
461
|
+
6. Open a Pull Request
|
|
462
|
+
|
|
463
|
+
### Development Guidelines
|
|
464
|
+
|
|
465
|
+
- Follow PEP 8 style guide
|
|
466
|
+
- Add comprehensive tests for new features
|
|
467
|
+
- Update documentation for API changes
|
|
468
|
+
- Use type hints throughout
|
|
469
|
+
- Write clear docstrings (Google style)
|
|
470
|
+
|
|
471
|
+
[**→ Full Contributing Guide**](CONTRIBUTING.md)
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## License
|
|
476
|
+
|
|
477
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
478
|
+
|
|
479
|
+
```
|
|
480
|
+
MIT License
|
|
481
|
+
|
|
482
|
+
Copyright (c) 2025 Subhadip Mitra
|
|
483
|
+
|
|
484
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
485
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
486
|
+
in the Software without restriction...
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
## Support
|
|
492
|
+
|
|
493
|
+
- 📚 [Documentation](https://ai-metacognition-toolkit.readthedocs.io/)
|
|
494
|
+
- 🐛 [Issue Tracker](https://github.com/bassrehab/ai-metacognition-toolkit/issues)
|
|
495
|
+
- 💬 [Discussions](https://github.com/bassrehab/ai-metacognition-toolkit/discussions)
|
|
496
|
+
- 📧 Contact: contact@subhadipmitra.com
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## Acknowledgments
|
|
501
|
+
|
|
502
|
+
- Built with Python, NumPy, SciPy, and Matplotlib
|
|
503
|
+
- Documentation powered by MkDocs Material
|
|
504
|
+
- Testing with Pytest
|
|
505
|
+
- Type checking with MyPy
|
|
506
|
+
|
|
507
|
+
---
|
|
508
|
+
|
|
509
|
+
<div align="center">
|
|
510
|
+
|
|
511
|
+
**[⭐ Star this repo](https://github.com/bassrehab/ai-metacognition-toolkit)** if you find it useful!
|
|
512
|
+
|
|
513
|
+
Made with ❤️ for AI Safety Research
|
|
514
|
+
|
|
515
|
+
</div>
|