driftguard-ai 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.
Files changed (56) hide show
  1. driftguard_ai-0.1.0/LICENSE +21 -0
  2. driftguard_ai-0.1.0/PKG-INFO +496 -0
  3. driftguard_ai-0.1.0/README.md +449 -0
  4. driftguard_ai-0.1.0/pyproject.toml +102 -0
  5. driftguard_ai-0.1.0/setup.cfg +4 -0
  6. driftguard_ai-0.1.0/src/driftguard/__init__.py +44 -0
  7. driftguard_ai-0.1.0/src/driftguard/adapters/__init__.py +2 -0
  8. driftguard_ai-0.1.0/src/driftguard/adapters/generic.py +32 -0
  9. driftguard_ai-0.1.0/src/driftguard/adapters/langgraph.py +46 -0
  10. driftguard_ai-0.1.0/src/driftguard/benchmark.py +352 -0
  11. driftguard_ai-0.1.0/src/driftguard/config.py +39 -0
  12. driftguard_ai-0.1.0/src/driftguard/embedding/__init__.py +0 -0
  13. driftguard_ai-0.1.0/src/driftguard/embedding/embedding_engine.py +108 -0
  14. driftguard_ai-0.1.0/src/driftguard/errors.py +22 -0
  15. driftguard_ai-0.1.0/src/driftguard/evaluation.py +186 -0
  16. driftguard_ai-0.1.0/src/driftguard/graph/__init__.py +0 -0
  17. driftguard_ai-0.1.0/src/driftguard/graph/graph_store.py +278 -0
  18. driftguard_ai-0.1.0/src/driftguard/graph/merge_engine.py +173 -0
  19. driftguard_ai-0.1.0/src/driftguard/graph/prune_engine.py +155 -0
  20. driftguard_ai-0.1.0/src/driftguard/guard.py +268 -0
  21. driftguard_ai-0.1.0/src/driftguard/logging_config.py +50 -0
  22. driftguard_ai-0.1.0/src/driftguard/mcp.py +95 -0
  23. driftguard_ai-0.1.0/src/driftguard/metrics.py +87 -0
  24. driftguard_ai-0.1.0/src/driftguard/models/__init__.py +0 -0
  25. driftguard_ai-0.1.0/src/driftguard/models/event.py +22 -0
  26. driftguard_ai-0.1.0/src/driftguard/models/response.py +22 -0
  27. driftguard_ai-0.1.0/src/driftguard/retrieval/__init__.py +0 -0
  28. driftguard_ai-0.1.0/src/driftguard/retrieval/retrieval_engine.py +210 -0
  29. driftguard_ai-0.1.0/src/driftguard/runtime.py +174 -0
  30. driftguard_ai-0.1.0/src/driftguard/server.py +22 -0
  31. driftguard_ai-0.1.0/src/driftguard/storage/__init__.py +0 -0
  32. driftguard_ai-0.1.0/src/driftguard/storage/base.py +13 -0
  33. driftguard_ai-0.1.0/src/driftguard/storage/persistence.py +180 -0
  34. driftguard_ai-0.1.0/src/driftguard/storage/sqlite_persistence.py +244 -0
  35. driftguard_ai-0.1.0/src/driftguard/utils/__init__.py +0 -0
  36. driftguard_ai-0.1.0/src/driftguard/utils/normalization.py +58 -0
  37. driftguard_ai-0.1.0/src/driftguard/utils/similarity.py +15 -0
  38. driftguard_ai-0.1.0/src/driftguard_ai.egg-info/PKG-INFO +496 -0
  39. driftguard_ai-0.1.0/src/driftguard_ai.egg-info/SOURCES.txt +54 -0
  40. driftguard_ai-0.1.0/src/driftguard_ai.egg-info/dependency_links.txt +1 -0
  41. driftguard_ai-0.1.0/src/driftguard_ai.egg-info/entry_points.txt +3 -0
  42. driftguard_ai-0.1.0/src/driftguard_ai.egg-info/requires.txt +24 -0
  43. driftguard_ai-0.1.0/src/driftguard_ai.egg-info/top_level.txt +1 -0
  44. driftguard_ai-0.1.0/tests/test_benchmark_cli.py +72 -0
  45. driftguard_ai-0.1.0/tests/test_demo_agent.py +151 -0
  46. driftguard_ai-0.1.0/tests/test_dependency_failures.py +72 -0
  47. driftguard_ai-0.1.0/tests/test_evaluation.py +176 -0
  48. driftguard_ai-0.1.0/tests/test_guard.py +265 -0
  49. driftguard_ai-0.1.0/tests/test_langgraph_demo.py +64 -0
  50. driftguard_ai-0.1.0/tests/test_metrics_adapters.py +113 -0
  51. driftguard_ai-0.1.0/tests/test_persistence_hardening.py +120 -0
  52. driftguard_ai-0.1.0/tests/test_pipeline.py +268 -0
  53. driftguard_ai-0.1.0/tests/test_project_metadata.py +122 -0
  54. driftguard_ai-0.1.0/tests/test_retrieval_precision.py +169 -0
  55. driftguard_ai-0.1.0/tests/test_runtime_mcp.py +328 -0
  56. driftguard_ai-0.1.0/tests/test_sqlite_persistence.py +115 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sujal maheshwari
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,496 @@
1
+ Metadata-Version: 2.4
2
+ Name: driftguard-ai
3
+ Version: 0.1.0
4
+ Summary: A semantic mistake-memory system for AI agents with MCP and in-process guardrail entrypoints.
5
+ Author-email: Sujal Maheshwari <sujalmaheshwari07@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sujal-maheshwari2004/DriftGuard
8
+ Project-URL: Repository, https://github.com/sujal-maheshwari2004/DriftGuard
9
+ Project-URL: Issues, https://github.com/sujal-maheshwari2004/DriftGuard/issues
10
+ Keywords: agents,mcp,memory,guardrails,retrieval,langgraph,agent-safety,ai-infrastructure
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
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
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: fastmcp>=3.2.0
26
+ Requires-Dist: networkx>=3.0
27
+ Requires-Dist: numpy>=1.24
28
+ Requires-Dist: orjson>=3.9
29
+ Requires-Dist: pydantic>=2.0
30
+ Requires-Dist: python-dateutil>=2.8
31
+ Requires-Dist: rich>=13.0
32
+ Requires-Dist: sentence-transformers>=2.6
33
+ Requires-Dist: spacy>=3.7
34
+ Requires-Dist: sqlite-utils>=3.35
35
+ Requires-Dist: tenacity>=8.0
36
+ Provides-Extra: test
37
+ Requires-Dist: pytest>=7.0; extra == "test"
38
+ Provides-Extra: demo
39
+ Requires-Dist: langchain-openai>=0.3.0; extra == "demo"
40
+ Requires-Dist: langgraph>=0.2.60; extra == "demo"
41
+ Provides-Extra: dev
42
+ Requires-Dist: build>=1.2.2; extra == "dev"
43
+ Requires-Dist: pytest>=7.0; extra == "dev"
44
+ Requires-Dist: langchain-openai>=0.3.0; extra == "dev"
45
+ Requires-Dist: langgraph>=0.2.60; extra == "dev"
46
+ Dynamic: license-file
47
+
48
+ # DriftGuard
49
+
50
+ **DriftGuard** is a semantic mistake-memory and guardrail layer for autonomous agents.
51
+
52
+ It sits between **intent** and **execution**, allowing agents to learn from past failures and avoid repeating them.
53
+
54
+ DriftGuard stores structured causal memories:
55
+
56
+ ```
57
+ action → feedback → outcome
58
+ ```
59
+
60
+ and surfaces warnings when similar risky actions appear again.
61
+
62
+ It works with:
63
+
64
+ * MCP agents
65
+ * LangGraph workflows
66
+ * custom Python agents
67
+ * tool-calling planners
68
+ * autonomous pipelines
69
+
70
+ ---
71
+
72
+ ## Why DriftGuard Exists
73
+
74
+ Agents today can act.
75
+
76
+ They usually cannot **remember mistakes meaningfully**.
77
+
78
+ Typical failure loop:
79
+
80
+ ```
81
+ agent makes mistake
82
+ agent retries
83
+ agent repeats mistake
84
+ agent retries again
85
+ ```
86
+
87
+ DriftGuard introduces a semantic failure memory layer:
88
+
89
+ ```
90
+ plan step
91
+
92
+ DriftGuard review
93
+
94
+ warning surfaced
95
+
96
+ agent revises action
97
+ ```
98
+
99
+ This improves:
100
+
101
+ * stability
102
+ * reliability
103
+ * convergence speed
104
+ * evaluation consistency
105
+ * production safety
106
+
107
+ without requiring changes to your planner architecture.
108
+
109
+ ---
110
+
111
+ ## What DriftGuard Does
112
+
113
+ DriftGuard provides:
114
+
115
+ • semantic mistake memory
116
+ • similarity-aware warning retrieval
117
+ • policy-based execution guardrails
118
+ • merge + deduplicate memory graphs
119
+ • JSON or SQLite persistence
120
+ • runtime metrics
121
+ • pruning of stale weak memories
122
+ • MCP server integration
123
+ • LangGraph adapters
124
+ • offline benchmark harness
125
+
126
+ ---
127
+
128
+ ## Installation
129
+
130
+ Install from PyPI:
131
+
132
+ ```bash
133
+ pip install driftguard
134
+ ```
135
+
136
+ Install test dependencies:
137
+
138
+ ```bash
139
+ pip install "driftguard[test]"
140
+ ```
141
+
142
+ Install LangGraph demo dependencies:
143
+
144
+ ```bash
145
+ pip install "driftguard[demo]"
146
+ ```
147
+
148
+ Install the spaCy normalization model:
149
+
150
+ ```bash
151
+ python -m spacy download en_core_web_sm
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Quick Example (Python Agent)
157
+
158
+ ```python
159
+ from driftguard import DriftGuard
160
+
161
+ guard = DriftGuard()
162
+
163
+ review = guard.before_step("increase salt")
164
+
165
+ if review.warnings:
166
+ print(review.warnings[0].risk)
167
+
168
+ guard.record(
169
+ action="increase salt",
170
+ feedback="too salty",
171
+ outcome="dish ruined",
172
+ )
173
+ ```
174
+
175
+ DriftGuard now remembers this failure and warns on similar steps later.
176
+
177
+ ---
178
+
179
+ ## Guard Policies
180
+
181
+ Control how the agent reacts to detected risks:
182
+
183
+ ```python
184
+ from driftguard import DriftGuard, DriftGuardSettings
185
+
186
+ guard = DriftGuard(
187
+ settings=DriftGuardSettings(
188
+ guard_policy="acknowledge",
189
+ guard_min_confidence=0.8,
190
+ )
191
+ )
192
+ ```
193
+
194
+ Supported modes:
195
+
196
+ | policy | behavior |
197
+ | ----------- | ---------------------------- |
198
+ | warn | surface warning only |
199
+ | block | raise exception |
200
+ | acknowledge | require confirmation |
201
+ | record_only | store memory but skip review |
202
+
203
+ ---
204
+
205
+ ## MCP Server Usage
206
+
207
+ Run DriftGuard as an MCP server:
208
+
209
+ ```bash
210
+ driftguard-mcp
211
+ ```
212
+
213
+ Available tools:
214
+
215
+ ```
216
+ register_mistake
217
+ query_memory
218
+ deep_prune
219
+ graph_stats
220
+ guard_metrics
221
+ ```
222
+
223
+ Example Claude Desktop config:
224
+
225
+ ```json
226
+ {
227
+ "mcpServers": {
228
+ "driftguard": {
229
+ "command": "driftguard-mcp"
230
+ }
231
+ }
232
+ }
233
+ ```
234
+
235
+ ---
236
+
237
+ ## LangGraph Integration
238
+
239
+ Create a review node inside a LangGraph workflow:
240
+
241
+ ```python
242
+ from driftguard import DriftGuard
243
+ from driftguard import make_langgraph_review_node
244
+
245
+ guard = DriftGuard()
246
+
247
+ review_node = make_langgraph_review_node(guard)
248
+ ```
249
+
250
+ Drop this node directly into a planner graph.
251
+
252
+ ---
253
+
254
+ ## Generic Payload Adapter
255
+
256
+ Review arbitrary planner payloads:
257
+
258
+ ```python
259
+ from driftguard import DriftGuard, review_payload
260
+
261
+ guard = DriftGuard()
262
+
263
+ result = review_payload(
264
+ guard,
265
+ {"action": "increase salt", "attempt": 2},
266
+ )
267
+ ```
268
+
269
+ ---
270
+
271
+ ## CLI Benchmark Tool
272
+
273
+ Evaluate merge and retrieval quality:
274
+
275
+ ```bash
276
+ driftguard-benchmark
277
+ ```
278
+
279
+ Export structured results:
280
+
281
+ ```bash
282
+ driftguard-benchmark --format json
283
+ ```
284
+
285
+ Measures:
286
+
287
+ * merge precision
288
+ * merge recall
289
+ * retrieval precision
290
+ * retrieval recall
291
+ * F1 score
292
+
293
+ ---
294
+
295
+ ## Storage Model
296
+
297
+ DriftGuard uses:
298
+
299
+ ```
300
+ in-memory semantic graph runtime
301
+ +
302
+ persistent storage backend
303
+ ```
304
+
305
+ Supported persistence:
306
+
307
+ | backend | purpose |
308
+ | ------- | -------------------- |
309
+ | JSON | local experiments |
310
+ | SQLite | production workflows |
311
+
312
+ Example configuration:
313
+
314
+ ```python
315
+ from driftguard import DriftGuardSettings
316
+
317
+ settings = DriftGuardSettings(
318
+ storage_backend="sqlite",
319
+ sqlite_filepath="driftguard.sqlite3",
320
+ )
321
+ ```
322
+
323
+ ---
324
+
325
+ ## Metrics and Observability
326
+
327
+ Runtime metrics available:
328
+
329
+ ```python
330
+ from driftguard import build_runtime
331
+
332
+ runtime = build_runtime()
333
+
334
+ snapshot = runtime.metrics_snapshot()
335
+
336
+ print(snapshot["counters"])
337
+ ```
338
+
339
+ Includes:
340
+
341
+ ```
342
+ reviews
343
+ warnings
344
+ blocks
345
+ acknowledgements
346
+ records
347
+ node reuse
348
+ edge reuse
349
+ prune activity
350
+ ```
351
+
352
+ Also available via MCP:
353
+
354
+ ```
355
+ guard_metrics
356
+ ```
357
+
358
+ ---
359
+
360
+ ## Example Architecture Placement
361
+
362
+ Typical agent loop:
363
+
364
+ ```
365
+ planner
366
+
367
+ candidate action
368
+
369
+ DriftGuard review
370
+
371
+ warning surfaced
372
+
373
+ planner revision
374
+
375
+ execution
376
+
377
+ feedback recorded
378
+ ```
379
+
380
+ DriftGuard improves stability without replacing the planner.
381
+
382
+ ---
383
+
384
+ ## Local Demos
385
+
386
+ Two included demos:
387
+
388
+ ### Rule-based simulator
389
+
390
+ Offline deterministic walkthrough:
391
+
392
+ ```bash
393
+ python demo/rule_based/demo_agent.py
394
+ ```
395
+
396
+ Shows:
397
+
398
+ * merge behavior
399
+ * warning retrieval
400
+ * pruning cleanup
401
+ * graph evolution
402
+
403
+ ---
404
+
405
+ ### LangGraph LLM agent demo
406
+
407
+ ```bash
408
+ pip install "driftguard[demo]"
409
+ python demo/langgraph/demo_agent.py
410
+ ```
411
+
412
+ Demonstrates:
413
+
414
+ planner → guard → revise → execute loop
415
+
416
+ with real model interaction.
417
+
418
+ ---
419
+
420
+ ## CLI Entry Points
421
+
422
+ Installed automatically:
423
+
424
+ ```
425
+ driftguard-mcp
426
+ driftguard-benchmark
427
+ ```
428
+
429
+ ---
430
+
431
+ ## Configuration Surface
432
+
433
+ Example advanced setup:
434
+
435
+ ```python
436
+ from driftguard import DriftGuardSettings
437
+
438
+ settings = DriftGuardSettings(
439
+ retrieval_top_k=5,
440
+ retrieval_min_similarity=0.60,
441
+ similarity_threshold_action=0.72,
442
+ guard_policy="warn",
443
+ )
444
+ ```
445
+
446
+ Full configuration supports:
447
+
448
+ ```
449
+ retrieval tuning
450
+ similarity thresholds
451
+ guard policy modes
452
+ storage backend selection
453
+ embedding configuration
454
+ graph pruning controls
455
+ logging verbosity
456
+ ```
457
+
458
+ ---
459
+
460
+ ## When To Use DriftGuard
461
+
462
+ DriftGuard helps when your agent:
463
+
464
+ * retries failing steps repeatedly
465
+ * forgets past execution errors
466
+ * needs execution-time guardrails
467
+ * requires semantic mistake recall
468
+ * runs multi-step planners
469
+ * uses LangGraph or MCP
470
+ * executes tools autonomously
471
+
472
+ ---
473
+
474
+ ## Project Status
475
+
476
+ Current release includes:
477
+
478
+ * semantic merge engine
479
+ * similarity retrieval engine
480
+ * graph persistence layer
481
+ * SQLite backend
482
+ * MCP server
483
+ * LangGraph adapter
484
+ * benchmark harness
485
+ * runtime metrics
486
+ * pruning engine
487
+ * deterministic demo runtime
488
+ * pytest coverage
489
+
490
+ DriftGuard is suitable for early production experimentation and agent-infrastructure research workflows.
491
+
492
+ ---
493
+
494
+ ## License
495
+
496
+ MIT License