kailash 0.2.1__py3-none-any.whl → 0.3.0__py3-none-any.whl
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.
- kailash/__init__.py +1 -1
- kailash/api/custom_nodes_secure.py +2 -2
- kailash/api/studio_secure.py +1 -1
- kailash/mcp/client_new.py +1 -1
- kailash/nodes/ai/a2a.py +1 -1
- kailash/nodes/api/__init__.py +26 -0
- kailash/nodes/api/monitoring.py +463 -0
- kailash/nodes/api/security.py +822 -0
- kailash/nodes/base.py +3 -3
- kailash/nodes/code/python.py +6 -0
- kailash/nodes/data/__init__.py +9 -0
- kailash/nodes/data/directory.py +278 -0
- kailash/nodes/data/event_generation.py +297 -0
- kailash/nodes/data/file_discovery.py +601 -0
- kailash/nodes/data/sql.py +2 -2
- kailash/nodes/transform/processors.py +32 -1
- kailash/runtime/async_local.py +1 -1
- kailash/runtime/docker.py +4 -4
- kailash/runtime/local.py +41 -4
- kailash/runtime/parallel.py +2 -2
- kailash/runtime/parallel_cyclic.py +2 -2
- kailash/runtime/testing.py +2 -2
- kailash/utils/templates.py +6 -6
- kailash/visualization/performance.py +16 -3
- kailash/visualization/reports.py +5 -1
- kailash/workflow/convergence.py +1 -1
- kailash/workflow/cycle_analyzer.py +8 -1
- kailash/workflow/cyclic_runner.py +1 -1
- kailash/workflow/graph.py +33 -6
- kailash/workflow/visualization.py +10 -2
- kailash-0.3.0.dist-info/METADATA +428 -0
- {kailash-0.2.1.dist-info → kailash-0.3.0.dist-info}/RECORD +36 -31
- kailash-0.2.1.dist-info/METADATA +0 -1617
- {kailash-0.2.1.dist-info → kailash-0.3.0.dist-info}/WHEEL +0 -0
- {kailash-0.2.1.dist-info → kailash-0.3.0.dist-info}/entry_points.txt +0 -0
- {kailash-0.2.1.dist-info → kailash-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {kailash-0.2.1.dist-info → kailash-0.3.0.dist-info}/top_level.txt +0 -0
kailash-0.2.1.dist-info/METADATA
DELETED
@@ -1,1617 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: kailash
|
3
|
-
Version: 0.2.1
|
4
|
-
Summary: Python SDK for the Kailash container-node architecture
|
5
|
-
Home-page: https://github.com/integrum/kailash-python-sdk
|
6
|
-
Author: Integrum
|
7
|
-
Author-email: Integrum <info@integrum.com>
|
8
|
-
Project-URL: Homepage, https://github.com/integrum/kailash-python-sdk
|
9
|
-
Project-URL: Bug Tracker, https://github.com/integrum/kailash-python-sdk/issues
|
10
|
-
Classifier: Development Status :: 3 - Alpha
|
11
|
-
Classifier: Intended Audience :: Developers
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
15
|
-
Requires-Python: >=3.11
|
16
|
-
Description-Content-Type: text/markdown
|
17
|
-
License-File: LICENSE
|
18
|
-
Requires-Dist: networkx>=2.7
|
19
|
-
Requires-Dist: pydantic>=1.9
|
20
|
-
Requires-Dist: matplotlib>=3.5
|
21
|
-
Requires-Dist: pyyaml>=6.0
|
22
|
-
Requires-Dist: click>=8.0
|
23
|
-
Requires-Dist: pytest>=8.3.5
|
24
|
-
Requires-Dist: mcp[cli]>=1.9.2
|
25
|
-
Requires-Dist: pandas>=2.2.3
|
26
|
-
Requires-Dist: numpy>=2.2.5
|
27
|
-
Requires-Dist: scipy>=1.15.3
|
28
|
-
Requires-Dist: scikit-learn>=1.6.1
|
29
|
-
Requires-Dist: requests>=2.32.3
|
30
|
-
Requires-Dist: pytest-cov>=6.1.1
|
31
|
-
Requires-Dist: isort>=6.0.1
|
32
|
-
Requires-Dist: aiohttp>=3.12.4
|
33
|
-
Requires-Dist: ruff>=0.11.12
|
34
|
-
Requires-Dist: msal>=1.32.3
|
35
|
-
Requires-Dist: sphinx>=8.2.3
|
36
|
-
Requires-Dist: sphinx-rtd-theme>=3.0.2
|
37
|
-
Requires-Dist: sphinx-copybutton>=0.5.2
|
38
|
-
Requires-Dist: sphinxcontrib-mermaid>=1.0.0
|
39
|
-
Requires-Dist: sphinx-autobuild>=2024.10.3
|
40
|
-
Requires-Dist: autodoc>=0.5.0
|
41
|
-
Requires-Dist: myst-parser>=4.0.1
|
42
|
-
Requires-Dist: black>=25.1.0
|
43
|
-
Requires-Dist: psutil>=7.0.0
|
44
|
-
Requires-Dist: fastapi>=0.115.12
|
45
|
-
Requires-Dist: uvicorn[standard]>=0.31.0
|
46
|
-
Requires-Dist: pytest-asyncio>=1.0.0
|
47
|
-
Requires-Dist: pre-commit>=4.2.0
|
48
|
-
Requires-Dist: twine>=6.1.0
|
49
|
-
Requires-Dist: ollama>=0.5.1
|
50
|
-
Requires-Dist: sqlalchemy>=2.0.0
|
51
|
-
Requires-Dist: psycopg2-binary>=2.9.0
|
52
|
-
Requires-Dist: pymysql>=1.1.0
|
53
|
-
Requires-Dist: aiosqlite>=0.19.0
|
54
|
-
Requires-Dist: websockets>=12.0
|
55
|
-
Requires-Dist: httpx>=0.25.0
|
56
|
-
Requires-Dist: python-jose>=3.5.0
|
57
|
-
Requires-Dist: pytest-xdist>=3.6.0
|
58
|
-
Requires-Dist: pytest-timeout>=2.3.0
|
59
|
-
Requires-Dist: pytest-split>=0.9.0
|
60
|
-
Provides-Extra: dev
|
61
|
-
Requires-Dist: pytest>=7.0; extra == "dev"
|
62
|
-
Requires-Dist: pytest-cov>=3.0; extra == "dev"
|
63
|
-
Requires-Dist: black>=22.0; extra == "dev"
|
64
|
-
Requires-Dist: isort>=5.10; extra == "dev"
|
65
|
-
Requires-Dist: mypy>=0.9; extra == "dev"
|
66
|
-
Dynamic: author
|
67
|
-
Dynamic: home-page
|
68
|
-
Dynamic: license-file
|
69
|
-
Dynamic: requires-python
|
70
|
-
|
71
|
-
# Kailash Python SDK
|
72
|
-
|
73
|
-
<p align="center">
|
74
|
-
<a href="https://pypi.org/project/kailash/"><img src="https://img.shields.io/pypi/v/kailash.svg" alt="PyPI version"></a>
|
75
|
-
<a href="https://pypi.org/project/kailash/"><img src="https://img.shields.io/pypi/pyversions/kailash.svg" alt="Python versions"></a>
|
76
|
-
<a href="https://pepy.tech/project/kailash"><img src="https://static.pepy.tech/badge/kailash" alt="Downloads"></a>
|
77
|
-
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License">
|
78
|
-
<img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black">
|
79
|
-
<img src="https://img.shields.io/badge/tests-734%20passing-brightgreen.svg" alt="Tests: 734 passing">
|
80
|
-
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg" alt="Coverage: 100%">
|
81
|
-
</p>
|
82
|
-
|
83
|
-
<p align="center">
|
84
|
-
<strong>A Pythonic SDK for the Kailash container-node architecture</strong>
|
85
|
-
</p>
|
86
|
-
|
87
|
-
<p align="center">
|
88
|
-
Build workflows that seamlessly integrate with Kailash's production environment while maintaining the flexibility to prototype quickly and iterate locally.
|
89
|
-
</p>
|
90
|
-
|
91
|
-
---
|
92
|
-
|
93
|
-
## ✨ Highlights
|
94
|
-
|
95
|
-
- 🚀 **Rapid Prototyping**: Create and test workflows locally without containerization
|
96
|
-
- 🏗️ **Architecture-Aligned**: Automatically ensures compliance with Kailash standards
|
97
|
-
- 🔄 **Seamless Handoff**: Export prototypes directly to production-ready formats
|
98
|
-
- 📊 **Real-time Monitoring**: Live dashboards with WebSocket streaming and performance metrics
|
99
|
-
- 🧩 **Extensible**: Easy to create custom nodes for domain-specific operations
|
100
|
-
- ⚡ **Fast Installation**: Uses `uv` for lightning-fast Python package management
|
101
|
-
- 🤖 **AI-Powered**: Complete LLM agents, embeddings, and hierarchical RAG architecture
|
102
|
-
- 🧠 **Retrieval-Augmented Generation**: Full RAG pipeline with intelligent document processing
|
103
|
-
- 🌐 **REST API Wrapper**: Expose any workflow as a production-ready API in 3 lines
|
104
|
-
- 🚪 **Multi-Workflow Gateway**: Manage multiple workflows through unified API with MCP integration
|
105
|
-
- 🤖 **Self-Organizing Agents**: Autonomous agent pools with intelligent team formation and convergence detection
|
106
|
-
- 🧠 **Agent-to-Agent Communication**: Shared memory pools and intelligent caching for coordinated multi-agent systems
|
107
|
-
- 🔒 **Production Security**: Comprehensive security framework with path traversal prevention, code sandboxing, and audit logging
|
108
|
-
- 🎨 **Visual Workflow Builder**: Kailash Workflow Studio - drag-and-drop interface for creating and managing workflows (coming soon)
|
109
|
-
- 🔁 **Cyclic Workflows (v0.2.0)**: Universal Hybrid Cyclic Graph Architecture with 30,000+ iterations/second performance
|
110
|
-
- 🛠️ **Developer Tools**: CycleAnalyzer, CycleDebugger, CycleProfiler for production-ready cyclic workflows
|
111
|
-
- 📈 **High Performance**: Optimized execution engine supporting 100,000+ iteration workflows
|
112
|
-
|
113
|
-
## 🎯 Who Is This For?
|
114
|
-
|
115
|
-
The Kailash Python SDK is designed for:
|
116
|
-
|
117
|
-
- **AI Business Coaches (ABCs)** who need to prototype workflows quickly
|
118
|
-
- **Data Scientists** building ML pipelines compatible with production infrastructure
|
119
|
-
- **Engineers** who want to test Kailash workflows locally before deployment
|
120
|
-
- **Teams** looking to standardize their workflow development process
|
121
|
-
|
122
|
-
## 🚀 Quick Start
|
123
|
-
|
124
|
-
### Installation
|
125
|
-
|
126
|
-
**Requirements:** Python 3.11 or higher
|
127
|
-
|
128
|
-
```bash
|
129
|
-
# Install uv if you haven't already
|
130
|
-
curl -LsSf https://astral.sh/uv/install.sh | sh
|
131
|
-
|
132
|
-
# For users: Install from PyPI
|
133
|
-
pip install kailash
|
134
|
-
|
135
|
-
# For developers: Clone and sync
|
136
|
-
git clone https://github.com/integrum/kailash-python-sdk.git
|
137
|
-
cd kailash-python-sdk
|
138
|
-
uv sync
|
139
|
-
```
|
140
|
-
|
141
|
-
### Your First Workflow
|
142
|
-
|
143
|
-
```python
|
144
|
-
from kailash.workflow import Workflow
|
145
|
-
from kailash.nodes.data import CSVReaderNode
|
146
|
-
from kailash.nodes.code import PythonCodeNode
|
147
|
-
from kailash.runtime.local import LocalRuntime
|
148
|
-
import pandas as pd
|
149
|
-
|
150
|
-
# Create a workflow
|
151
|
-
workflow = Workflow("customer_analysis", name="customer_analysis")
|
152
|
-
|
153
|
-
# Add data reader
|
154
|
-
reader = CSVReaderNode(file_path="customers.csv")
|
155
|
-
workflow.add_node("read_customers", reader)
|
156
|
-
|
157
|
-
# Add custom processing using Python code
|
158
|
-
def analyze_customers(data):
|
159
|
-
"""Analyze customer data and compute metrics."""
|
160
|
-
df = pd.DataFrame(data)
|
161
|
-
# Convert total_spent to numeric
|
162
|
-
df['total_spent'] = pd.to_numeric(df['total_spent'])
|
163
|
-
return {
|
164
|
-
"result": {
|
165
|
-
"total_customers": len(df),
|
166
|
-
"avg_spend": df["total_spent"].mean(),
|
167
|
-
"top_customers": df.nlargest(10, "total_spent").to_dict("records")
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
analyzer = PythonCodeNode.from_function(analyze_customers, name="analyzer")
|
172
|
-
workflow.add_node("analyze", analyzer)
|
173
|
-
|
174
|
-
# Connect nodes
|
175
|
-
workflow.connect("read_customers", "analyze", {"data": "data"})
|
176
|
-
|
177
|
-
# Run locally
|
178
|
-
runtime = LocalRuntime()
|
179
|
-
results, run_id = runtime.execute(workflow)
|
180
|
-
print(f"Analysis complete! Results: {results}")
|
181
|
-
|
182
|
-
# Export for production
|
183
|
-
from kailash.utils.export import WorkflowExporter
|
184
|
-
exporter = WorkflowExporter()
|
185
|
-
workflow.save("customer_analysis.yaml", format="yaml")
|
186
|
-
```
|
187
|
-
|
188
|
-
### SharePoint Integration Example
|
189
|
-
|
190
|
-
```python
|
191
|
-
from kailash.workflow import Workflow
|
192
|
-
from kailash.nodes.data import SharePointGraphReader, CSVWriterNode
|
193
|
-
import os
|
194
|
-
|
195
|
-
# Create workflow for SharePoint file processing
|
196
|
-
workflow = Workflow("sharepoint_processor", name="sharepoint_processor")
|
197
|
-
|
198
|
-
# Configure SharePoint reader (using environment variables)
|
199
|
-
sharepoint = SharePointGraphReader()
|
200
|
-
workflow.add_node("read_sharepoint", sharepoint)
|
201
|
-
|
202
|
-
# Process downloaded files
|
203
|
-
csv_writer = CSVWriterNode(file_path="sharepoint_output.csv")
|
204
|
-
workflow.add_node("save_locally", csv_writer)
|
205
|
-
|
206
|
-
# Connect nodes
|
207
|
-
workflow.connect("read_sharepoint", "save_locally")
|
208
|
-
|
209
|
-
# Execute with credentials
|
210
|
-
from kailash.runtime.local import LocalRuntime
|
211
|
-
|
212
|
-
inputs = {
|
213
|
-
"read_sharepoint": {
|
214
|
-
"tenant_id": os.getenv("SHAREPOINT_TENANT_ID"),
|
215
|
-
"client_id": os.getenv("SHAREPOINT_CLIENT_ID"),
|
216
|
-
"client_secret": os.getenv("SHAREPOINT_CLIENT_SECRET"),
|
217
|
-
"site_url": "https://yourcompany.sharepoint.com/sites/YourSite",
|
218
|
-
"operation": "list_files",
|
219
|
-
"library_name": "Documents"
|
220
|
-
}
|
221
|
-
}
|
222
|
-
|
223
|
-
runtime = LocalRuntime()
|
224
|
-
results, run_id = runtime.execute(workflow, inputs=inputs)
|
225
|
-
```
|
226
|
-
|
227
|
-
### Hierarchical RAG Example
|
228
|
-
|
229
|
-
```python
|
230
|
-
from kailash.workflow import Workflow
|
231
|
-
from kailash.nodes.ai.embedding_generator import EmbeddingGeneratorNode
|
232
|
-
from kailash.nodes.ai.llm_agent import LLMAgentNode
|
233
|
-
from kailash.nodes.data.sources import DocumentSourceNode, QuerySourceNode
|
234
|
-
from kailash.nodes.data.retrieval import RelevanceScorerNode
|
235
|
-
from kailash.nodes.transform.chunkers import HierarchicalChunkerNode
|
236
|
-
from kailash.nodes.transform.formatters import (
|
237
|
-
ChunkTextExtractorNode, QueryTextWrapperNode, ContextFormatterNode
|
238
|
-
)
|
239
|
-
|
240
|
-
# Create hierarchical RAG workflow
|
241
|
-
workflow = Workflow("hierarchical_rag", name="Hierarchical RAG Workflow")
|
242
|
-
|
243
|
-
# Data sources (autonomous - no external files needed)
|
244
|
-
doc_source = DocumentSourceNode()
|
245
|
-
query_source = QuerySourceNode()
|
246
|
-
|
247
|
-
# Document processing pipeline
|
248
|
-
chunker = HierarchicalChunkerNode()
|
249
|
-
chunk_text_extractor = ChunkTextExtractorNode()
|
250
|
-
query_text_wrapper = QueryTextWrapperNode()
|
251
|
-
|
252
|
-
# AI processing with Ollama
|
253
|
-
chunk_embedder = EmbeddingGeneratorNode(
|
254
|
-
provider="ollama", model="nomic-embed-text", operation="embed_batch"
|
255
|
-
)
|
256
|
-
query_embedder = EmbeddingGeneratorNode(
|
257
|
-
provider="ollama", model="nomic-embed-text", operation="embed_batch"
|
258
|
-
)
|
259
|
-
|
260
|
-
# Retrieval and response generation
|
261
|
-
relevance_scorer = RelevanceScorerNode()
|
262
|
-
context_formatter = ContextFormatterNode()
|
263
|
-
llm_agent = LLMAgentNode(provider="ollama", model="llama3.2", temperature=0.7)
|
264
|
-
|
265
|
-
# Add all nodes to workflow
|
266
|
-
for name, node in {
|
267
|
-
"doc_source": doc_source, "query_source": query_source,
|
268
|
-
"chunker": chunker, "chunk_text_extractor": chunk_text_extractor,
|
269
|
-
"query_text_wrapper": query_text_wrapper, "chunk_embedder": chunk_embedder,
|
270
|
-
"query_embedder": query_embedder, "relevance_scorer": relevance_scorer,
|
271
|
-
"context_formatter": context_formatter, "llm_agent": llm_agent
|
272
|
-
}.items():
|
273
|
-
workflow.add_node(name, node)
|
274
|
-
|
275
|
-
# Connect the RAG pipeline
|
276
|
-
workflow.connect("doc_source", "chunker", {"documents": "documents"})
|
277
|
-
workflow.connect("chunker", "chunk_text_extractor", {"chunks": "chunks"})
|
278
|
-
workflow.connect("chunk_text_extractor", "chunk_embedder", {"input_texts": "input_texts"})
|
279
|
-
workflow.connect("query_source", "query_text_wrapper", {"query": "query"})
|
280
|
-
workflow.connect("query_text_wrapper", "query_embedder", {"input_texts": "input_texts"})
|
281
|
-
workflow.connect("chunker", "relevance_scorer", {"chunks": "chunks"})
|
282
|
-
workflow.connect("query_embedder", "relevance_scorer", {"embeddings": "query_embedding"})
|
283
|
-
workflow.connect("chunk_embedder", "relevance_scorer", {"embeddings": "chunk_embeddings"})
|
284
|
-
workflow.connect("relevance_scorer", "context_formatter", {"relevant_chunks": "relevant_chunks"})
|
285
|
-
workflow.connect("query_source", "context_formatter", {"query": "query"})
|
286
|
-
workflow.connect("context_formatter", "llm_agent", {"messages": "messages"})
|
287
|
-
|
288
|
-
# Execute the RAG workflow
|
289
|
-
from kailash.runtime.local import LocalRuntime
|
290
|
-
runtime = LocalRuntime()
|
291
|
-
results, run_id = runtime.execute(workflow)
|
292
|
-
|
293
|
-
print("RAG Response:", results["llm_agent"]["response"])
|
294
|
-
```
|
295
|
-
|
296
|
-
### Cyclic Workflows - Iterative Processing with Convergence
|
297
|
-
|
298
|
-
Build workflows that iterate until a condition is met, perfect for optimization, retries, and ML training:
|
299
|
-
|
300
|
-
```python
|
301
|
-
from kailash.workflow import Workflow
|
302
|
-
from kailash.nodes.base_cycle_aware import CycleAwareNode
|
303
|
-
from kailash.nodes.base import NodeParameter
|
304
|
-
from kailash.runtime.local import LocalRuntime
|
305
|
-
from typing import Any, Dict
|
306
|
-
|
307
|
-
# Create a custom cycle-aware node for data quality improvement
|
308
|
-
class DataQualityImproverNode(CycleAwareNode):
|
309
|
-
def get_parameters(self) -> Dict[str, NodeParameter]:
|
310
|
-
return {
|
311
|
-
"data": NodeParameter(name="data", type=list, required=True),
|
312
|
-
"target_quality": NodeParameter(name="target_quality", type=float, required=False, default=0.95)
|
313
|
-
}
|
314
|
-
|
315
|
-
def run(self, context: Dict[str, Any], **kwargs) -> Dict[str, Any]:
|
316
|
-
"""Iteratively improve data quality."""
|
317
|
-
data = kwargs["data"]
|
318
|
-
target_quality = kwargs.get("target_quality", 0.95)
|
319
|
-
|
320
|
-
# Get current iteration and previous state
|
321
|
-
iteration = self.get_iteration(context)
|
322
|
-
prev_state = self.get_previous_state(context)
|
323
|
-
|
324
|
-
# Calculate current quality
|
325
|
-
quality = prev_state.get("quality", 0.5) + 0.1 # Improve by 10% each iteration
|
326
|
-
quality = min(quality, 1.0)
|
327
|
-
|
328
|
-
# Process data (simplified)
|
329
|
-
processed_data = [item for item in data if item is not None]
|
330
|
-
|
331
|
-
# Track quality history
|
332
|
-
quality_history = self.accumulate_values(context, "quality_history", quality, max_history=10)
|
333
|
-
|
334
|
-
# Detect convergence trend
|
335
|
-
trend = self.detect_convergence_trend(context, "quality_history", window_size=5)
|
336
|
-
converged = quality >= target_quality or (trend and trend["slope"] < 0.01)
|
337
|
-
|
338
|
-
# Log progress
|
339
|
-
self.log_cycle_info(context, f"Iteration {iteration}: Quality={quality:.2%}")
|
340
|
-
|
341
|
-
# Save state for next iteration
|
342
|
-
self.set_cycle_state({"quality": quality, "processed_count": len(processed_data)})
|
343
|
-
|
344
|
-
return {
|
345
|
-
"data": processed_data,
|
346
|
-
"quality": quality,
|
347
|
-
"converged": converged,
|
348
|
-
"iteration": iteration,
|
349
|
-
"history": quality_history
|
350
|
-
}
|
351
|
-
|
352
|
-
# Build cyclic workflow
|
353
|
-
workflow = Workflow("quality_improvement", "Iterative Data Quality")
|
354
|
-
workflow.add_node("improver", DataQualityImproverNode())
|
355
|
-
|
356
|
-
# Create a cycle - node connects to itself!
|
357
|
-
workflow.connect("improver", "improver",
|
358
|
-
mapping={"data": "data"}, # Pass data to next iteration
|
359
|
-
cycle=True, # This is a cycle
|
360
|
-
max_iterations=20, # Safety limit
|
361
|
-
convergence_check="converged == True") # Stop condition
|
362
|
-
|
363
|
-
# Execute with automatic iteration management
|
364
|
-
runtime = LocalRuntime()
|
365
|
-
results, run_id = runtime.execute(workflow, parameters={
|
366
|
-
"improver": {
|
367
|
-
"data": [1, None, 3, None, 5, 6, None, 8, 9, 10],
|
368
|
-
"target_quality": 0.9
|
369
|
-
}
|
370
|
-
})
|
371
|
-
|
372
|
-
print(f"Converged after {results['improver']['iteration']} iterations")
|
373
|
-
print(f"Final quality: {results['improver']['quality']:.2%}")
|
374
|
-
print(f"Quality history: {results['improver']['history']}")
|
375
|
-
```
|
376
|
-
|
377
|
-
### NEW in v0.2.0: CycleBuilder API
|
378
|
-
|
379
|
-
The new CycleBuilder API provides a fluent interface for creating cyclic workflows:
|
380
|
-
|
381
|
-
```python
|
382
|
-
# Modern approach with CycleBuilder
|
383
|
-
workflow.create_cycle("optimization_loop")
|
384
|
-
.connect("gradient", "optimizer")
|
385
|
-
.connect("optimizer", "evaluator")
|
386
|
-
.connect("evaluator", "gradient")
|
387
|
-
.max_iterations(100)
|
388
|
-
.converge_when("loss < 0.01")
|
389
|
-
.early_stop_when("gradient_norm < 1e-6")
|
390
|
-
.checkpoint_every(10)
|
391
|
-
.build()
|
392
|
-
|
393
|
-
# Developer tools for production workflows
|
394
|
-
from kailash.workflow import CycleAnalyzer, CycleDebugger, CycleProfiler
|
395
|
-
|
396
|
-
# Analyze cycle patterns
|
397
|
-
analyzer = CycleAnalyzer(workflow)
|
398
|
-
report = analyzer.analyze()
|
399
|
-
print(f"Found {len(report.cycles)} cycles")
|
400
|
-
print(f"Max depth: {report.max_cycle_depth}")
|
401
|
-
|
402
|
-
# Debug with breakpoints
|
403
|
-
debugger = CycleDebugger(workflow)
|
404
|
-
debugger.set_breakpoint("optimizer", iteration=50)
|
405
|
-
debugger.set_trace("gradient_norm", lambda x: x < 0.001)
|
406
|
-
|
407
|
-
# Profile performance
|
408
|
-
profiler = CycleProfiler(workflow)
|
409
|
-
profile_data = profiler.profile(runtime, parameters)
|
410
|
-
print(f"Bottleneck: {profile_data.bottleneck_node}")
|
411
|
-
print(f"Iterations/sec: {profile_data.iterations_per_second}")
|
412
|
-
```
|
413
|
-
|
414
|
-
#### Cyclic Workflow Features
|
415
|
-
|
416
|
-
- **Built-in Iteration Management**: No manual loops or recursion needed
|
417
|
-
- **State Persistence**: Maintain state across iterations with `get_previous_state()` and `set_cycle_state()`
|
418
|
-
- **Convergence Detection**: Automatic trend analysis with `detect_convergence_trend()`
|
419
|
-
- **Value Accumulation**: Track metrics over time with `accumulate_values()`
|
420
|
-
- **Safety Limits**: Max iterations prevent infinite loops
|
421
|
-
- **Performance**: Optimized execution with ~30,000 iterations/second
|
422
|
-
- **Developer Tools**: CycleAnalyzer, CycleDebugger, CycleProfiler for production workflows
|
423
|
-
|
424
|
-
Common cyclic patterns include:
|
425
|
-
- **Retry with Backoff**: ETL pipelines with automatic retry
|
426
|
-
- **Optimization Loops**: Iterative parameter tuning
|
427
|
-
- **ML Training**: Training until accuracy threshold
|
428
|
-
- **Polling**: API polling with rate limiting
|
429
|
-
- **Stream Processing**: Windowed data processing
|
430
|
-
|
431
|
-
### Workflow API Wrapper - Expose Workflows as REST APIs
|
432
|
-
|
433
|
-
Transform any Kailash workflow into a production-ready REST API in just 3 lines of code:
|
434
|
-
|
435
|
-
```python
|
436
|
-
from kailash.api.workflow_api import WorkflowAPI
|
437
|
-
|
438
|
-
# Take any workflow and expose it as an API
|
439
|
-
api = WorkflowAPI(workflow)
|
440
|
-
api.run(port=8000) # That's it! Your workflow is now a REST API
|
441
|
-
```
|
442
|
-
|
443
|
-
#### Features
|
444
|
-
|
445
|
-
- **Automatic REST Endpoints**:
|
446
|
-
- `POST /execute` - Execute workflow with inputs
|
447
|
-
- `GET /workflow/info` - Get workflow metadata
|
448
|
-
- `GET /health` - Health check endpoint
|
449
|
-
- Automatic OpenAPI docs at `/docs`
|
450
|
-
|
451
|
-
- **Multiple Execution Modes**:
|
452
|
-
```python
|
453
|
-
# Synchronous execution (wait for results)
|
454
|
-
curl -X POST http://localhost:8000/execute \
|
455
|
-
-d '{"inputs": {...}, "mode": "sync"}'
|
456
|
-
|
457
|
-
# Asynchronous execution (get execution ID)
|
458
|
-
curl -X POST http://localhost:8000/execute \
|
459
|
-
-d '{"inputs": {...}, "mode": "async"}'
|
460
|
-
|
461
|
-
# Check async status
|
462
|
-
curl http://localhost:8000/status/{execution_id}
|
463
|
-
```
|
464
|
-
|
465
|
-
- **Specialized APIs** for specific domains:
|
466
|
-
```python
|
467
|
-
from kailash.api.workflow_api import create_workflow_api
|
468
|
-
|
469
|
-
# Create a RAG-specific API with custom endpoints
|
470
|
-
api = create_workflow_api(rag_workflow, api_type="rag")
|
471
|
-
# Adds /documents and /query endpoints
|
472
|
-
```
|
473
|
-
|
474
|
-
- **Production Ready**:
|
475
|
-
```python
|
476
|
-
# Development
|
477
|
-
api.run(reload=True, log_level="debug")
|
478
|
-
|
479
|
-
# Production with SSL
|
480
|
-
api.run(
|
481
|
-
host="0.0.0.0",
|
482
|
-
port=443,
|
483
|
-
ssl_keyfile="key.pem",
|
484
|
-
ssl_certfile="cert.pem",
|
485
|
-
workers=4
|
486
|
-
)
|
487
|
-
```
|
488
|
-
|
489
|
-
See the [API demo example](examples/integration_examples/integration_api_demo.py) for complete usage patterns.
|
490
|
-
|
491
|
-
### Multi-Workflow API Gateway - Manage Multiple Workflows
|
492
|
-
|
493
|
-
Run multiple workflows through a single unified API gateway with dynamic routing and MCP integration:
|
494
|
-
|
495
|
-
```python
|
496
|
-
from kailash.api.gateway import WorkflowAPIGateway
|
497
|
-
from kailash.api.mcp_integration import MCPIntegration
|
498
|
-
|
499
|
-
# Create gateway
|
500
|
-
gateway = WorkflowAPIGateway(
|
501
|
-
title="Enterprise Platform",
|
502
|
-
description="Unified API for all workflows"
|
503
|
-
)
|
504
|
-
|
505
|
-
# Register multiple workflows
|
506
|
-
gateway.register_workflow("sales", sales_workflow)
|
507
|
-
gateway.register_workflow("analytics", analytics_workflow)
|
508
|
-
gateway.register_workflow("reports", reporting_workflow)
|
509
|
-
|
510
|
-
# Add AI-powered tools via MCP
|
511
|
-
mcp = MCPIntegration("ai_tools")
|
512
|
-
mcp.add_tool("analyze", analyze_function)
|
513
|
-
mcp.add_tool("predict", predict_function)
|
514
|
-
gateway.register_mcp_server("ai", mcp)
|
515
|
-
|
516
|
-
# Run unified server
|
517
|
-
gateway.run(port=8000)
|
518
|
-
```
|
519
|
-
|
520
|
-
#### Gateway Features
|
521
|
-
|
522
|
-
- **Unified Access Point**: All workflows accessible through one server
|
523
|
-
- `/sales/execute` - Execute sales workflow
|
524
|
-
- `/analytics/execute` - Execute analytics workflow
|
525
|
-
- `/workflows` - List all available workflows
|
526
|
-
- `/health` - Check health of all services
|
527
|
-
|
528
|
-
- **MCP Integration**: AI-powered tools available to all workflows
|
529
|
-
```python
|
530
|
-
# Use MCP tools in workflows
|
531
|
-
from kailash.api.mcp_integration import MCPToolNode
|
532
|
-
|
533
|
-
tool_node = MCPToolNode(
|
534
|
-
mcp_server="ai_tools",
|
535
|
-
tool_name="analyze"
|
536
|
-
)
|
537
|
-
workflow.add_node("ai_analysis", tool_node)
|
538
|
-
```
|
539
|
-
|
540
|
-
- **Flexible Deployment Patterns**:
|
541
|
-
```python
|
542
|
-
# Pattern 1: Single Gateway (most cases)
|
543
|
-
gateway.register_workflow("workflow1", wf1)
|
544
|
-
gateway.register_workflow("workflow2", wf2)
|
545
|
-
|
546
|
-
# Pattern 2: Hybrid (heavy workflows separate)
|
547
|
-
gateway.register_workflow("light", light_wf)
|
548
|
-
gateway.proxy_workflow("heavy", "http://gpu-service:8080")
|
549
|
-
|
550
|
-
# Pattern 3: High Availability
|
551
|
-
# Run multiple gateway instances behind load balancer
|
552
|
-
|
553
|
-
# Pattern 4: Kubernetes
|
554
|
-
# Deploy with horizontal pod autoscaling
|
555
|
-
```
|
556
|
-
|
557
|
-
- **Production Features**:
|
558
|
-
- WebSocket support for real-time updates
|
559
|
-
- Health monitoring across all workflows
|
560
|
-
- Dynamic workflow registration/unregistration
|
561
|
-
- Built-in CORS and authentication support
|
562
|
-
|
563
|
-
See the [Gateway examples](examples/integration_examples/gateway_comprehensive_demo.py) for complete implementation patterns.
|
564
|
-
|
565
|
-
### Self-Organizing Agent Pools - Autonomous Multi-Agent Systems
|
566
|
-
|
567
|
-
Build intelligent agent systems that can autonomously form teams, share information, and solve complex problems collaboratively:
|
568
|
-
|
569
|
-
```python
|
570
|
-
from kailash import Workflow
|
571
|
-
from kailash.runtime import LocalRuntime
|
572
|
-
from kailash.nodes.ai.intelligent_agent_orchestrator import (
|
573
|
-
OrchestrationManagerNode,
|
574
|
-
IntelligentCacheNode,
|
575
|
-
ConvergenceDetectorNode
|
576
|
-
)
|
577
|
-
from kailash.nodes.ai.self_organizing import (
|
578
|
-
AgentPoolManagerNode,
|
579
|
-
TeamFormationNode,
|
580
|
-
ProblemAnalyzerNode
|
581
|
-
)
|
582
|
-
from kailash.nodes.ai.a2a import SharedMemoryPoolNode, A2AAgentNode
|
583
|
-
|
584
|
-
# Create self-organizing agent workflow
|
585
|
-
workflow = Workflow("self_organizing_research")
|
586
|
-
|
587
|
-
# Shared infrastructure
|
588
|
-
memory_pool = SharedMemoryPoolNode(
|
589
|
-
memory_size_limit=1000,
|
590
|
-
attention_window=50
|
591
|
-
)
|
592
|
-
workflow.add_node("memory", memory_pool)
|
593
|
-
|
594
|
-
# Intelligent caching to prevent redundant operations
|
595
|
-
cache = IntelligentCacheNode(
|
596
|
-
ttl=3600, # 1 hour cache
|
597
|
-
similarity_threshold=0.8,
|
598
|
-
max_entries=1000
|
599
|
-
)
|
600
|
-
workflow.add_node("cache", cache)
|
601
|
-
|
602
|
-
# Problem analysis and team formation
|
603
|
-
problem_analyzer = ProblemAnalyzerNode()
|
604
|
-
team_former = TeamFormationNode(
|
605
|
-
formation_strategy="capability_matching",
|
606
|
-
optimization_rounds=3
|
607
|
-
)
|
608
|
-
workflow.add_node("analyzer", problem_analyzer)
|
609
|
-
workflow.add_node("team_former", team_former)
|
610
|
-
|
611
|
-
# Self-organizing agent pool
|
612
|
-
pool_manager = AgentPoolManagerNode(
|
613
|
-
max_active_agents=20,
|
614
|
-
agent_timeout=120
|
615
|
-
)
|
616
|
-
workflow.add_node("pool", pool_manager)
|
617
|
-
|
618
|
-
# Convergence detection for stopping criteria
|
619
|
-
convergence = ConvergenceDetectorNode(
|
620
|
-
quality_threshold=0.85,
|
621
|
-
improvement_threshold=0.02,
|
622
|
-
max_iterations=10
|
623
|
-
)
|
624
|
-
workflow.add_node("convergence", convergence)
|
625
|
-
|
626
|
-
# Orchestration manager coordinates the entire system
|
627
|
-
orchestrator = OrchestrationManagerNode(
|
628
|
-
max_iterations=10,
|
629
|
-
quality_threshold=0.85,
|
630
|
-
parallel_execution=True
|
631
|
-
)
|
632
|
-
workflow.add_node("orchestrator", orchestrator)
|
633
|
-
|
634
|
-
# Execute with complex business problem
|
635
|
-
runtime = LocalRuntime()
|
636
|
-
result, _ = runtime.execute(workflow, parameters={
|
637
|
-
"orchestrator": {
|
638
|
-
"query": "Analyze market trends and develop growth strategy for fintech",
|
639
|
-
"agent_pool_size": 12,
|
640
|
-
"mcp_servers": [
|
641
|
-
{"name": "market_data", "command": "python", "args": ["-m", "market_mcp"]},
|
642
|
-
{"name": "financial", "command": "python", "args": ["-m", "finance_mcp"]},
|
643
|
-
{"name": "research", "command": "python", "args": ["-m", "research_mcp"]}
|
644
|
-
],
|
645
|
-
"context": {
|
646
|
-
"domain": "fintech",
|
647
|
-
"depth": "comprehensive",
|
648
|
-
"output_format": "strategic_report"
|
649
|
-
}
|
650
|
-
}
|
651
|
-
})
|
652
|
-
|
653
|
-
print(f"Solution Quality: {result['orchestrator']['quality_score']:.2%}")
|
654
|
-
print(f"Agents Used: {result['orchestrator']['agents_deployed']}")
|
655
|
-
print(f"Iterations: {result['orchestrator']['iterations_completed']}")
|
656
|
-
print(f"Final Strategy: {result['orchestrator']['final_solution']['strategy']}")
|
657
|
-
```
|
658
|
-
|
659
|
-
#### Key Self-Organizing Features
|
660
|
-
|
661
|
-
- **Autonomous Team Formation**: Agents automatically form optimal teams based on:
|
662
|
-
- Capability matching for skill-specific tasks
|
663
|
-
- Swarm-based formation for exploration
|
664
|
-
- Market-based allocation for resource constraints
|
665
|
-
- Hierarchical organization for complex problems
|
666
|
-
|
667
|
-
- **Intelligent Information Sharing**:
|
668
|
-
- **SharedMemoryPoolNode**: Selective attention mechanisms for relevant information
|
669
|
-
- **IntelligentCacheNode**: Semantic similarity detection prevents redundant operations
|
670
|
-
- **A2AAgentNode**: Direct agent-to-agent communication with context awareness
|
671
|
-
|
672
|
-
- **Convergence Detection**: Automatic termination when:
|
673
|
-
- Solution quality exceeds threshold (e.g., 85% confidence)
|
674
|
-
- Improvement rate drops below minimum (e.g., <2% per iteration)
|
675
|
-
- Maximum iterations reached
|
676
|
-
- Time limits exceeded
|
677
|
-
|
678
|
-
- **MCP Integration**: Agents can access external tools and data sources:
|
679
|
-
- File systems, databases, APIs
|
680
|
-
- Web scraping and research tools
|
681
|
-
- Specialized domain knowledge bases
|
682
|
-
- Real-time data streams
|
683
|
-
|
684
|
-
- **Performance Optimization**:
|
685
|
-
- Multi-level caching strategies
|
686
|
-
- Parallel agent execution
|
687
|
-
- Resource management and monitoring
|
688
|
-
- Cost tracking for API usage
|
689
|
-
|
690
|
-
See the [Self-Organizing Agents examples](examples/integration_examples/) for complete implementation patterns and the [Agent Systems Guide](docs/guides/self_organizing_agents.rst) for detailed documentation.
|
691
|
-
|
692
|
-
### Zero-Code MCP Ecosystem - Visual Workflow Builder
|
693
|
-
|
694
|
-
Build and deploy workflows through an interactive web interface without writing any code:
|
695
|
-
|
696
|
-
```python
|
697
|
-
from kailash.api.gateway import WorkflowAPIGateway
|
698
|
-
from kailash.api.mcp_integration import MCPServerRegistry
|
699
|
-
|
700
|
-
# Run the MCP ecosystem demo
|
701
|
-
# cd examples/integration_examples
|
702
|
-
# ./run_ecosystem.sh
|
703
|
-
|
704
|
-
# Or run programmatically:
|
705
|
-
python examples/integration_examples/mcp_ecosystem_demo.py
|
706
|
-
```
|
707
|
-
|
708
|
-
#### Features
|
709
|
-
|
710
|
-
- **Drag-and-Drop Builder**: Visual interface for creating workflows
|
711
|
-
- Drag nodes from palette (CSV Reader, Python Code, JSON Writer, etc.)
|
712
|
-
- Drop onto canvas to build workflows
|
713
|
-
- Deploy with one click
|
714
|
-
|
715
|
-
- **Live Dashboard**: Real-time monitoring and statistics
|
716
|
-
- Connected MCP server status
|
717
|
-
- Running workflow count
|
718
|
-
- Execution logs with timestamps
|
719
|
-
|
720
|
-
- **Pre-built Templates**: One-click deployment
|
721
|
-
- GitHub → Slack Notifier
|
722
|
-
- Data Processing Pipeline (CSV → Transform → JSON)
|
723
|
-
- AI Research Assistant
|
724
|
-
|
725
|
-
- **Technology Stack**: Lightweight and fast
|
726
|
-
- Backend: FastAPI + Kailash SDK
|
727
|
-
- Frontend: Vanilla HTML/CSS/JavaScript (no frameworks)
|
728
|
-
- Zero build process required
|
729
|
-
|
730
|
-
See the [MCP Ecosystem example](examples/integration_examples/) for the complete zero-code workflow deployment platform.
|
731
|
-
|
732
|
-
## 📚 Documentation
|
733
|
-
|
734
|
-
| Resource | Description |
|
735
|
-
|----------|-------------|
|
736
|
-
| 📖 [User Guide](docs/user-guide.md) | Comprehensive guide for using the SDK |
|
737
|
-
| 📋 [API Reference](docs/) | Detailed API documentation |
|
738
|
-
| 🌐 [API Integration Guide](examples/API_INTEGRATION_README.md) | Complete API integration documentation |
|
739
|
-
| 🎓 [Examples](examples/) | Working examples and tutorials |
|
740
|
-
| 🤝 [Contributing](CONTRIBUTING.md) | Contribution guidelines |
|
741
|
-
|
742
|
-
## 🛠️ Features
|
743
|
-
|
744
|
-
### 📦 Pre-built Nodes
|
745
|
-
|
746
|
-
The SDK includes a rich set of pre-built nodes for common operations:
|
747
|
-
|
748
|
-
<table>
|
749
|
-
<tr>
|
750
|
-
<td width="50%">
|
751
|
-
|
752
|
-
**Data Operations**
|
753
|
-
- `CSVReaderNode` - Read CSV files
|
754
|
-
- `JSONReaderNode` - Read JSON files
|
755
|
-
- `DocumentSourceNode` - Sample document provider
|
756
|
-
- `QuerySourceNode` - Sample query provider
|
757
|
-
- `RelevanceScorerNode` - Multi-method similarity
|
758
|
-
- `SQLDatabaseNode` - Query databases
|
759
|
-
- `CSVWriterNode` - Write CSV files
|
760
|
-
- `JSONWriterNode` - Write JSON files
|
761
|
-
|
762
|
-
</td>
|
763
|
-
<td width="50%">
|
764
|
-
|
765
|
-
**Transform Nodes**
|
766
|
-
- `PythonCodeNode` - Custom Python logic
|
767
|
-
- `DataTransformer` - Transform data
|
768
|
-
- `HierarchicalChunkerNode` - Document chunking
|
769
|
-
- `ChunkTextExtractorNode` - Extract chunk text
|
770
|
-
- `QueryTextWrapperNode` - Wrap queries for processing
|
771
|
-
- `ContextFormatterNode` - Format LLM context
|
772
|
-
- `Filter` - Filter records
|
773
|
-
- `Aggregator` - Aggregate data
|
774
|
-
|
775
|
-
**Logic Nodes**
|
776
|
-
- `SwitchNode` - Conditional routing
|
777
|
-
- `MergeNode` - Combine multiple inputs
|
778
|
-
- `WorkflowNode` - Wrap workflows as reusable nodes
|
779
|
-
|
780
|
-
</td>
|
781
|
-
</tr>
|
782
|
-
<tr>
|
783
|
-
<td width="50%">
|
784
|
-
|
785
|
-
**AI/ML Nodes**
|
786
|
-
- `LLMAgentNode` - Multi-provider LLM with memory & tools
|
787
|
-
- `EmbeddingGeneratorNode` - Vector embeddings with caching
|
788
|
-
- `MCPClient/MCPServer` - Model Context Protocol
|
789
|
-
- `TextClassifier` - Text classification
|
790
|
-
- `SentimentAnalyzer` - Sentiment analysis
|
791
|
-
- `NamedEntityRecognizer` - NER extraction
|
792
|
-
|
793
|
-
**Self-Organizing Agent Nodes**
|
794
|
-
- `SharedMemoryPoolNode` - Agent memory sharing
|
795
|
-
- `A2AAgentNode` - Agent-to-agent communication
|
796
|
-
- `A2ACoordinatorNode` - Multi-agent coordination
|
797
|
-
- `IntelligentCacheNode` - Semantic caching system
|
798
|
-
- `MCPAgentNode` - MCP-enabled agents
|
799
|
-
- `QueryAnalysisNode` - Query complexity analysis
|
800
|
-
- `OrchestrationManagerNode` - System orchestration
|
801
|
-
- `ConvergenceDetectorNode` - Solution convergence
|
802
|
-
- `AgentPoolManagerNode` - Agent pool management
|
803
|
-
- `ProblemAnalyzerNode` - Problem decomposition
|
804
|
-
- `TeamFormationNode` - Optimal team creation
|
805
|
-
- `SolutionEvaluatorNode` - Multi-criteria evaluation
|
806
|
-
- `SelfOrganizingAgentNode` - Adaptive individual agents
|
807
|
-
|
808
|
-
</td>
|
809
|
-
<td width="50%">
|
810
|
-
|
811
|
-
**API Integration Nodes**
|
812
|
-
- `HTTPRequestNode` - HTTP requests
|
813
|
-
- `RESTAPINode` - REST API client
|
814
|
-
- `GraphQLClientNode` - GraphQL queries
|
815
|
-
- `OAuth2AuthNode` - OAuth 2.0 authentication
|
816
|
-
- `RateLimitedAPINode` - Rate-limited API calls
|
817
|
-
|
818
|
-
**Other Integration Nodes**
|
819
|
-
- `KafkaConsumerNode` - Kafka streaming
|
820
|
-
- `WebSocketNode` - WebSocket connections
|
821
|
-
- `EmailNode` - Send emails
|
822
|
-
|
823
|
-
**SharePoint Integration**
|
824
|
-
- `SharePointGraphReader` - Read SharePoint files
|
825
|
-
- `SharePointGraphWriter` - Upload to SharePoint
|
826
|
-
|
827
|
-
**Real-time Monitoring**
|
828
|
-
- `RealTimeDashboard` - Live workflow monitoring
|
829
|
-
- `WorkflowPerformanceReporter` - Comprehensive reports
|
830
|
-
- `SimpleDashboardAPI` - REST API for metrics
|
831
|
-
- `DashboardAPIServer` - WebSocket streaming server
|
832
|
-
|
833
|
-
</td>
|
834
|
-
</tr>
|
835
|
-
</table>
|
836
|
-
|
837
|
-
### 🔧 Core Capabilities
|
838
|
-
|
839
|
-
#### Workflow Management
|
840
|
-
```python
|
841
|
-
from kailash.workflow import Workflow
|
842
|
-
from kailash.nodes.logic import SwitchNode
|
843
|
-
from kailash.nodes.transform import DataTransformer
|
844
|
-
|
845
|
-
# Create complex workflows with branching logic
|
846
|
-
workflow = Workflow("data_pipeline", name="data_pipeline")
|
847
|
-
|
848
|
-
# Add conditional branching with SwitchNode
|
849
|
-
switch = SwitchNode()
|
850
|
-
workflow.add_node("route", switch)
|
851
|
-
|
852
|
-
# Different paths based on validation
|
853
|
-
processor_a = DataTransformer(transformations=["lambda x: x"])
|
854
|
-
error_handler = DataTransformer(transformations=["lambda x: {'error': str(x)}"])
|
855
|
-
workflow.add_node("process_valid", processor_a)
|
856
|
-
workflow.add_node("handle_errors", error_handler)
|
857
|
-
|
858
|
-
# Connect with switch routing
|
859
|
-
workflow.connect("route", "process_valid")
|
860
|
-
workflow.connect("route", "handle_errors")
|
861
|
-
```
|
862
|
-
|
863
|
-
#### Hierarchical Workflow Composition
|
864
|
-
```python
|
865
|
-
from kailash.workflow import Workflow
|
866
|
-
from kailash.nodes.logic import WorkflowNode
|
867
|
-
from kailash.runtime.local import LocalRuntime
|
868
|
-
|
869
|
-
# Create a reusable data processing workflow
|
870
|
-
inner_workflow = Workflow("data_processor", name="Data Processor")
|
871
|
-
# ... add nodes to inner workflow ...
|
872
|
-
|
873
|
-
# Wrap the workflow as a node
|
874
|
-
processor_node = WorkflowNode(
|
875
|
-
workflow=inner_workflow,
|
876
|
-
name="data_processor"
|
877
|
-
)
|
878
|
-
|
879
|
-
# Use in a larger workflow
|
880
|
-
main_workflow = Workflow("main", name="Main Pipeline")
|
881
|
-
main_workflow.add_node("process", processor_node)
|
882
|
-
main_workflow.add_node("analyze", analyzer_node)
|
883
|
-
|
884
|
-
# Connect workflows
|
885
|
-
main_workflow.connect("process", "analyze")
|
886
|
-
|
887
|
-
# Execute - parameters automatically mapped to inner workflow
|
888
|
-
runtime = LocalRuntime()
|
889
|
-
results, _ = runtime.execute(main_workflow)
|
890
|
-
```
|
891
|
-
|
892
|
-
#### Immutable State Management
|
893
|
-
```python
|
894
|
-
from kailash.workflow import Workflow
|
895
|
-
from kailash.workflow.state import WorkflowStateWrapper
|
896
|
-
from pydantic import BaseModel
|
897
|
-
|
898
|
-
# Define state model
|
899
|
-
class MyStateModel(BaseModel):
|
900
|
-
counter: int = 0
|
901
|
-
status: str = "pending"
|
902
|
-
nested: dict = {}
|
903
|
-
|
904
|
-
# Create workflow
|
905
|
-
workflow = Workflow("state_workflow", name="state_workflow")
|
906
|
-
|
907
|
-
# Create and wrap state object
|
908
|
-
state = MyStateModel()
|
909
|
-
state_wrapper = workflow.create_state_wrapper(state)
|
910
|
-
|
911
|
-
# Single path-based update
|
912
|
-
updated_wrapper = state_wrapper.update_in(
|
913
|
-
["counter"],
|
914
|
-
42
|
915
|
-
)
|
916
|
-
|
917
|
-
# Batch update multiple fields atomically
|
918
|
-
updated_wrapper = state_wrapper.batch_update([
|
919
|
-
(["counter"], 10),
|
920
|
-
(["status"], "processing")
|
921
|
-
])
|
922
|
-
|
923
|
-
# Access the updated state
|
924
|
-
print(f"Updated counter: {updated_wrapper._state.counter}")
|
925
|
-
print(f"Updated status: {updated_wrapper._state.status}")
|
926
|
-
```
|
927
|
-
|
928
|
-
#### Task Tracking
|
929
|
-
```python
|
930
|
-
from kailash.tracking import TaskManager
|
931
|
-
|
932
|
-
# Initialize task manager
|
933
|
-
task_manager = TaskManager()
|
934
|
-
|
935
|
-
# Create a sample workflow
|
936
|
-
from kailash.workflow import Workflow
|
937
|
-
workflow = Workflow("sample_workflow", name="Sample Workflow")
|
938
|
-
|
939
|
-
# Run workflow with tracking
|
940
|
-
from kailash.runtime.local import LocalRuntime
|
941
|
-
runtime = LocalRuntime()
|
942
|
-
results, run_id = runtime.execute(workflow)
|
943
|
-
|
944
|
-
# Query execution history
|
945
|
-
# Note: list_runs() may fail with timezone comparison errors in some cases
|
946
|
-
try:
|
947
|
-
# List all runs
|
948
|
-
all_runs = task_manager.list_runs()
|
949
|
-
|
950
|
-
# Filter by status
|
951
|
-
completed_runs = task_manager.list_runs(status="completed")
|
952
|
-
failed_runs = task_manager.list_runs(status="failed")
|
953
|
-
|
954
|
-
# Filter by workflow name
|
955
|
-
workflow_runs = task_manager.list_runs(workflow_name="sample_workflow")
|
956
|
-
|
957
|
-
# Process run information
|
958
|
-
for run in completed_runs[:5]: # First 5 runs
|
959
|
-
print(f"Run {run.run_id[:8]}: {run.workflow_name} - {run.status}")
|
960
|
-
|
961
|
-
except Exception as e:
|
962
|
-
print(f"Error listing runs: {e}")
|
963
|
-
# Fallback: Access run details directly if available
|
964
|
-
if hasattr(task_manager, 'storage'):
|
965
|
-
run = task_manager.get_run(run_id)
|
966
|
-
```
|
967
|
-
|
968
|
-
#### Local Testing
|
969
|
-
```python
|
970
|
-
from kailash.runtime.local import LocalRuntime
|
971
|
-
from kailash.workflow import Workflow
|
972
|
-
|
973
|
-
# Create a test workflow
|
974
|
-
workflow = Workflow("test_workflow", name="test_workflow")
|
975
|
-
|
976
|
-
# Create test runtime with debugging enabled
|
977
|
-
runtime = LocalRuntime(debug=True)
|
978
|
-
|
979
|
-
# Execute with test data
|
980
|
-
results, run_id = runtime.execute(workflow)
|
981
|
-
|
982
|
-
# Validate results
|
983
|
-
assert isinstance(results, dict)
|
984
|
-
```
|
985
|
-
|
986
|
-
#### Performance Monitoring & Real-time Dashboards
|
987
|
-
```python
|
988
|
-
from kailash.visualization.performance import PerformanceVisualizer
|
989
|
-
from kailash.visualization.dashboard import RealTimeDashboard, DashboardConfig
|
990
|
-
from kailash.visualization.reports import WorkflowPerformanceReporter, ReportFormat
|
991
|
-
from kailash.tracking import TaskManager
|
992
|
-
from kailash.runtime.local import LocalRuntime
|
993
|
-
from kailash.workflow import Workflow
|
994
|
-
from kailash.nodes.transform import DataTransformer
|
995
|
-
|
996
|
-
# Create a workflow to monitor
|
997
|
-
workflow = Workflow("monitored_workflow", name="monitored_workflow")
|
998
|
-
node = DataTransformer(transformations=["lambda x: x"])
|
999
|
-
workflow.add_node("transform", node)
|
1000
|
-
|
1001
|
-
# Run workflow with task tracking
|
1002
|
-
# Note: Pass task_manager to execute() to enable performance tracking
|
1003
|
-
task_manager = TaskManager()
|
1004
|
-
runtime = LocalRuntime()
|
1005
|
-
results, run_id = runtime.execute(workflow, task_manager=task_manager)
|
1006
|
-
|
1007
|
-
# Static performance analysis
|
1008
|
-
from pathlib import Path
|
1009
|
-
perf_viz = PerformanceVisualizer(task_manager)
|
1010
|
-
outputs = perf_viz.create_run_performance_summary(run_id, output_dir=Path("performance_report"))
|
1011
|
-
|
1012
|
-
# Real-time monitoring dashboard
|
1013
|
-
config = DashboardConfig(
|
1014
|
-
update_interval=1.0,
|
1015
|
-
max_history_points=100,
|
1016
|
-
auto_refresh=True,
|
1017
|
-
theme="light"
|
1018
|
-
)
|
1019
|
-
|
1020
|
-
dashboard = RealTimeDashboard(task_manager, config)
|
1021
|
-
dashboard.start_monitoring(run_id)
|
1022
|
-
|
1023
|
-
# Add real-time callbacks
|
1024
|
-
def on_metrics_update(metrics):
|
1025
|
-
print(f"Tasks: {metrics.completed_tasks} completed, {metrics.active_tasks} active")
|
1026
|
-
|
1027
|
-
dashboard.add_metrics_callback(on_metrics_update)
|
1028
|
-
|
1029
|
-
# Generate live HTML dashboard
|
1030
|
-
dashboard.generate_live_report("live_dashboard.html", include_charts=True)
|
1031
|
-
dashboard.stop_monitoring()
|
1032
|
-
|
1033
|
-
# Comprehensive performance reports
|
1034
|
-
reporter = WorkflowPerformanceReporter(task_manager)
|
1035
|
-
report_path = reporter.generate_report(
|
1036
|
-
run_id,
|
1037
|
-
output_path="workflow_report.html",
|
1038
|
-
format=ReportFormat.HTML
|
1039
|
-
)
|
1040
|
-
```
|
1041
|
-
|
1042
|
-
**Real-time Dashboard Features**:
|
1043
|
-
- ⚡ **Live Metrics Streaming**: Real-time task progress and resource monitoring
|
1044
|
-
- 📊 **Interactive Charts**: CPU, memory, and throughput visualizations with Chart.js
|
1045
|
-
- 🔌 **API Endpoints**: REST and WebSocket APIs for custom integrations
|
1046
|
-
- 📈 **Performance Reports**: Multi-format reports (HTML, Markdown, JSON) with insights
|
1047
|
-
- 🎯 **Bottleneck Detection**: Automatic identification of performance issues
|
1048
|
-
- 📱 **Responsive Design**: Mobile-friendly dashboards with auto-refresh
|
1049
|
-
|
1050
|
-
**Performance Metrics Collected**:
|
1051
|
-
- **Execution Timeline**: Gantt charts showing node execution order and duration
|
1052
|
-
- **Resource Usage**: Real-time CPU and memory consumption
|
1053
|
-
- **I/O Analysis**: Read/write operations and data transfer volumes
|
1054
|
-
- **Performance Heatmaps**: Identify bottlenecks across workflow runs
|
1055
|
-
- **Throughput Metrics**: Tasks per minute and completion rates
|
1056
|
-
- **Error Tracking**: Failed task analysis and error patterns
|
1057
|
-
|
1058
|
-
#### API Integration
|
1059
|
-
```python
|
1060
|
-
from kailash.nodes.api import (
|
1061
|
-
HTTPRequestNode as RESTAPINode,
|
1062
|
-
# OAuth2AuthNode,
|
1063
|
-
# RateLimitedAPINode,
|
1064
|
-
# RateLimitConfig
|
1065
|
-
)
|
1066
|
-
|
1067
|
-
# OAuth 2.0 authentication
|
1068
|
-
# # auth_node = OAuth2AuthNode(
|
1069
|
-
# client_id="your_client_id",
|
1070
|
-
# client_secret="your_client_secret",
|
1071
|
-
# token_url="https://api.example.com/oauth/token"
|
1072
|
-
# )
|
1073
|
-
|
1074
|
-
# Rate-limited API client
|
1075
|
-
rate_config = None # RateLimitConfig(
|
1076
|
-
# max_requests=100,
|
1077
|
-
# time_window=60.0,
|
1078
|
-
# strategy="token_bucket"
|
1079
|
-
# )
|
1080
|
-
|
1081
|
-
api_client = RESTAPINode(
|
1082
|
-
base_url="https://api.example.com"
|
1083
|
-
# auth_node=auth_node
|
1084
|
-
)
|
1085
|
-
|
1086
|
-
# rate_limited_client = RateLimitedAPINode(
|
1087
|
-
# wrapped_node=api_client,
|
1088
|
-
# rate_limit_config=rate_config
|
1089
|
-
# )
|
1090
|
-
```
|
1091
|
-
|
1092
|
-
#### Export Formats
|
1093
|
-
```python
|
1094
|
-
from kailash.utils.export import WorkflowExporter, ExportConfig
|
1095
|
-
from kailash.workflow import Workflow
|
1096
|
-
from kailash.nodes.transform import DataTransformer
|
1097
|
-
|
1098
|
-
# Create a workflow to export
|
1099
|
-
workflow = Workflow("export_example", name="export_example")
|
1100
|
-
node = DataTransformer(transformations=["lambda x: x"])
|
1101
|
-
workflow.add_node("transform", node)
|
1102
|
-
|
1103
|
-
exporter = WorkflowExporter()
|
1104
|
-
|
1105
|
-
# Export to different formats
|
1106
|
-
workflow.save("workflow.yaml", format="yaml") # Kailash YAML format
|
1107
|
-
workflow.save("workflow.json", format="json") # JSON representation
|
1108
|
-
|
1109
|
-
# Export with custom configuration
|
1110
|
-
config = ExportConfig(
|
1111
|
-
include_metadata=True,
|
1112
|
-
container_tag="latest"
|
1113
|
-
)
|
1114
|
-
workflow.save("deployment.yaml")
|
1115
|
-
```
|
1116
|
-
|
1117
|
-
### 🎨 Visualization
|
1118
|
-
|
1119
|
-
```python
|
1120
|
-
from kailash.workflow import Workflow
|
1121
|
-
from kailash.workflow.visualization import WorkflowVisualizer
|
1122
|
-
from kailash.nodes.transform import DataTransformer
|
1123
|
-
|
1124
|
-
# Create a workflow to visualize
|
1125
|
-
workflow = Workflow("viz_example", name="viz_example")
|
1126
|
-
node = DataTransformer(transformations=["lambda x: x"])
|
1127
|
-
workflow.add_node("transform", node)
|
1128
|
-
|
1129
|
-
# Generate Mermaid diagram (recommended for documentation)
|
1130
|
-
mermaid_code = workflow.to_mermaid()
|
1131
|
-
print(mermaid_code)
|
1132
|
-
|
1133
|
-
# Save as Mermaid markdown file
|
1134
|
-
with open("workflow.md", "w") as f:
|
1135
|
-
f.write(workflow.to_mermaid_markdown(title="My Workflow"))
|
1136
|
-
|
1137
|
-
# Or use matplotlib visualization
|
1138
|
-
visualizer = WorkflowVisualizer(workflow)
|
1139
|
-
visualizer.visualize()
|
1140
|
-
visualizer.save("workflow.png", dpi=300) # Save as PNG
|
1141
|
-
```
|
1142
|
-
|
1143
|
-
#### Hierarchical RAG (Retrieval-Augmented Generation)
|
1144
|
-
```python
|
1145
|
-
from kailash.workflow import Workflow
|
1146
|
-
from kailash.nodes.data.sources import DocumentSourceNode, QuerySourceNode
|
1147
|
-
from kailash.nodes.data.retrieval import RelevanceScorerNode
|
1148
|
-
from kailash.nodes.transform.chunkers import HierarchicalChunkerNode
|
1149
|
-
from kailash.nodes.transform.formatters import (
|
1150
|
-
ChunkTextExtractorNode,
|
1151
|
-
QueryTextWrapperNode,
|
1152
|
-
ContextFormatterNode,
|
1153
|
-
)
|
1154
|
-
from kailash.nodes.ai.llm_agent import LLMAgent
|
1155
|
-
from kailash.nodes.ai.embedding_generator import EmbeddingGenerator
|
1156
|
-
|
1157
|
-
# Create hierarchical RAG workflow
|
1158
|
-
workflow = Workflow(
|
1159
|
-
workflow_id="hierarchical_rag_example",
|
1160
|
-
name="Hierarchical RAG Workflow",
|
1161
|
-
description="Complete RAG pipeline with embedding-based retrieval",
|
1162
|
-
version="1.0.0"
|
1163
|
-
)
|
1164
|
-
|
1165
|
-
# Create data source nodes
|
1166
|
-
doc_source = DocumentSourceNode()
|
1167
|
-
query_source = QuerySourceNode()
|
1168
|
-
|
1169
|
-
# Create document processing pipeline
|
1170
|
-
chunker = HierarchicalChunkerNode()
|
1171
|
-
chunk_text_extractor = ChunkTextExtractorNode()
|
1172
|
-
query_text_wrapper = QueryTextWrapperNode()
|
1173
|
-
|
1174
|
-
# Create embedding generators
|
1175
|
-
chunk_embedder = EmbeddingGeneratorNode(
|
1176
|
-
provider="ollama",
|
1177
|
-
model="nomic-embed-text",
|
1178
|
-
operation="embed_batch"
|
1179
|
-
)
|
1180
|
-
|
1181
|
-
query_embedder = EmbeddingGeneratorNode(
|
1182
|
-
provider="ollama",
|
1183
|
-
model="nomic-embed-text",
|
1184
|
-
operation="embed_batch"
|
1185
|
-
)
|
1186
|
-
|
1187
|
-
# Create retrieval and formatting nodes
|
1188
|
-
relevance_scorer = RelevanceScorerNode(similarity_method="cosine")
|
1189
|
-
context_formatter = ContextFormatterNode()
|
1190
|
-
|
1191
|
-
# Create LLM agent for final answer generation
|
1192
|
-
llm_agent = LLMAgentNode(
|
1193
|
-
provider="ollama",
|
1194
|
-
model="llama3.2",
|
1195
|
-
temperature=0.7,
|
1196
|
-
max_tokens=500
|
1197
|
-
)
|
1198
|
-
|
1199
|
-
# Add all nodes to workflow
|
1200
|
-
for node_id, node in [
|
1201
|
-
("doc_source", doc_source),
|
1202
|
-
("chunker", chunker),
|
1203
|
-
("query_source", query_source),
|
1204
|
-
("chunk_text_extractor", chunk_text_extractor),
|
1205
|
-
("query_text_wrapper", query_text_wrapper),
|
1206
|
-
("chunk_embedder", chunk_embedder),
|
1207
|
-
("query_embedder", query_embedder),
|
1208
|
-
("relevance_scorer", relevance_scorer),
|
1209
|
-
("context_formatter", context_formatter),
|
1210
|
-
("llm_agent", llm_agent)
|
1211
|
-
]:
|
1212
|
-
workflow.add_node(node_id, node)
|
1213
|
-
|
1214
|
-
# Connect the workflow pipeline
|
1215
|
-
# Document processing: docs → chunks → text → embeddings
|
1216
|
-
workflow.connect("doc_source", "chunker", {"documents": "documents"})
|
1217
|
-
workflow.connect("chunker", "chunk_text_extractor", {"chunks": "chunks"})
|
1218
|
-
workflow.connect("chunk_text_extractor", "chunk_embedder", {"input_texts": "input_texts"})
|
1219
|
-
|
1220
|
-
# Query processing: query → text wrapper → embeddings
|
1221
|
-
workflow.connect("query_source", "query_text_wrapper", {"query": "query"})
|
1222
|
-
workflow.connect("query_text_wrapper", "query_embedder", {"input_texts": "input_texts"})
|
1223
|
-
|
1224
|
-
# Relevance scoring: chunks + embeddings → scored chunks
|
1225
|
-
workflow.connect("chunker", "relevance_scorer", {"chunks": "chunks"})
|
1226
|
-
workflow.connect("query_embedder", "relevance_scorer", {"embeddings": "query_embedding"})
|
1227
|
-
workflow.connect("chunk_embedder", "relevance_scorer", {"embeddings": "chunk_embeddings"})
|
1228
|
-
|
1229
|
-
# Context formatting: relevant chunks + query → formatted context
|
1230
|
-
workflow.connect("relevance_scorer", "context_formatter", {"relevant_chunks": "relevant_chunks"})
|
1231
|
-
workflow.connect("query_source", "context_formatter", {"query": "query"})
|
1232
|
-
|
1233
|
-
# Final answer generation: formatted context → LLM response
|
1234
|
-
workflow.connect("context_formatter", "llm_agent", {"messages": "messages"})
|
1235
|
-
|
1236
|
-
# Execute workflow
|
1237
|
-
results, run_id = workflow.run()
|
1238
|
-
|
1239
|
-
# Access results
|
1240
|
-
print("🎯 Top Relevant Chunks:")
|
1241
|
-
for chunk in results["relevance_scorer"]["relevant_chunks"]:
|
1242
|
-
print(f" - {chunk['document_title']}: {chunk['relevance_score']:.3f}")
|
1243
|
-
|
1244
|
-
print("\n🤖 Final Answer:")
|
1245
|
-
print(results["llm_agent"]["response"]["content"])
|
1246
|
-
```
|
1247
|
-
|
1248
|
-
This example demonstrates:
|
1249
|
-
- **Document chunking** with hierarchical structure
|
1250
|
-
- **Vector embeddings** using Ollama's nomic-embed-text model
|
1251
|
-
- **Semantic similarity** scoring with cosine similarity
|
1252
|
-
- **Context formatting** for LLM input
|
1253
|
-
- **Answer generation** using Ollama's llama3.2 model
|
1254
|
-
|
1255
|
-
### 🔒 Access Control and Security
|
1256
|
-
|
1257
|
-
Kailash SDK provides comprehensive access control and security features for enterprise deployments:
|
1258
|
-
|
1259
|
-
#### Role-Based Access Control (RBAC)
|
1260
|
-
```python
|
1261
|
-
from kailash.access_control import UserContext, PermissionRule, NodePermission
|
1262
|
-
from kailash.runtime.access_controlled import AccessControlledRuntime
|
1263
|
-
|
1264
|
-
# Define user with roles
|
1265
|
-
user = UserContext(
|
1266
|
-
user_id="analyst_001",
|
1267
|
-
tenant_id="company_abc",
|
1268
|
-
email="analyst@company.com",
|
1269
|
-
roles=["analyst", "viewer"]
|
1270
|
-
)
|
1271
|
-
|
1272
|
-
# Create secure runtime
|
1273
|
-
runtime = AccessControlledRuntime(user_context=user)
|
1274
|
-
|
1275
|
-
# Execute workflow with automatic permission checks
|
1276
|
-
results, run_id = runtime.execute(workflow, parameters={})
|
1277
|
-
```
|
1278
|
-
|
1279
|
-
#### Multi-Tenant Isolation
|
1280
|
-
```python
|
1281
|
-
from kailash.access_control import get_access_control_manager, PermissionEffect, WorkflowPermission
|
1282
|
-
|
1283
|
-
# Configure tenant-based access rules
|
1284
|
-
acm = get_access_control_manager()
|
1285
|
-
acm.enabled = True
|
1286
|
-
|
1287
|
-
# Tenant isolation rule
|
1288
|
-
acm.add_rule(PermissionRule(
|
1289
|
-
id="tenant_isolation",
|
1290
|
-
resource_type="workflow",
|
1291
|
-
resource_id="customer_analytics",
|
1292
|
-
permission=WorkflowPermission.EXECUTE,
|
1293
|
-
effect=PermissionEffect.ALLOW,
|
1294
|
-
tenant_id="company_abc" # Only this tenant can access
|
1295
|
-
))
|
1296
|
-
```
|
1297
|
-
|
1298
|
-
#### Data Masking and Field Protection
|
1299
|
-
```python
|
1300
|
-
from kailash.nodes.base_with_acl import add_access_control
|
1301
|
-
|
1302
|
-
# Add access control to sensitive data nodes
|
1303
|
-
secure_reader = add_access_control(
|
1304
|
-
CSVReaderNode(file_path="customers.csv"),
|
1305
|
-
enable_access_control=True,
|
1306
|
-
required_permission=NodePermission.READ_OUTPUT,
|
1307
|
-
mask_output_fields=["ssn", "phone"] # Mask for non-admin users
|
1308
|
-
)
|
1309
|
-
|
1310
|
-
workflow.add_node("secure_data", secure_reader)
|
1311
|
-
```
|
1312
|
-
|
1313
|
-
#### Permission-Based Routing
|
1314
|
-
```python
|
1315
|
-
# Different execution paths based on user permissions
|
1316
|
-
from kailash.access_control import NodePermission
|
1317
|
-
|
1318
|
-
# Admin users get full processing
|
1319
|
-
admin_processor = PythonCodeNode.from_function(
|
1320
|
-
lambda data: {"result": process_all_data(data)},
|
1321
|
-
name="admin_processor"
|
1322
|
-
)
|
1323
|
-
|
1324
|
-
# Analyst users get limited processing
|
1325
|
-
analyst_processor = PythonCodeNode.from_function(
|
1326
|
-
lambda data: {"result": process_limited_data(data)},
|
1327
|
-
name="analyst_processor"
|
1328
|
-
)
|
1329
|
-
|
1330
|
-
# Runtime automatically routes based on user permissions
|
1331
|
-
workflow.add_node("admin_path", admin_processor)
|
1332
|
-
workflow.add_node("analyst_path", analyst_processor)
|
1333
|
-
```
|
1334
|
-
|
1335
|
-
**Security Features:**
|
1336
|
-
- 🔐 **JWT Authentication**: Token-based authentication with refresh support
|
1337
|
-
- 👥 **Multi-Tenant Isolation**: Complete data separation between tenants
|
1338
|
-
- 🛡️ **Field-Level Security**: Mask sensitive data based on user roles
|
1339
|
-
- 📊 **Audit Logging**: Complete access attempt logging for compliance
|
1340
|
-
- 🚫 **Path Traversal Prevention**: Built-in protection against directory attacks
|
1341
|
-
- 🏗️ **Backward Compatibility**: Existing workflows work unchanged
|
1342
|
-
- ⚡ **Performance Optimized**: Minimal overhead with caching
|
1343
|
-
|
1344
|
-
## 💻 CLI Commands
|
1345
|
-
|
1346
|
-
The SDK includes a comprehensive CLI for workflow management:
|
1347
|
-
|
1348
|
-
```bash
|
1349
|
-
# Project initialization
|
1350
|
-
kailash init my-project --template data-pipeline
|
1351
|
-
|
1352
|
-
# Workflow operations
|
1353
|
-
kailash validate workflow.yaml
|
1354
|
-
kailash run workflow.yaml --inputs data.json
|
1355
|
-
kailash export workflow.py --format kubernetes
|
1356
|
-
|
1357
|
-
# Task management
|
1358
|
-
kailash tasks list --status running
|
1359
|
-
kailash tasks show run-123
|
1360
|
-
kailash tasks cancel run-123
|
1361
|
-
|
1362
|
-
# Development tools
|
1363
|
-
kailash test workflow.yaml --data test_data.json
|
1364
|
-
kailash debug workflow.yaml --breakpoint node-id
|
1365
|
-
```
|
1366
|
-
|
1367
|
-
## 🏗️ Architecture
|
1368
|
-
|
1369
|
-
The SDK follows a clean, modular architecture:
|
1370
|
-
|
1371
|
-
```
|
1372
|
-
kailash/
|
1373
|
-
├── nodes/ # Node implementations and base classes
|
1374
|
-
│ ├── base.py # Abstract Node class
|
1375
|
-
│ ├── data/ # Data I/O nodes
|
1376
|
-
│ ├── transform/ # Transformation nodes
|
1377
|
-
│ ├── logic/ # Business logic nodes
|
1378
|
-
│ └── ai/ # AI/ML nodes
|
1379
|
-
├── workflow/ # Workflow management
|
1380
|
-
│ ├── graph.py # DAG representation
|
1381
|
-
│ └── visualization.py # Visualization tools
|
1382
|
-
├── visualization/ # Performance visualization
|
1383
|
-
│ └── performance.py # Performance metrics charts
|
1384
|
-
├── runtime/ # Execution engines
|
1385
|
-
│ ├── local.py # Local execution
|
1386
|
-
│ └── docker.py # Docker execution (planned)
|
1387
|
-
├── tracking/ # Monitoring and tracking
|
1388
|
-
│ ├── manager.py # Task management
|
1389
|
-
│ └── metrics_collector.py # Performance metrics
|
1390
|
-
│ └── storage/ # Storage backends
|
1391
|
-
├── cli/ # Command-line interface
|
1392
|
-
└── utils/ # Utilities and helpers
|
1393
|
-
```
|
1394
|
-
|
1395
|
-
### 🤖 Unified AI Provider Architecture
|
1396
|
-
|
1397
|
-
The SDK features a unified provider architecture for AI capabilities:
|
1398
|
-
|
1399
|
-
```python
|
1400
|
-
from kailash.nodes.ai import LLMAgentNode, EmbeddingGeneratorNode
|
1401
|
-
|
1402
|
-
# Multi-provider LLM support
|
1403
|
-
agent = LLMAgentNode()
|
1404
|
-
result = agent.run(
|
1405
|
-
provider="ollama", # or "openai", "anthropic", "mock"
|
1406
|
-
model="llama3.1:8b-instruct-q8_0",
|
1407
|
-
messages=[{"role": "user", "content": "Explain quantum computing"}],
|
1408
|
-
generation_config={"temperature": 0.7, "max_tokens": 500}
|
1409
|
-
)
|
1410
|
-
|
1411
|
-
# Vector embeddings with the same providers
|
1412
|
-
embedder = EmbeddingGeneratorNode()
|
1413
|
-
embedding = embedder.run(
|
1414
|
-
provider="ollama", # Same providers support embeddings
|
1415
|
-
model="snowflake-arctic-embed2",
|
1416
|
-
operation="embed_text",
|
1417
|
-
input_text="Quantum computing uses quantum mechanics principles"
|
1418
|
-
)
|
1419
|
-
|
1420
|
-
# Check available providers and capabilities
|
1421
|
-
from kailash.nodes.ai.ai_providers import get_available_providers
|
1422
|
-
providers = get_available_providers()
|
1423
|
-
# Returns: {"ollama": {"available": True, "chat": True, "embeddings": True}, ...}
|
1424
|
-
```
|
1425
|
-
|
1426
|
-
**Supported AI Providers:**
|
1427
|
-
- **Ollama**: Local LLMs with both chat and embeddings (llama3.1, mistral, etc.)
|
1428
|
-
- **OpenAI**: GPT models and text-embedding-3 series
|
1429
|
-
- **Anthropic**: Claude models (chat only)
|
1430
|
-
- **Cohere**: Embedding models (embed-english-v3.0)
|
1431
|
-
- **HuggingFace**: Sentence transformers and local models
|
1432
|
-
- **Mock**: Testing provider with consistent outputs
|
1433
|
-
|
1434
|
-
## 🧪 Testing
|
1435
|
-
|
1436
|
-
The SDK is thoroughly tested with comprehensive test suites:
|
1437
|
-
|
1438
|
-
```bash
|
1439
|
-
# Run all tests
|
1440
|
-
uv run pytest
|
1441
|
-
|
1442
|
-
# Run with coverage
|
1443
|
-
uv run pytest --cov=kailash --cov-report=html
|
1444
|
-
|
1445
|
-
# Run specific test categories
|
1446
|
-
uv run pytest tests/unit/
|
1447
|
-
uv run pytest tests/integration/
|
1448
|
-
uv run pytest tests/e2e/
|
1449
|
-
```
|
1450
|
-
|
1451
|
-
## 🤝 Contributing
|
1452
|
-
|
1453
|
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
1454
|
-
|
1455
|
-
### Development Setup
|
1456
|
-
|
1457
|
-
```bash
|
1458
|
-
# Clone the repository
|
1459
|
-
git clone https://github.com/integrum/kailash-python-sdk.git
|
1460
|
-
cd kailash-python-sdk
|
1461
|
-
|
1462
|
-
# Install uv if you haven't already
|
1463
|
-
curl -LsSf https://astral.sh/uv/install.sh | sh
|
1464
|
-
|
1465
|
-
# Sync dependencies (creates venv automatically and installs everything)
|
1466
|
-
uv sync
|
1467
|
-
|
1468
|
-
# Run commands using uv (no need to activate venv)
|
1469
|
-
uv run pytest
|
1470
|
-
uv run kailash --help
|
1471
|
-
|
1472
|
-
# Or activate the venv if you prefer
|
1473
|
-
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
1474
|
-
|
1475
|
-
# Install development dependencies
|
1476
|
-
uv add --dev pre-commit detect-secrets doc8
|
1477
|
-
|
1478
|
-
# Install Trivy (macOS with Homebrew)
|
1479
|
-
brew install trivy
|
1480
|
-
|
1481
|
-
# Set up pre-commit hooks
|
1482
|
-
pre-commit install
|
1483
|
-
pre-commit install --hook-type pre-push
|
1484
|
-
|
1485
|
-
# Run initial setup (formats code and fixes issues)
|
1486
|
-
pre-commit run --all-files
|
1487
|
-
```
|
1488
|
-
|
1489
|
-
### Code Quality & Pre-commit Hooks
|
1490
|
-
|
1491
|
-
We use automated pre-commit hooks to ensure code quality:
|
1492
|
-
|
1493
|
-
**Hooks Include:**
|
1494
|
-
- **Black**: Code formatting
|
1495
|
-
- **isort**: Import sorting
|
1496
|
-
- **Ruff**: Fast Python linting
|
1497
|
-
- **pytest**: Unit tests
|
1498
|
-
- **Trivy**: Security vulnerability scanning
|
1499
|
-
- **detect-secrets**: Secret detection
|
1500
|
-
- **doc8**: Documentation linting
|
1501
|
-
- **mypy**: Type checking
|
1502
|
-
|
1503
|
-
**Manual Quality Checks:**
|
1504
|
-
```bash
|
1505
|
-
# Format code
|
1506
|
-
black src/ tests/
|
1507
|
-
isort src/ tests/
|
1508
|
-
|
1509
|
-
# Linting and fixes
|
1510
|
-
ruff check src/ tests/ --fix
|
1511
|
-
|
1512
|
-
# Type checking
|
1513
|
-
mypy src/
|
1514
|
-
|
1515
|
-
# Run all pre-commit hooks manually
|
1516
|
-
pre-commit run --all-files
|
1517
|
-
|
1518
|
-
# Run specific hooks
|
1519
|
-
pre-commit run black
|
1520
|
-
pre-commit run pytest-check
|
1521
|
-
```
|
1522
|
-
|
1523
|
-
## 📈 Project Status
|
1524
|
-
|
1525
|
-
<table>
|
1526
|
-
<tr>
|
1527
|
-
<td width="40%">
|
1528
|
-
|
1529
|
-
### ✅ Completed
|
1530
|
-
- Core node system with 66+ node types
|
1531
|
-
- Workflow builder with DAG validation
|
1532
|
-
- Local & async execution engines
|
1533
|
-
- Task tracking with metrics
|
1534
|
-
- Multiple storage backends
|
1535
|
-
- Export functionality (YAML/JSON)
|
1536
|
-
- CLI interface
|
1537
|
-
- Immutable state management
|
1538
|
-
- API integration with rate limiting
|
1539
|
-
- OAuth 2.0 authentication
|
1540
|
-
- Production security framework
|
1541
|
-
- Path traversal prevention
|
1542
|
-
- Code execution sandboxing
|
1543
|
-
- Comprehensive security testing
|
1544
|
-
- SharePoint Graph API integration
|
1545
|
-
- **Self-organizing agent pools with 13 specialized nodes**
|
1546
|
-
- **Agent-to-agent communication and shared memory**
|
1547
|
-
- **Intelligent caching and convergence detection**
|
1548
|
-
- **MCP integration for external tool access**
|
1549
|
-
- **Multi-strategy team formation algorithms**
|
1550
|
-
- **Real-time performance metrics collection**
|
1551
|
-
- **Performance visualization dashboards**
|
1552
|
-
- **Real-time monitoring dashboard with WebSocket streaming**
|
1553
|
-
- **Comprehensive performance reports (HTML, Markdown, JSON)**
|
1554
|
-
- **100% test coverage (591 tests)**
|
1555
|
-
- **All test categories passing**
|
1556
|
-
- 68 working examples
|
1557
|
-
|
1558
|
-
</td>
|
1559
|
-
<td width="30%">
|
1560
|
-
|
1561
|
-
### 🚧 In Progress
|
1562
|
-
- **Kailash Workflow Studio** - Visual workflow builder UI
|
1563
|
-
- React-based drag-and-drop interface
|
1564
|
-
- Multi-tenant architecture with Docker
|
1565
|
-
- WorkflowStudioAPI backend
|
1566
|
-
- Real-time execution monitoring
|
1567
|
-
- Performance optimizations
|
1568
|
-
- Docker runtime finalization
|
1569
|
-
|
1570
|
-
</td>
|
1571
|
-
<td width="30%">
|
1572
|
-
|
1573
|
-
### 📋 Planned
|
1574
|
-
- Cloud deployment templates
|
1575
|
-
- Visual workflow editor
|
1576
|
-
- Plugin system
|
1577
|
-
- Additional integrations
|
1578
|
-
|
1579
|
-
</td>
|
1580
|
-
</tr>
|
1581
|
-
</table>
|
1582
|
-
|
1583
|
-
### 🎯 Test Suite Status
|
1584
|
-
- **Total Tests**: 591 passing (100%)
|
1585
|
-
- **Test Categories**: All passing
|
1586
|
-
- **Integration Tests**: All passing
|
1587
|
-
- **Security Tests**: 10 consolidated comprehensive tests
|
1588
|
-
- **Examples**: 68/68 working
|
1589
|
-
- **Code Coverage**: 100%
|
1590
|
-
|
1591
|
-
## ⚠️ Known Issues
|
1592
|
-
|
1593
|
-
1. **DateTime Comparison in `list_runs()`**: The `TaskManager.list_runs()` method may encounter timezone comparison errors between timezone-aware and timezone-naive datetime objects. Workaround: Use try-catch blocks when calling `list_runs()` or access run details directly via `get_run(run_id)`.
|
1594
|
-
|
1595
|
-
2. **Performance Tracking**: To enable performance metrics collection, you must pass the `task_manager` parameter to the `runtime.execute()` method: `runtime.execute(workflow, task_manager=task_manager)`.
|
1596
|
-
|
1597
|
-
## 📄 License
|
1598
|
-
|
1599
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
1600
|
-
|
1601
|
-
## 🙏 Acknowledgments
|
1602
|
-
|
1603
|
-
- The Integrum team for the Kailash architecture
|
1604
|
-
- All contributors who have helped shape this SDK
|
1605
|
-
- The Python community for excellent tools and libraries
|
1606
|
-
|
1607
|
-
## 📞 Support
|
1608
|
-
|
1609
|
-
- 📋 [GitHub Issues](https://github.com/integrum/kailash-python-sdk/issues)
|
1610
|
-
- 📧 Email: support@integrum.com
|
1611
|
-
- 💬 Slack: [Join our community](https://integrum.slack.com/kailash-sdk)
|
1612
|
-
|
1613
|
-
---
|
1614
|
-
|
1615
|
-
<p align="center">
|
1616
|
-
Made with ❤️ by the Integrum Team
|
1617
|
-
</p>
|