humane-proxy 0.2.2__tar.gz → 0.3.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 (69) hide show
  1. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/PKG-INFO +80 -14
  2. humane_proxy-0.2.2/humane_proxy.egg-info/PKG-INFO → humane_proxy-0.3.0/README.md +67 -58
  3. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/__init__.py +1 -1
  4. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/api/admin.py +166 -2
  5. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/embedding_classifier.py +104 -11
  6. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/pipeline.py +41 -9
  7. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/config.py +17 -0
  8. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/config.yaml +32 -0
  9. humane_proxy-0.3.0/humane_proxy/escalation/local_db.py +68 -0
  10. humane_proxy-0.3.0/humane_proxy/integrations/autogen.py +160 -0
  11. humane_proxy-0.3.0/humane_proxy/integrations/crewai.py +131 -0
  12. humane_proxy-0.3.0/humane_proxy/integrations/llamaindex.py +138 -0
  13. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/mcp_server.py +1 -6
  14. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/middleware/interceptor.py +1 -1
  15. humane_proxy-0.3.0/humane_proxy/storage/__init__.py +15 -0
  16. humane_proxy-0.3.0/humane_proxy/storage/base.py +75 -0
  17. humane_proxy-0.3.0/humane_proxy/storage/factory.py +75 -0
  18. humane_proxy-0.3.0/humane_proxy/storage/postgres.py +212 -0
  19. humane_proxy-0.3.0/humane_proxy/storage/redis.py +193 -0
  20. humane_proxy-0.3.0/humane_proxy/storage/sqlite.py +242 -0
  21. humane_proxy-0.2.2/README.md → humane_proxy-0.3.0/humane_proxy.egg-info/PKG-INFO +124 -12
  22. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy.egg-info/SOURCES.txt +13 -0
  23. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy.egg-info/requires.txt +17 -1
  24. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/pyproject.toml +18 -2
  25. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/server.json +3 -3
  26. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_embedding_classifier.py +84 -2
  27. humane_proxy-0.3.0/tests/test_embedding_singleton.py +77 -0
  28. humane_proxy-0.3.0/tests/test_integrations_smoke.py +76 -0
  29. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_pipeline.py +129 -3
  30. humane_proxy-0.3.0/tests/test_self_harm_threshold.py +51 -0
  31. humane_proxy-0.3.0/tests/test_storage_backends.py +81 -0
  32. humane_proxy-0.2.2/humane_proxy/escalation/local_db.py +0 -170
  33. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/LICENSE +0 -0
  34. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/NOTICE +0 -0
  35. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/api/__init__.py +0 -0
  36. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/__init__.py +0 -0
  37. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/heuristics.py +0 -0
  38. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/models.py +0 -0
  39. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/stage3/__init__.py +0 -0
  40. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/stage3/base.py +0 -0
  41. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/stage3/llamaguard.py +0 -0
  42. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/stage3/openai_chat.py +0 -0
  43. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/classifiers/stage3/openai_moderation.py +0 -0
  44. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/cli.py +0 -0
  45. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/escalation/__init__.py +0 -0
  46. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/escalation/router.py +0 -0
  47. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/escalation/webhooks.py +0 -0
  48. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/integrations/__init__.py +0 -0
  49. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/integrations/langchain.py +0 -0
  50. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/middleware/__init__.py +0 -0
  51. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/risk/__init__.py +0 -0
  52. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy/risk/trajectory.py +0 -0
  53. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy.egg-info/dependency_links.txt +0 -0
  54. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy.egg-info/entry_points.txt +0 -0
  55. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/humane_proxy.egg-info/top_level.txt +0 -0
  56. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/setup.cfg +0 -0
  57. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_admin_api.py +0 -0
  58. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_care_response.py +0 -0
  59. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_cli.py +0 -0
  60. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_config.py +0 -0
  61. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_enhanced_webhooks.py +0 -0
  62. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_heuristics.py +0 -0
  63. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_interceptor.py +0 -0
  64. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_local_db.py +0 -0
  65. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_models.py +0 -0
  66. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_router.py +0 -0
  67. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_stage3.py +0 -0
  68. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_trajectory.py +0 -0
  69. {humane_proxy-0.2.2 → humane_proxy-0.3.0}/tests/test_webhooks.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: humane-proxy
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Lightweight, plug-and-play AI safety middleware that protects humans.
5
5
  Author-email: Vishisht Mishra <Vishisht16@users.noreply.github.com>
