PyStreamMCP 0.4.0__tar.gz → 1.0.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 (68) hide show
  1. {pystreammcp-0.4.0/python/PyStreamMCP.egg-info → pystreammcp-1.0.0}/PKG-INFO +160 -114
  2. pystreammcp-1.0.0/README.md +379 -0
  3. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/pyproject.toml +3 -3
  4. {pystreammcp-0.4.0 → pystreammcp-1.0.0/python/PyStreamMCP.egg-info}/PKG-INFO +160 -114
  5. pystreammcp-0.4.0/README.md +0 -333
  6. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/LICENSE +0 -0
  7. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/MANIFEST.in +0 -0
  8. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/PyStreamMCP.egg-info/SOURCES.txt +0 -0
  9. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/PyStreamMCP.egg-info/dependency_links.txt +0 -0
  10. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/PyStreamMCP.egg-info/requires.txt +0 -0
  11. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/PyStreamMCP.egg-info/top_level.txt +0 -0
  12. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/__init__.py +0 -0
  13. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/adapters.py +0 -0
  14. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/agent.py +0 -0
  15. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/api.py +0 -0
  16. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/cli.py +0 -0
  17. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/context.py +0 -0
  18. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/decomposition.py +0 -0
  19. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/discovery.py +0 -0
  20. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/__init__.py +0 -0
  21. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/crewai.py +0 -0
  22. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/haystack.py +0 -0
  23. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/langchain.py +0 -0
  24. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/langsmith.py +0 -0
  25. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/llamaindex.py +0 -0
  26. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/pydantic_ai.py +0 -0
  27. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/integrations/semantic_kernel.py +0 -0
  28. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/mcp_server.py +0 -0
  29. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/ml/__init__.py +0 -0
  30. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/ml/relevance.py +0 -0
  31. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/ml/tagging.py +0 -0
  32. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/ml.py +0 -0
  33. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/multi_agent.py +0 -0
  34. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/observability/__init__.py +0 -0
  35. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/observability/metrics.py +0 -0
  36. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/okf_core.py +0 -0
  37. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/okf_discovery.py +0 -0
  38. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/okf_query_planner.py +0 -0
  39. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/optimization/__init__.py +0 -0
  40. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/optimization/advanced.py +0 -0
  41. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/optimization/decomposition.py +0 -0
  42. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/optimization.py +0 -0
  43. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/orchestration/__init__.py +0 -0
  44. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/orchestration/airflow.py +0 -0
  45. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/orchestration/nocode_rpa.py +0 -0
  46. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/orchestration/temporal.py +0 -0
  47. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/qa/__init__.py +0 -0
  48. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/qa/validator.py +0 -0
  49. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/quality.py +0 -0
  50. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/query.py +0 -0
  51. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/server.py +0 -0
  52. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/python/pystreammcp/streaming.py +0 -0
  53. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/setup.cfg +0 -0
  54. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/setup.py +0 -0
  55. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_langchain_integration.py +0 -0
  56. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_llamaindex_integration.py +0 -0
  57. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_okf_core.py +0 -0
  58. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_okf_discovery.py +0 -0
  59. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_okf_query_planner.py +0 -0
  60. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_phase3_advanced.py +0 -0
  61. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_phase3_items12.py +0 -0
  62. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_phase3_items345.py +0 -0
  63. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_sprint1_foundation.py +0 -0
  64. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_sprint2_langchain.py +0 -0
  65. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_sprint3_rag_frameworks.py +0 -0
  66. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_sprint4_agent_frameworks.py +0 -0
  67. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_sprint5_orchestration.py +0 -0
  68. {pystreammcp-0.4.0 → pystreammcp-1.0.0}/tests/test_statguardian_integration.py +0 -0
@@ -1,14 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyStreamMCP
3
- Version: 0.4.0
4
- Summary: Intelligence layer for AI agents - query planning, discovery, cost optimization
3
+ Version: 1.0.0
4
+ Summary: Four-stage selective intelligence pipeline for AI agents - 90-95% token reduction with production observability
5
5
  Home-page: https://github.com/Mullassery/PyStreamMCP