6
6
  License: Apache-2.0
@@ -40,8 +40,19 @@ Requires-Dist: humane-proxy[mcp]; extra == "langchain"
40
40
  Requires-Dist: langchain-mcp-adapters>=0.1.0; extra == "langchain"
41
41
  Provides-Extra: webhooks
42
42
  Requires-Dist: httpx>=0.24.0; extra == "webhooks"
43
+ Provides-Extra: redis
44
+ Requires-Dist: redis>=5.0; extra == "redis"
45
+ Provides-Extra: postgres
46
+ Requires-Dist: psycopg[binary]>=3.1; extra == "postgres"
47
+ Requires-Dist: psycopg_pool>=3.1; extra == "postgres"
48
+ Provides-Extra: llamaindex
49
+ Requires-Dist: llama-index-core>=0.10; extra == "llamaindex"
50
+ Provides-Extra: crewai
51
+ Requires-Dist: crewai[tools]>=0.80; extra == "crewai"
52
+ Provides-Extra: autogen
53
+ Requires-Dist: autogen-agentchat>=0.4; extra == "autogen"
43
54
  Provides-Extra: all
44
- Requires-Dist: humane-proxy[langchain,mcp,ml]; extra == "all"
55
+ Requires-Dist: humane-proxy[autogen,crewai,langchain,llamaindex,mcp,ml,postgres,redis]; extra == "all"
45
56
  Dynamic: license-file
46
57
 
47
58
  # 🛡️ HumaneProxy