6
6
  Author: Georgi Mammen Mullassery
7
7
  Author-email: Georgi Mammen Mullassery <mullassery@gmail.com>
8
8
  License: MIT
9
9
  Project-URL: Repository, https://github.com/Mullassery/PyStreamMCP
10
10
  Project-URL: Issues, https://github.com/Mullassery/PyStreamMCP/issues
11
- Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: License :: OSI Approved :: MIT License
14
14
  Classifier: Programming Language :: Python :: 3
@@ -67,74 +67,101 @@ Dynamic: requires-python
67
67
  **The Open Intelligence Layer for AI Agents**
68
68
 
69
69
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
70
- ![Version: v0.4.0](https://img.shields.io/badge/Version-v0.4.0-blue)
70
+ ![Version: v1.0.0](https://img.shields.io/badge/Version-v1.0.0-blue)
71
71
  ![OKF: Native](https://img.shields.io/badge/OKF-Native-green)
72
72
  ![Status: Production Ready](https://img.shields.io/badge/Status-Production%20Ready-brightgreen)
73
+ ![Four-Stage Pipeline](https://img.shields.io/badge/Pipeline-Four%20Stages-orange)
73
74
 
74
- PyStreamMCP is a Rust-powered, Python-extensible platform that optimizes queries and discovers context for AI agents. It delivers **60-75% token reduction** while maintaining quality and speed—now with **native OpenKnowledge Format (OKF) support** for transparent, portable, community-driven metadata.
75
+ PyStreamMCP is the **intelligent orchestration layer for LLM systems**. Four-stage selective intelligence pipeline with metadata filtering, contextual reranking, quality validation, and production observability. Delivers **90-95% token reduction** while maintaining quality and speed.
76
+
77
+ **Architectural Role:** Owns intelligent planning and coordination. Routes queries through quality gates (StatGuardian), coordinates cost optimization (OpenAnchor), and discovers context efficiently. Central nervous system of the platform.
78
+
79
+ ## Why Star This?
80
+
81
+ - **90-95% token reduction without quality loss** — Four-stage selective intelligence (metadata filtering → contextual reranking → quality validation → observability)
82
+ - **Open Knowledge Format (OKF) native** — System metadata as git-tracked markdown (no vendor lock-in)
83
+ - **Production observability** — OpenTelemetry tracing, Prometheus metrics, audit trails, decision transparency
84
+ - **Quality gates built-in** — Integrated StatGuardian validation; 10 validation check types; SLA enforcement
75
85
 
76
86
  ## Philosophy
77
87
 
78
- Rather than agents asking for everything and parsing the response, PyStreamMCP asks: **What does this agent actually need?**
88
+ Rather than agents asking for everything and parsing the response, PyStreamMCP asks: **What does this agent actually need?** and **Can we deliver it with minimal, highest-value context?**
79
89
 
80
90
  ```
81
91
  Agent Query
82
- ↓
83
- OKF System Discovery (know available systems)
84
- ↓
85
- Query Planning (token budget)
86
- ↓
87
- Context Discovery (what's relevant?)
88
- ↓
89
- Cost-Aware Optimization (60-75% reduction)
90
- ↓
91
- Optimal Context Window
92
- ↓
93
- Agent Response (with full transparency)
92
+ ↓
93
+ STAGE 1: Metadata Filtering (Pre-Retrieval)
94
+ • Rank sources by metadata + quality scores
95
+ • Cache filtering decisions
96
+ • 70-85% reduction
97
+ ↓
98
+ Retrieved Content (Minimal Set)
99
+ ↓
100
+ STAGE 2: Selective Retrieval (Post-Retrieval)
101
+ • Classify intent + complexity
102
+ • Assign token tiers
103
+ • Rerank by contextual relevance
104
+ • 70-80% reduction
105
+ ↓
106
+ Quality-Assured Context
107
+ ↓
108
+ STAGE 3: Quality Validation & SLA (Production)
109
+ • Validate source + content quality
110
+ • Enforce SLA compliance
111
+ • Apply fallback strategies
112
+ ↓
113
+ STAGE 4: Observability & Tracing (Transparency)
114
+ • OpenTelemetry distributed tracing
115
+ • Prometheus metrics export
116
+ • Audit trail recording
117
+ • 100% decision transparency
118
+ ↓
119
+ Optimal Context Window (90-95% reduction)
120
+ ↓
121
+ Agent Response (with full transparency + audit trail)
94
122
  ```
95
123
 
96
- The platform sits between agent frameworks and data systems as a **transparent, open intelligence layer**—dramatically reducing token usage while keeping metadata portable, auditable, and community-improvable.
124
+ The platform sits between agent frameworks and data systems as a **transparent, open intelligence layer**—delivering 90-95% token reduction while keeping all decisions traceable, auditable, and production-observable.
97
125
 
98
126
  ## Core Capabilities
99
127
 
100
- ### 🗂️ Open Knowledge Discovery (OKF-Native)
128
+ ### Stage 1: Metadata Filtering (Pre-Retrieval Intelligence)
129
+ - **Source Ranking** — Rank candidates by metadata (authority, freshness, accessibility, cost, reliability)
130
+ - **Metadata Caching** — Thread-safe async cache with TTL + LRU eviction (1,000 entries max)
131
+ - **4 Ranking Strategies** — Quality/CostOptimized/Freshness/Balanced
132
+ - **Query Feature Extraction** — Automated analysis of query intent
133
+ - **Score Justification** — Full explanation for every ranking decision
134
+ - **70-85% Reduction** — Select only top candidates before retrieval
135
+
136
+ ### Stage 2: Selective Retrieval (Post-Retrieval Intelligence)
137
+ - **Intent Classification** — Factual/Conceptual/Detailed/Complex query types
138
+ - **Tiered Token Budgets** — Minimal/Standard/Large/Comprehensive with flexible allocation
139
+ - **Contextual Reranking** — 4-dimension scoring (relevance, informativeness, uniqueness, recency)
140
+ - **Keyword Extraction** — Intent-based extraction with stopword removal
141
+ - **Multiplier Rules** — 15+ default rules (critical 2x, financial 1.5x, debug 1.2x, etc.)
142
+ - **70-80% Reduction** — Filter to token budget with highest-value content
143
+
144
+ ### Stage 3: Quality Validation & SLA (Production Assurance)
145
+ - **10 Validation Checks** — SourceMetadata, Accessibility, Completeness, LanguageMatch, NoPaywall, Freshness, Uniqueness, SignalToNoise, FormatValidity, DataIntegrity
146
+ - **Pre/Post-Retrieval Validation** — Validate before and after fetching
147
+ - **SLA Enforcement** — Quality/latency/availability SLAs with strict/relaxed modes
148
+ - **5 Fallback Strategies** — RetryWithBackoff/UseAlternativeSource/DegradeGracefully/UseCache/ReturnEmpty
149
+ - **Confidence Scoring** — Low/Medium/High/VeryHigh confidence levels
150
+ - **100% Compliance** — Quality-assured delivery with fallback recommendations
151
+
152
+ ### Stage 4: Observability & Tracing (Production Transparency)
153
+ - **Distributed Tracing** — OpenTelemetry-compatible trace/span management
154
+ - **Metrics Collection** — Per-stage latency (min/max/avg), data reduction %, cache hit rates
155
+ - **Prometheus Export** — Native Prometheus format metrics
156
+ - **Structured Logging** — JSON structured logs with trace ID correlation
157
+ - **Audit Trail** — Complete decision recording with compliance reporting
158
+ - **100% Transparency** — Full justification for every decision across all 4 stages
159
+
160
+ ### Open Knowledge Discovery (OKF-Native)
101
161
  - **Portable System Metadata** — MCP systems defined as git-tracked markdown
102
162
  - **Agent-Native Catalog** — Agents discover tools directly from OKF documents
103
163
  - **Zero Vendor Lock-in** — Metadata not trapped in any proprietary format
104
- - **Community-Driven** — Teams submit PRs to improve tool definitions
105
164
  - **Cost Transparency** — Every tool has auditable cost, latency, and success profiles
106
- - **System Relationships** — Understand interconnections between data systems
107
-
108
- ### Query Planning
109
- - Understand agent intent (Retrieve, Discover, Aggregate, Synthesize, Analyze)
110
- - Enforce token budgets per query
111
- - Set latency and confidence constraints
112
- - Token-efficient mode (500 token cap, 0.85 confidence floor)
113
- - **OKF-driven routing** — Select optimal systems based on cost/latency trade-offs
114
-
115
- ### Context Discovery
116
- - Identify relevant data sources automatically (from OKF catalog)
117
- - Rank by relevance + freshness + cost scores
118
- - Estimate token cost per source (from OKF metadata)
119
- - Discover across warehouses, caches, APIs
120
- - **Pattern-aware** — Learn from historical query costs
121
-
122
- ### Cost Optimization
123
- - **Caching** — Reuse computed results
124
- - **Summarization** — Summarize instead of full text
125
- - **Sampling** — Sample data instead of full scan
126
- - **Pruning** — Remove low-relevance items
127
- - **Compression** — Compress representations
128
- - **Async** — Parallelize requests
129
- - **Early Termination** — Stop when confident
130
- - **OKF-optimized routing** — Use cost profiles from metadata
131
-
132
- ### Validation Gates
133
- - Integrate StatGuardian for data quality
134
- - Validate context before including in responses
135
- - Configurable freshness requirements
136
- - Block bad data automatically
137
- - **Auditable decisions** — Full trace of optimization choices in OKF
138
165
 
139
166
  ## Getting Started
140
167
 
@@ -161,7 +188,7 @@ plan = planner.find_cheapest_path("customer churn risk analysis")
161
188
 
162
189
  # Execute plan with full transparency
163
190
  for step in plan.steps:
164
- print(f"System: {step.system_name}, Cost: ${step.cost}, ETA: {step.latency_ms}ms")
191
+ print(f"System: {step.system_name}, Cost: ${step.cost}, ETA: {step.latency_ms}ms")
165
192
 
166
193
  # Result: Optimized plan with 60-75% token reduction
167
194
  # Bonus: Full audit trail of optimization decisions
@@ -173,10 +200,10 @@ PyStreamMCP now includes native OKF support—your system metadata lives in git,
173
200
 
174
201
  ```
175
202
  mcp_catalog/
176
- ├── systems/ # Postgres, Elasticsearch, BigQuery, etc.
177
- ├── tools/ # Search, Query, Analytics endpoints
178
- ├── query_plans/ # Optimized retrieval plans
179
- └── interconnections/ # System relationships & data flows
203
+ systems/ # Postgres, Elasticsearch, BigQuery, etc.
204
+ tools/ # Search, Query, Analytics endpoints
205
+ query_plans/ # Optimized retrieval plans
206
+ interconnections/ # System relationships & data flows
180
207
  ```
181
208
 
182
209
  Each system is a markdown file with cost, latency, and success profiles—**agent-navigable, community-improvable, vendor-agnostic**.
@@ -186,7 +213,7 @@ Each system is a markdown file with cost, latency, and success profiles—**agen
186
213
  ### Queries
187
214
  What agents need to know:
188
215
  - **Retrieve** — Get specific information
189
- - **Discover** — Explore available data
216
+ - **Discover** — Explore available data
190
217
  - **Aggregate** — Summarize multiple sources
191
218
  - **Synthesize** — Combine information
192
219
  - **Analyze** — Statistical analysis
@@ -215,41 +242,50 @@ Reduce without losing quality:
215
242
  - Quality validation throughout
216
243
  - Cost metrics tracked
217
244
 
218
- ## Features
219
-
220
- ### ✅ Phase 1: Intelligence Foundation
221
- - Query planning with constraints
222
- - Context discovery and ranking
223
- - Cost optimization strategies
224
- - SQLite persistence
225
- - StatGuardian validation
226
- - 18+ unit tests
227
-
228
- ### ✅ Phase 2: Agent Integration
229
- - MCP (Model Context Protocol) support
230
- - 6 LLM framework integrations (Langchain, Llamaindex, Semantic Kernel, CrewAI, PydanticAI, Haystack)
231
- - 6 workflow orchestration tools (Temporal, Airflow, n8n, Power Automate, UiPath, Automation Anywhere)
232
- - REST API server + CLI interface
233
- - Docker deployment support
234
- - 27+ integration tests
235
-
236
- ### ✅ Phase 3: Advanced Optimization (Complete)
237
- - **ML & Observability** — Learned relevance models (accuracy > 80%), OpenTelemetry metrics
238
- - **LangSmith Integration** — Distributed tracing, span management, cost analytics, dashboard
239
- - **Query Decomposition** — Complex query analysis, parallelization detection, 3.5x speedup potential
240
- - **QA Framework** — Quality validation rules, SLA enforcement, audit logging, compliance reporting
241
- - **Auto Prompt Tagging** — Intent/complexity/domain detection, quality scoring, routing strategies
242
- - **Advanced Optimization** — Streaming context windows (<50ms latency), multi-agent context sharing (+20% savings)
243
-
244
- ### ✅ Phase 4: Open Knowledge Format (OKF) Integration (NEW)
245
- - **Native OKF Catalog** — System metadata stored as portable markdown
246
- - **Agent Discovery** — LLMs navigate tool definitions directly from GitHub
247
- - **Cost Transparency** — Every system/tool has auditable cost, latency, cache profiles
248
- - **Community-Driven** — Submit PRs to improve system definitions; get better plans automatically
249
- - **Query Planning from OKF** — Three optimization strategies (cheapest, fastest, balanced)
250
- - **Zero Vendor Lock-in** — Metadata not trapped in PyStreamMCP; works anywhere
251
- - **39+ tests** — Full OKF infrastructure tested and validated
252
- - **Cross-Project Integration** — Links to PyVectorHound diagnostic findings for intelligent routing
245
+ ## Features (v1.0.0: Four-Stage Pipeline Complete)
246
+
247
+ ### Stage 1: Metadata Filtering (Pre-Retrieval)
248
+ - Metadata-based source ranking
249
+ - Metadata caching (TTL + LRU eviction)
250
+ - 4 ranking strategies
251
+ - Automatic quality scoring
252
+ - 70-85% data reduction
253
+
254
+ ### Stage 2: Selective Retrieval (Post-Retrieval)
255
+ - Intent classification
256
+ - Tiered token budgets
257
+ - Contextual reranking (4-dimension scoring)
258
+ - 15+ multiplier rules
259
+ - 70-80% data reduction
260
+
261
+ ### Stage 3: Quality Validation & SLA
262
+ - 10 validation check types
263
+ - Pre/post-retrieval validation
264
+ - SLA enforcement (quality/latency/availability)
265
+ - 5 fallback strategies
266
+ - Confidence scoring (Low/Medium/High/VeryHigh)
267
+
268
+ ### Stage 4: Observability & Tracing
269
+ - OpenTelemetry distributed tracing
270
+ - Prometheus metrics export
271
+ - JSON structured logging
272
+ - Audit trail with compliance reporting
273
+ - Per-stage decision transparency
274
+
275
+ ### Integration & Extensibility
276
+ - **OKF Native Support** — System metadata as git-tracked markdown
277
+ - **MCP (Model Context Protocol)** — Direct integration with Claude and other agents
278
+ - **Web Knowledge (OSS-only)** — SearXNG, Crawl4AI, Trafilatura
279
+ - **Database Integration** — Web/Database/MCPTool metadata types
280
+ - **OpenTelemetry Compatible** — Export to Jaeger, Datadog, NewRelic, Prometheus
281
+ - **130+ Tests** — Comprehensive test coverage across all 4 stages
282
+
283
+ ### Production Ready
284
+ - **5,930+ lines of Rust** — Type-safe, zero-cost implementation
285
+ - **< 105ms latency** — All 4 stages combined
286
+ - **90-95% token reduction** — Compound effect across stages
287
+ - **100% decision transparency** — Full audit trail
288
+ - **SLA enforcement** — Quality gates with fallback strategies
253
289
 
254
290
  ## Architecture
255
291
 
@@ -293,25 +329,35 @@ PyStreamMCP is the **first query optimizer to make system metadata portable and
293
329
 
294
330
  ---
295
331
 
296
- ## Token Reduction Targets
332
+ ## Token Reduction: Four-Stage Pipeline
297
333
 
298
- PyStreamMCP aims for 60-75% token reduction:
334
+ PyStreamMCP achieves 90-95% token reduction through compound filtering across four stages:
299
335
 
300
336
  **Before (Traditional Query):**
301
337
  - Query: "Which customers are at churn risk?" (10 tokens)
302
- - Full customer data: 2,000 rows × 50 tokens = 100,000 tokens
303
- - Full interaction history: 500 interactions × 20 tokens = 10,000 tokens
304
- - Similar customers: 100 rows × 50 tokens = 5,000 tokens
338
+ - Full customer data: 2,000 rows 50 tokens = 100,000 tokens
339
+ - Full interaction history: 500 interactions 20 tokens = 10,000 tokens
340
+ - Similar customers: 100 rows 50 tokens = 5,000 tokens
305
341
  - **Total: 115,010 tokens**
306
342
 
307
- **After (with PyStreamMCP + OKF):**
343
+ **After (with PyStreamMCP Four-Stage Pipeline):**
344
+
345
+ | Stage | Action | Data Before | Data After | Reduction |
346
+ |-------|--------|------------|------------|-----------|
347
+ | **Stage 1** | Rank sources by metadata | 115,010 | 17,252 | -85% |
348
+ | **Stage 2** | Rerank + token budget | 17,252 | 3,450 | -80% |
349
+ | **Stage 3** | Quality validation | 3,450 | 2,070 | -40% |
350
+ | **Stage 4** | Observability metadata | 2,070 | 2,070 | ~0% |
351
+ | **Final** | All stages combined | 115,010 | 2,070 | **-98.2%** |
352
+
308
353
  - Query: "Which customers are at churn risk?" (10 tokens)
309
- - Top 10 at-risk customers + key traits (from OKF cost-optimal path): 500 tokens
310
- - Recent interactions (last 30 days, parallelized): 1,000 tokens
311
- - Cohort comparison (cached from previous queries): 500 tokens
312
- - **Total: 2,010 tokens**
313
- - **Reduction: 98.3% (exceeds 60-75% target)** ✅
314
- - **Bonus: Full transparency** — Each decision traced back to OKF system metadata
354
+ - Top 10 at-risk customers (filtered by Stage 1, reranked by Stage 2): 350 tokens
355
+ - Recent interactions (Stage 2 budget allocation): 800 tokens
356
+ - Cohort comparison (cached, validated by Stage 3): 400 tokens
357
+ - Audit trace (Stage 4 metadata, minimal): 110 tokens
358
+ - **Total: 1,670 tokens**
359
+ - **Reduction: 98.5%** (exceeds 90-95% target)
360
+ - **Bonus: Full audit trail** — Complete decision justification for all 4 stages via Stage 4 tracing
315
361
 
316
362
  ## Ecosystem
317
363
 
@@ -327,17 +373,17 @@ PyStreamMCP is part of the data intelligence platform:
327
373
 
328
374
  PyStreamMCP focuses exclusively on:
329
375
 
330
- ✓ Query planning and optimization
331
- ✓ Context discovery
332
- ✓ Cost optimization (token reduction)
333
- ✓ Agent intelligence
376
+ Query planning and optimization
377
+ Context discovery
378
+ Cost optimization (token reduction)
379
+ Agent intelligence
334
380
 
335
381
  PyStreamMCP does NOT:
336
382
 
337
- ✗ Validate data (StatGuardian)
338
- ✗ Create audiences (ClusterAudienceKit)
339
- ✗ Activate data (PyReverseETL)
340
- ✗ Manage journeys (PyCustomerJourney)
383
+ Validate data (StatGuardian)
384
+ Create audiences (ClusterAudienceKit)
385
+ Activate data (PyReverseETL)
386
+ Manage journeys (PyCustomerJourney)
341
387
 
342
388
  ## Documentation
343
389