@@ -56,6 +67,8 @@ HumaneProxy sits between your users and any LLM. When someone expresses self-har
56
67
  [![Python](https://img.shields.io/pypi/pyversions/humane-proxy.svg)](https://pypi.org/project/humane-proxy/)
57
68
  [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
58
69
  [![Tests](https://github.com/Vishisht16/Humane-Proxy/actions/workflows/tests.yaml/badge.svg)](https://github.com/Vishisht16/Humane-Proxy/actions/workflows/tests.yaml)
70
+ [![Humane-Proxy MCP server](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy/badges/score.svg)](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy)
71
+ [![Humane-Proxy MCP server](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy/badges/card.svg)](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy)
59
72
 
60
73
  ---
61
74
 
@@ -85,10 +98,13 @@ pip install humane-proxy
85
98
  # Scaffold config in your project directory
86
99
  humane-proxy init
87
100
 
88
- # Start the proxy (set LLM_API_KEY and LLM_API_URL in .env first)
101
+ # Start the reverse proxy server
102
+ # (requires LLM_API_KEY and LLM_API_URL in .env — these point to your upstream LLM)
89
103
  humane-proxy start
90
104
  ```
91
105
 
106
+ > **Note:** `LLM_API_KEY` and `LLM_API_URL` are only needed for the reverse proxy server (`humane-proxy start`). They tell HumaneProxy where to forward safe messages. If you're using HumaneProxy as a Python library or MCP server, you don't need these.
107
+
92
108
  ### As a Python library
93
109
 
94
110
  ```python
@@ -109,19 +125,21 @@ result = await proxy.check_async("How do I make a bomb")
109
125
 
110
126
  ## 3-Stage Cascade Pipeline
111
127
 
112
- HumaneProxy classifies every message through up to **3 stages**, each progressively more capable but also more expensive. Stages exit early when confident.
128
+ HumaneProxy classifies every message through up to **3 stages**, each progressively more capable but also more expensive.
113
129
 
114
130
  ```
115
131
  ┌──────────────────────────────────────────────────────────┐
116
132
  │ Stage 1 — Heuristics < 1ms │
117
133
  │ Keyword corpus + intent regex patterns │
118
134
  │ Always on. Catches clear cases instantly. │
135
+ │ Early-exit: definitive self_harm → block immediately. │
119
136
  └──────────────────────────────────────────────────────────┘
120
- ↓ (ambiguous or medium-score)
137
+ ↓ (all other messages when Stage 2 enabled)
121
138
  ┌──────────────────────────────────────────────────────────┐
122
139
  │ Stage 2 — Semantic Embeddings ~100ms │
123
140
  │ sentence-transformers cosine similarity │
124
141
  │ vs. curated anchor sentences (self-harm + criminal) │
142
+ │ ALL messages flow here when enabled. │
125
143
  │ Optional: pip install humane-proxy[ml] │
126
144
  └──────────────────────────────────────────────────────────┘
127
145
  ↓ (still ambiguous)
@@ -170,6 +188,8 @@ stage2:
170
188
 
171
189
  The model lazy-loads on first use. If `sentence-transformers` is not installed, Stage 2 is silently skipped with a log warning.
172
190
 
191
+ > **How Stage 2 works with Stage 1:** When you enable `[1, 2]`, **every message** that Stage 1 does not flag as definitive `self_harm` proceeds to the embedding classifier. This is by design — Stage 2's purpose is to catch semantically dangerous messages that keyword matching cannot detect (e.g. *"Nobody would notice if I disappeared"*). Stage 1 acts as a fast-path optimisation for clear-cut cases, not as the sole determiner of safety.
192
+
173
193
  ### Stage 3 — Reasoning LLM
174
194
 
175
195
  Set your API key and optionally configure the provider:
@@ -225,6 +245,10 @@ HumaneProxy returns an empathetic message with crisis resources for 10+ countrie
225
245
  safety:
226
246
  categories:
227
247
  self_harm:
248
+ # Self-harm escalation threshold (0.0 to 1.0).
249
+ # Scores below this are downgraded to safe.
250
+ escalate_threshold: 0.5
251
+
228
252
  response_mode: "block" # default
229
253
 
230
254
  # Optional: override the built-in message
@@ -275,6 +299,10 @@ escalation:
275
299
  to:
276
300
  - "safety-team@yourorg.com"
277
301
  - "oncall@yourorg.com"
302
+
303
+ # Swappable Storage Backend (sqlite config default, redis/postgres optional)
304
+ storage:
305
+ backend: "sqlite" # or "redis", "postgres"
278
306
  ```
279
307
 
280
308
  ---
@@ -324,10 +352,13 @@ curl -X DELETE http://localhost:8000/admin/sessions/user-42 \
324
352
 
325
353
  | Endpoint | Description |
326
354
  |---|---|
327
- | `GET /admin/escalations` | Paginated list, filterable by `category`, `session_id` |
355
+ | `GET /admin/health` | Health check (no auth required) |
356
+ | `GET /admin/config` | Active config view (secrets redacted) |
357
+ | `GET /admin/escalations` | Paginated list, filterable by `category`, `session_id`, `date`, sortable |
358
+ | `GET /admin/escalations/export` | CSV export of escalations |
328
359
  | `GET /admin/escalations/{id}` | Single escalation detail |
329
360
  | `GET /admin/sessions/{id}/risk` | Session history + trajectory |
330
- | `GET /admin/stats` | Aggregate counts by category and day |
361
+ | `GET /admin/stats` | Aggregate counts, top sessions, hourly breakdown |
331
362
  | `DELETE /admin/sessions/{id}` | Delete all session records |
332
363
 
333
364
  ---
@@ -352,10 +383,38 @@ Available on the [Official MCP Registry](https://registry.modelcontextprotocol.i
352
383
 
353
384
  ---
354
385
 
355
- ## LangChain Integration
386
+ ## AI Agent Integrations
387
+
388
+ HumaneProxy tools can be natively plugged into standard agentic frameworks:
389
+
390
+ ### LlamaIndex
391
+ ```bash
392
+ pip install humane-proxy[llamaindex]
393
+ ```
394
+ ```python
395
+ from humane_proxy.integrations.llamaindex import get_safety_tools
396
+ tools = get_safety_tools() # Native FunctionTool instances
397
+ ```
356
398
 
357
- Plug HumaneProxy safety tools into any LangChain or LangGraph agent:
399
+ ### CrewAI
400
+ ```bash
401
+ pip install humane-proxy[crewai]
402
+ ```
403
+ ```python
404
+ from humane_proxy.integrations.crewai import get_safety_tools
405
+ tools = get_safety_tools() # Native BaseTool subclass instances
406
+ ```
407
+
408
+ ### AutoGen (AG2)
409
+ ```bash
410
+ pip install humane-proxy[autogen]
411
+ ```
412
+ ```python
413
+ from humane_proxy.integrations.autogen import register_safety_tools
414
+ register_safety_tools(assistant, user_proxy)
415
+ ```
358
416
 
417
+ ### LangChain
359
418
  ```bash
360
419
  pip install humane-proxy[langchain]
361
420
  ```
@@ -381,15 +440,17 @@ All values can be set in `humane_proxy.yaml` (project root) or via `HUMANE_PROXY
381
440
  | YAML key | Env var | Default | Description |
382
441
  |---|---|---|---|
383
442
  | `safety.risk_threshold` | `HUMANE_PROXY_RISK_THRESHOLD` | `0.7` | Score threshold for criminal_intent escalation |
384
- | `safety.spike_boost` | | `0.25` | Score boost on trajectory spike |
443
+ | `safety.categories.self_harm.escalate_threshold` | `HUMANE_PROXY_SELF_HARM_THRESHOLD` | `0.5` | Score threshold for self_harm escalation |
444
+ | `safety.spike_boost` | `HUMANE_PROXY_SPIKE_BOOST` | `0.25` | Score boost on trajectory spike |
385
445
  | `server.port` | `HUMANE_PROXY_PORT` | `8000` | Proxy port |
386
- | `pipeline.enabled_stages` | `HUMANE_PROXY_ENABLED_STAGES` | `[1]` | Active stages |
446
+ | `pipeline.enabled_stages` | `HUMANE_PROXY_ENABLED_STAGES` | `[1]` | Active stages (e.g. `1,2,3`) |
387
447
  | `pipeline.stage1_ceiling` | `HUMANE_PROXY_STAGE1_CEILING` | `0.3` | Early exit after Stage 1 |
388
448
  | `pipeline.stage2_ceiling` | `HUMANE_PROXY_STAGE2_CEILING` | `0.4` | Early exit after Stage 2 |
389
449
  | `stage3.provider` | `HUMANE_PROXY_STAGE3_PROVIDER` | `"auto"` | Stage 3 provider |
390
450
  | `stage3.timeout` | `HUMANE_PROXY_STAGE3_TIMEOUT` | `10` | Stage 3 timeout (s) |
391
451
  | `privacy.store_message_text` | — | `false` | Store raw text (vs SHA-256 hash) |
392
- | `escalation.rate_limit_max` | | `3` | Max alerts per session/window |
452
+ | `escalation.rate_limit_max` | `HUMANE_PROXY_RATE_LIMIT_MAX` | `3` | Max alerts per session/window |
453
+ | `storage.backend` | `HUMANE_PROXY_STORAGE_BACKEND` | `"sqlite"` | `"sqlite"`, `"redis"`, `"postgres"` |
393
454
  | `safety.categories.self_harm.response_mode` | — | `"block"` | `"block"` or `"forward"` |
394
455
 
395
456
  ---
@@ -419,11 +480,16 @@ privacy:
419
480
 
420
481
  | Extra | Command | What it adds |
421
482
  |---|---|---|
422
- | *(none)* | `pip install humane-proxy` | Stage 1 heuristics + full API + CLI |
483
+ | *(none)* | `pip install humane-proxy` | Stage 1 heuristics + default SQLite storage |
423
484
  | `ml` | `pip install humane-proxy[ml]` | Stage 2 semantic embeddings (`sentence-transformers`) |
424
485
  | `mcp` | `pip install humane-proxy[mcp]` | MCP server for AI agent integration (`fastmcp`) |
486
+ | `redis` | `pip install humane-proxy[redis]` | Redis storage backend (`redis`) |
487
+ | `postgres` | `pip install humane-proxy[postgres]` | PostgreSQL storage backend (`psycopg`, `psycopg_pool`) |
488
+ | `llamaindex` | `pip install humane-proxy[llamaindex]` | LlamaIndex native integration (`llama-index-core`) |
489
+ | `crewai` | `pip install humane-proxy[crewai]` | CrewAI native integration (`crewai[tools]`) |
490
+ | `autogen` | `pip install humane-proxy[autogen]` | AutoGen native integration (`autogen-agentchat`) |
425
491
  | `langchain` | `pip install humane-proxy[langchain]` | LangChain adapter (MCP + `langchain-mcp-adapters`) |
426
- | `all` | `pip install humane-proxy[all]` | Everything above |
492
+ | `all` | `pip install humane-proxy[all]` | Includes ALL optional dependencies above |
427
493
 
428
494
  ---
429
495
 
@@ -1,49 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: humane-proxy
3
- Version: 0.2.2
4
- Summary: Lightweight, plug-and-play AI safety middleware that protects humans.
5
- Author-email: Vishisht Mishra <Vishisht16@users.noreply.github.com>
6
- License: Apache-2.0
7
- Project-URL: Homepage, https://github.com/Vishisht16/Humane-Proxy
8
- Project-URL: Repository, https://github.com/Vishisht16/Humane-Proxy
9
- Project-URL: Issues, https://github.com/Vishisht16/Humane-Proxy/issues
10
- Keywords: ai-safety,llm,middleware,guardrails,human-safety
11
- Classifier: Development Status :: 3 - Alpha
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: Apache Software License
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
- Classifier: Topic :: Security
20
- Requires-Python: >=3.10
21
- Description-Content-Type: text/markdown
22
- License-File: LICENSE
23
- License-File: NOTICE
24
- Requires-Dist: fastapi>=0.100.0
25
- Requires-Dist: httpx>=0.24.0
26
- Requires-Dist: numpy>=1.24.0
27
- Requires-Dist: pyyaml>=6.0
28
- Requires-Dist: uvicorn>=0.22.0
29
- Requires-Dist: click>=8.0
30
- Provides-Extra: dev
31
- Requires-Dist: pytest>=7.0; extra == "dev"
32
- Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
33
- Requires-Dist: httpx; extra == "dev"
34
- Provides-Extra: ml
35
- Requires-Dist: sentence-transformers>=2.2.0; extra == "ml"
36
- Provides-Extra: mcp
37
- Requires-Dist: fastmcp>=0.4.0; extra == "mcp"
38
- Provides-Extra: langchain
39
- Requires-Dist: humane-proxy[mcp]; extra == "langchain"
40
- Requires-Dist: langchain-mcp-adapters>=0.1.0; extra == "langchain"
41
- Provides-Extra: webhooks
42
- Requires-Dist: httpx>=0.24.0; extra == "webhooks"
43
- Provides-Extra: all
44
- Requires-Dist: humane-proxy[langchain,mcp,ml]; extra == "all"
45
- Dynamic: license-file
46
-
47
1
  # 🛡️ HumaneProxy
48
2
 
49
3
  <!-- mcp-name: io.github.Vishisht16/humane-proxy -->
@@ -56,6 +10,8 @@ HumaneProxy sits between your users and any LLM. When someone expresses self-har
56
10
  [![Python](https://img.shields.io/pypi/pyversions/humane-proxy.svg)](https://pypi.org/project/humane-proxy/)
57
11
  [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
58
12
  [![Tests](https://github.com/Vishisht16/Humane-Proxy/actions/workflows/tests.yaml/badge.svg)](https://github.com/Vishisht16/Humane-Proxy/actions/workflows/tests.yaml)
13
+ [![Humane-Proxy MCP server](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy/badges/score.svg)](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy)
14
+ [![Humane-Proxy MCP server](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy/badges/card.svg)](https://glama.ai/mcp/servers/Vishisht16/Humane-Proxy)
59
15
 
60
16
  ---
61
17
 
@@ -85,10 +41,13 @@ pip install humane-proxy
85
41
  # Scaffold config in your project directory
86
42
  humane-proxy init
87
43
 
88
- # Start the proxy (set LLM_API_KEY and LLM_API_URL in .env first)
44
+ # Start the reverse proxy server
45
+ # (requires LLM_API_KEY and LLM_API_URL in .env — these point to your upstream LLM)
89
46
  humane-proxy start
90
47
  ```
91
48
 
49
+ > **Note:** `LLM_API_KEY` and `LLM_API_URL` are only needed for the reverse proxy server (`humane-proxy start`). They tell HumaneProxy where to forward safe messages. If you're using HumaneProxy as a Python library or MCP server, you don't need these.
50
+
92
51
  ### As a Python library
93
52
 
94
53
  ```python
@@ -109,19 +68,21 @@ result = await proxy.check_async("How do I make a bomb")
109
68
 
110
69
  ## 3-Stage Cascade Pipeline
111
70
 
112
- HumaneProxy classifies every message through up to **3 stages**, each progressively more capable but also more expensive. Stages exit early when confident.
71
+ HumaneProxy classifies every message through up to **3 stages**, each progressively more capable but also more expensive.
113
72
 
114
73
  ```
115
74
  ┌──────────────────────────────────────────────────────────┐
116
75
  │ Stage 1 — Heuristics < 1ms │
117
76
  │ Keyword corpus + intent regex patterns │
118
77
  │ Always on. Catches clear cases instantly. │
78
+ │ Early-exit: definitive self_harm → block immediately. │
119
79
  └──────────────────────────────────────────────────────────┘
120
- ↓ (ambiguous or medium-score)
80
+ ↓ (all other messages when Stage 2 enabled)
121
81
  ┌──────────────────────────────────────────────────────────┐
122
82
  │ Stage 2 — Semantic Embeddings ~100ms │
123
83
  │ sentence-transformers cosine similarity │
124
84
  │ vs. curated anchor sentences (self-harm + criminal) │
85
+ │ ALL messages flow here when enabled. │
125
86
  │ Optional: pip install humane-proxy[ml] │
126
87
  └──────────────────────────────────────────────────────────┘
127
88
  ↓ (still ambiguous)
@@ -170,6 +131,8 @@ stage2:
170
131
 
171
132
  The model lazy-loads on first use. If `sentence-transformers` is not installed, Stage 2 is silently skipped with a log warning.
172
133
 
134
+ > **How Stage 2 works with Stage 1:** When you enable `[1, 2]`, **every message** that Stage 1 does not flag as definitive `self_harm` proceeds to the embedding classifier. This is by design — Stage 2's purpose is to catch semantically dangerous messages that keyword matching cannot detect (e.g. *"Nobody would notice if I disappeared"*). Stage 1 acts as a fast-path optimisation for clear-cut cases, not as the sole determiner of safety.
135
+
173
136
  ### Stage 3 — Reasoning LLM
174
137
 
175
138
  Set your API key and optionally configure the provider:
@@ -225,6 +188,10 @@ HumaneProxy returns an empathetic message with crisis resources for 10+ countrie
225
188
  safety:
226
189
  categories:
227
190
  self_harm:
191
+ # Self-harm escalation threshold (0.0 to 1.0).
192
+ # Scores below this are downgraded to safe.
193
+ escalate_threshold: 0.5
194
+
228
195
  response_mode: "block" # default
229
196
 
230
197
  # Optional: override the built-in message
@@ -275,6 +242,10 @@ escalation:
275
242
  to:
276
243
  - "safety-team@yourorg.com"
277
244
  - "oncall@yourorg.com"
245
+
246
+ # Swappable Storage Backend (sqlite config default, redis/postgres optional)
247
+ storage:
248
+ backend: "sqlite" # or "redis", "postgres"
278
249
  ```
279
250
 
280
251
  ---
@@ -324,10 +295,13 @@ curl -X DELETE http://localhost:8000/admin/sessions/user-42 \
324
295
 
325
296
  | Endpoint | Description |
326
297
  |---|---|
327
- | `GET /admin/escalations` | Paginated list, filterable by `category`, `session_id` |
298
+ | `GET /admin/health` | Health check (no auth required) |
299
+ | `GET /admin/config` | Active config view (secrets redacted) |
300
+ | `GET /admin/escalations` | Paginated list, filterable by `category`, `session_id`, `date`, sortable |
301
+ | `GET /admin/escalations/export` | CSV export of escalations |
328
302
  | `GET /admin/escalations/{id}` | Single escalation detail |
329
303
  | `GET /admin/sessions/{id}/risk` | Session history + trajectory |
330
- | `GET /admin/stats` | Aggregate counts by category and day |
304
+ | `GET /admin/stats` | Aggregate counts, top sessions, hourly breakdown |
331
305
  | `DELETE /admin/sessions/{id}` | Delete all session records |
332
306
 
333
307
  ---
@@ -352,10 +326,38 @@ Available on the [Official MCP Registry](https://registry.modelcontextprotocol.i
352
326
 
353
327
  ---
354
328
 
355
- ## LangChain Integration
329
+ ## AI Agent Integrations
330
+
331
+ HumaneProxy tools can be natively plugged into standard agentic frameworks:
332
+
333
+ ### LlamaIndex
334
+ ```bash
335
+ pip install humane-proxy[llamaindex]
336
+ ```
337
+ ```python
338
+ from humane_proxy.integrations.llamaindex import get_safety_tools
339
+ tools = get_safety_tools() # Native FunctionTool instances
340
+ ```
341
+
342
+ ### CrewAI
343
+ ```bash
344
+ pip install humane-proxy[crewai]
345
+ ```
346
+ ```python
347
+ from humane_proxy.integrations.crewai import get_safety_tools
348
+ tools = get_safety_tools() # Native BaseTool subclass instances
349
+ ```
356
350
 
357
- Plug HumaneProxy safety tools into any LangChain or LangGraph agent:
351
+ ### AutoGen (AG2)
352
+ ```bash
353
+ pip install humane-proxy[autogen]
354
+ ```
355
+ ```python
356
+ from humane_proxy.integrations.autogen import register_safety_tools
357
+ register_safety_tools(assistant, user_proxy)
358
+ ```
358
359
 
360
+ ### LangChain
359
361
  ```bash
360
362
  pip install humane-proxy[langchain]
361
363
  ```
@@ -381,15 +383,17 @@ All values can be set in `humane_proxy.yaml` (project root) or via `HUMANE_PROXY
381
383
  | YAML key | Env var | Default | Description |
382
384
  |---|---|---|---|
383
385
  | `safety.risk_threshold` | `HUMANE_PROXY_RISK_THRESHOLD` | `0.7` | Score threshold for criminal_intent escalation |
384
- | `safety.spike_boost` | | `0.25` | Score boost on trajectory spike |
386
+ | `safety.categories.self_harm.escalate_threshold` | `HUMANE_PROXY_SELF_HARM_THRESHOLD` | `0.5` | Score threshold for self_harm escalation |
387
+ | `safety.spike_boost` | `HUMANE_PROXY_SPIKE_BOOST` | `0.25` | Score boost on trajectory spike |
385
388
  | `server.port` | `HUMANE_PROXY_PORT` | `8000` | Proxy port |
386
- | `pipeline.enabled_stages` | `HUMANE_PROXY_ENABLED_STAGES` | `[1]` | Active stages |
389
+ | `pipeline.enabled_stages` | `HUMANE_PROXY_ENABLED_STAGES` | `[1]` | Active stages (e.g. `1,2,3`) |
387
390
  | `pipeline.stage1_ceiling` | `HUMANE_PROXY_STAGE1_CEILING` | `0.3` | Early exit after Stage 1 |
388
391
  | `pipeline.stage2_ceiling` | `HUMANE_PROXY_STAGE2_CEILING` | `0.4` | Early exit after Stage 2 |
389
392
  | `stage3.provider` | `HUMANE_PROXY_STAGE3_PROVIDER` | `"auto"` | Stage 3 provider |
390
393
  | `stage3.timeout` | `HUMANE_PROXY_STAGE3_TIMEOUT` | `10` | Stage 3 timeout (s) |
391
394
  | `privacy.store_message_text` | — | `false` | Store raw text (vs SHA-256 hash) |
392
- | `escalation.rate_limit_max` | | `3` | Max alerts per session/window |
395
+ | `escalation.rate_limit_max` | `HUMANE_PROXY_RATE_LIMIT_MAX` | `3` | Max alerts per session/window |
396
+ | `storage.backend` | `HUMANE_PROXY_STORAGE_BACKEND` | `"sqlite"` | `"sqlite"`, `"redis"`, `"postgres"` |
393
397
  | `safety.categories.self_harm.response_mode` | — | `"block"` | `"block"` or `"forward"` |
394
398
 
395
399
  ---
@@ -419,11 +423,16 @@ privacy:
419
423
 
420
424
  | Extra | Command | What it adds |
421
425
  |---|---|---|
422
- | *(none)* | `pip install humane-proxy` | Stage 1 heuristics + full API + CLI |
426
+ | *(none)* | `pip install humane-proxy` | Stage 1 heuristics + default SQLite storage |
423
427
  | `ml` | `pip install humane-proxy[ml]` | Stage 2 semantic embeddings (`sentence-transformers`) |
424
428
  | `mcp` | `pip install humane-proxy[mcp]` | MCP server for AI agent integration (`fastmcp`) |
429
+ | `redis` | `pip install humane-proxy[redis]` | Redis storage backend (`redis`) |
430
+ | `postgres` | `pip install humane-proxy[postgres]` | PostgreSQL storage backend (`psycopg`, `psycopg_pool`) |
431
+ | `llamaindex` | `pip install humane-proxy[llamaindex]` | LlamaIndex native integration (`llama-index-core`) |
432
+ | `crewai` | `pip install humane-proxy[crewai]` | CrewAI native integration (`crewai[tools]`) |
433
+ | `autogen` | `pip install humane-proxy[autogen]` | AutoGen native integration (`autogen-agentchat`) |
425
434
  | `langchain` | `pip install humane-proxy[langchain]` | LangChain adapter (MCP + `langchain-mcp-adapters`) |
426
- | `all` | `pip install humane-proxy[all]` | Everything above |
435
+ | `all` | `pip install humane-proxy[all]` | Includes ALL optional dependencies above |
427
436
 
428
437
  ---
429
438
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- __version__ = "0.2.2"
19
+ __version__ = "0.3.0"
20
20
 
21
21
  # ---------------------------------------------------------------------------
22
22
  # Legacy API — keep backward compatibility with existing modules that call