AbstractIntegratedModule 0.1.5__tar.gz → 0.1.6__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.
@@ -1,1010 +1,1043 @@
1
- Metadata-Version: 2.4
2
- Name: AbstractIntegratedModule
3
- Version: 0.1.5
4
- Summary: Advanced Integrated AI Module - Multi-agent P2P inference
5
- Author: Micro-Novelty
6
- Author-email: hernikpuspita5@gmail.com
7
- License: MIT
8
- Classifier: Programming Language :: Python :: 3.9
9
- Classifier: Programming Language :: Python :: 3.10
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: Programming Language :: Python :: 3.12
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.9
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE.txt
17
- License-File: LICENSE.txt:Zone.Identifier
18
- Requires-Dist: numpy>=1.21.0
19
- Requires-Dist: scikit-learn>=1.0.0
20
- Requires-Dist: pandas>=1.3.0
21
- Requires-Dist: joblib>=1.1.0
22
- Requires-Dist: cryptography>=41.0.0
23
- Requires-Dist: aiohttp>=3.8.0
24
- Requires-Dist: psutil>=5.9.0
25
- Dynamic: author
26
- Dynamic: author-email
27
- Dynamic: classifier
28
- Dynamic: description
29
- Dynamic: description-content-type
30
- Dynamic: license
31
- Dynamic: license-file
32
- Dynamic: requires-dist
33
- Dynamic: requires-python
34
- Dynamic: summary
35
-
36
- # [=] IntegratedPipeline-Specialized-AI-Agent-library
37
-
38
- [~] IntegratedPipeline is a standalone Specialized AI Agent Library for Non-LLL memory Augmented Agentic Framework orchestrator, Specifically designed to provide Agentic capability for any Autonomous Agentic Framework locally and Coordinatively that runs efficiently from consumer based machine to High-end embedded systems, where the AI Can directly and continously learn, with minimal and efficient compute, built-in augmented memory, Secure Peer-To-Peer (Multi-Agent) Coordination with security layers as an option, And Explainability capability based on proof from in it's internal metrics, reducing Black-Box condition necessary for reliability. Containing specialized MLP using Its Own specialized geometric Weight shaping (AWE) and Specialized efficient Transformer for Scarce Data with Alpha-based computation, specifically designed for low-amount samples environment, or Messy environments.
39
-
40
- <img width="1600" height="600" alt="WhatsApp Image 2026-05-10 at 18 17 37" src="https://github.com/user-attachments/assets/aaf10427-7ff6-4f54-837d-58d46049de78" />
41
-
42
-
43
- ## [+] MANN Intro
44
- [=] Memory augmented Neural network (MANN) is a neural network architecture coupled with an external, dynamic memory module, allowing it to store, retrieve, and update information similarly to a computer's RAM. Unlike traditional networks that store knowledge only in weight parameters, MANNs excel at fast learning, long-term dependency handling, and episodic recall, In IntegratedPipeline, Its memory is stored in a custom database inside your local machine, then later used for memory retrieval, transfered to the AI Dictionary where it can finnaly recall its memory when input condition matched with memory.
45
-
46
- ## [+] Abstract Weight Encoder (AWE) Intro
47
- [=] AWE is a specialized custom weight shaping method that used eigenvalue and spectral methods to calculate covariance inside a given input data, and shape the correct Weight from the given eigenvalue, AWE Works by processing input and then captures the necessary eigenvalue to shape a properly initialized Weight that aligns with input data complexity, So, MLP training will be much more consistent and robust against noise.
48
-
49
- [~] For a much In-Depth Explanation You can visit This repository to learn more about AWE and its performance results:
50
- - Link: https://github.com/Micro-Novelty/Specialized-MLP-for-noise-robustness
51
-
52
- ## [+] Why IntegratedPipeline?
53
- [~] IntegratedPipeline is a great choice for a sophisticated Non-LLM AI Program for The Main Orchestrator of a Distributed MANN-Type AI Agent Working in Edge-device/Consumer-Based machine Where LLM is'nt a great fit for Messy, Noisy environments. while still run efficiently on High-end Embedded systems in single-instance or as a distributed network during multi Agent cooperation.
54
-
55
- [=] IntegratedPipeline offers:
56
- 1. Local-Based AI Orchestrator:
57
- - IntegratedPipeline Creates its own SQLite Database inside Your Computer once the library is executed, This database is used directly to store the AI Memory, Attention weights, predicted Output, and identified peer, all without leaving the machine, The Database will be created Automatically once you run the library, database name saved as activity_log.db.
58
-
59
- 2. Continously Learning behavior for an Agent:
60
- - different from LLM that is static and cannot improve beyond its given training condition, AI Agent using IntegratedPipeline has a dynamic, flexible continously learning behavior with conditional training algorithms included in the library that has both supervised and unsupervised learning present, The learned input and predicted Output will be stored in the database, allowing it to recall its memory during processing and find matching known prediction given if input matched with the stored input inside the database. this Continous learning behavior is efficient because its not relying on weights for memory, allowing flexible and predictable behavior inside a given environment.
61
-
62
- 3. Robust Specialized MLP and Transformer Architecture with ensemble weighting:
63
- - IntegratedPipeline has 2 Different type's of AI Architecture stacked together, and one architecture to weight their confidence and probability fairly to get the final prediction, Specialized MLP for Noise robustness And Specialized Transformer that used Alpha-based Computing algorithm for contextual reasoning, The reason why those Models complement and used together :
64
- - Specialized MLP Provides synchronous robust classification Against noise with its specialized Weight Encoder (AWE) to handle noise using eigenvalue based computing that is lightweight and efficient. This Method can't be replicated Inside Transformer FFN (Feed-forward-network) because of Transformer dynamic brute force computing where AWE-Based generated weight's get diluted over time by Transformer dynamic projection embedding, making AWE Generated weight causes inefficient inside Transformer dynamic FFN/QKV projection.
65
- - Specialized Transformer provides robust synchronous advanced contextual relationships, efficient data processing using Alpha based computing, The Transformer is tuned towards to be as flexible as possible to provide dynamic projection or fixed FFN projection training with minimal head's and dimension's to reduce computational power.
66
- - Ensemble weighting provides the model a much more robust classification best from both worlds perspective, weighting both MLP and Transformer confidence and probability, combined with Attention quality from the transformer to get the final prediction of an input if transformer is allowed and permitted to be in use.
67
-
68
- 4. flexible and secure Peer-to-Peer Coordination (Multi-Agent):
69
- - IntegratedPipeline offers Peer to Peer communication capabilities asynchronously, Where IntegratedPipeline directly checks for other Peer presence directly to the local database present in the local computer or system (Synchronous prediction from peer previous data in the database), or externally, by using asynchronous request for initiating prediction, P2P is secured Using:
70
- - secure socket using user provided SSL CERT. on both client and server,
71
- - API key for requesting,
72
- - Alpha rate limiting,
73
- - HMAC secret key for authentication,
74
- - and IP validation.
75
- [~] Each agent has double roles during P2P:
76
- - Server provider: the peer Agent can start a server to listen for peer client's
77
- - Connecting Agent: the peer Agent which happens to connect to other peer that has or have opened and provided a server listener to act as a receiver.
78
-
79
- 5. Cross-Session memory availability:
80
- - IntegratedPipeline offers share-able Memory capability, included capability below:
81
- - Exportable memory: this allows a flexible memory saving for later use, such as cross transfer memory between model, the memory is saved as .json file after exporting.
82
- - Importable Memory: allowing to import memory from the exported .json file directly for the model to use.
83
- - syncing with other model: socket-based communication to export memory to other external machine.
84
- - [=] Note: socket Syncing is unsecure witout additional security layer wrapped, For a safer syncing, directly transfer the .json file memory to the target machine via other ways such as manual send.
85
- - list sessions: listing available sessions using model's memory name.
86
-
87
- [=] With its Specialized Multi-Layer-Perceptron (using AWE Encoder) and Optimized Transformer module with optimized Embedding, IntegratedPipeline can directly tolerate low samples-amount of Data, including noisy ambiguous data, using Weighted Confidence assembling from both specialized MLP and Transformer for better reliability during training and prediction over Messy, noisy environments, such as:
88
-
89
- [1.] User data's : User data is often messy and ambiguous, Specialized MLP with AWE will do the job for shaping the necessary Weight to complement for the Ambiguous noisy pattern, AWE MLP is highly robust to noise, proven in synthetic Environment such as scikit-learn Make-Classification scarce and Noisy Input robustness during generalization test. making it a great fit for messy, Scarce data.
90
-
91
- [2.] Small Dataset's : We often don't have enough Dataset to train a Transformer Model, Thats Why IntegratedPipeline Offers a Highly optimized Transformer that supports scarce dataset processing, Using Alpha-Based computing as a Warm-up for training, it provides a direct Boost for the transformer to be efficient during training in scarce-data Environment.
92
-
93
- [3.] Non-Representative data (Undersampled) : IntegratedPipeline Support's ambiguous data that come's from file with format such as CSV Format to extract title's and label's necessary to create automatic Dataset for Later use in Training, making it optimized for specific task's and easier dataset creation with lower overfitting rate for reliability.
94
-
95
- [=] Architectural-Overview
96
- <img width="1600" height="860" alt="WhatsApp Image 2026-05-09 at 16 13 41" src="https://github.com/user-attachments/assets/580722aa-bbd8-4148-a425-4bff01c06c47" />
97
- [=] Contextual meaning:
98
- 1. - Sequence encoding is a machine learning technique that transforms a sequential input (like text, time-series data, or audio) into a compact, fixed-length numerical vector, often called a context vector
99
- 2. - TF-IDF (Term Frequency-Inverse Document Frequency) is a numerical statistic used in machine learning and NLP to evaluate how important a word is to a document within a collection (corpus). It boosts rare words and penalizes common words (like "the", "and") by multiplying two metrics: how often a word appears in a document (TF) and the inverse frequency of the word across all documents (IDF).
100
- 3. - Explainability provides deeper transparency of why a model thought about a detail by showing its internal metrics like attention quality, from distributed peer memory or Ensemble prediction result's.
101
-
102
-
103
-
104
- ## [=] Requirements
105
- [~] To run and execute IntegratedPipeline, Requirement's include (Or see [Requirements](requirements.txt):
106
- - Machine (Choose one minimal, specified for your needs):
107
- - Windows Native OS - AbstractIntegratedModule.cp313-win_amd64 Supports Python 3.13 for Windows Only (Robust, Stable version)
108
- - Linux x86_64 - AbstractIntegratedModule.cpython-312-x86_64-linux-gnu.so supports Python 3.12 only.
109
- - Linux ARM64 - Raspberry Pi (Supports Raspberry pi 3 - 5) - AbstractIntegratedModule.cpython-310-aarch64-linux-gnu.so supports Python 3.10 only.
110
- - Libraries:
111
- - Pandas
112
- - aiohttp
113
- - scikit-learn
114
- - numpy
115
- - psutil
116
-
117
- - Download AbstractIntegratedModule from release section or in here, [AbstractIntegratedModule Package](AbstractIntegratedModule-Package.zip)
118
- - This file contains:
119
- - AbstractIntegratedModule.pyd (For windows machine).
120
- - AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so (For linux x86_64).
121
- - AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so (for Linux ARM64 - Raspberry Pi).
122
-
123
- [=] for labels assignation:
124
- - CSV file that contains training labels and titles used for training and prediction label map, example will be provided below, [Go to Step's for in-depth Usage](#Step's-for-in-depth-Usage)
125
-
126
- ### [=] Requirements for Docker container
127
- - Dockerfile (For Container assembler)
128
- - Python scripts (Such as main.py for Dockerfile usage).
129
- - entrypoint.sh (for smart entry point for Dockerfile container usage).
130
-
131
- ## [=] System-Specific Notes
132
- 1. Windows:
133
- - Requires Visual C++ Build Tools for compatibility
134
- - Use PowerShell or CMD (not WSL bash for best results)
135
-
136
- 2. Linux:
137
- - Ensure gcc and build-essential are installed
138
- - Different distributions may require different package managers
139
-
140
- 3. ARM64 - Raspberry Pi
141
- - Installation may take 30+ minutes due to ARM architecture
142
- - Monitor system resources during installation
143
- - Consider using faster storage (USB SSD) for better performance
144
-
145
- ## [=] Docker Container Application
146
- 0. See [Docker_installation_Section](Docker_installation_Section.md) for an in-depth explanation, or [Quick_Docker_start](Quick_Docker_start.sh) for a quick start.
147
- - Note Consider checking:
148
- - [Dockerfile](Dockerfile) contains all the instructions need to assemble a Docker container.
149
- - [start.sh](start.sh) for Quick single agent start in Docker container.
150
- - [entrypoint.sh](entrypoint.sh) for a Smart entrypoint used in Dockerfile (Must be downloaded too along with Dockerfile and put in the same folder with Dockerfile after its downloaded)
151
- - [start-multi-agent-cluster.sh](start-multi-agent-cluster.sh) for Multi-agent cluster start in Docker container, What it does:
152
- - Starts a multi-agent Docker cluster — runs docker-compose up -d in detached mode (background), scaling the agent-client service to 5 simultaneous instances, alongside whatever server is defined in the docker-compose.yml.
153
- - Tails the logs — runs docker-compose logs -f which streams live logs from all containers (server + all 5 clients) to your terminal until you hit Ctrl+C.
154
- - [main.py](main.py) for executing a python script in the Docker container that used main.py, like in this code:
155
- - ```bash
156
- docker run -it -v $(pwd):/app/data integrated-pipeline:latest python /app/data/main.py
157
- ```
158
- - To use a [.dockerignore](.dockerignore) file, place it in your build context directory (the same location as your Dockerfile) to specify which files and folders should be excluded when building your image.
159
- - [.env](.env) is used for environment setup in [entrypoint.sh](entrypoint.sh), this file must be in the same folder with Dockerfile and entrypoint.sh after its downloaded.
160
-
161
- 1. Build Image:
162
- - Clone repository:
163
- - ```bash
164
- git clone https://github.com/Micro-Novelty/IntegratedPipeline-Continous-Learning-AI-Agent-library-framework.git
165
- cd IntegratedPipeline-Continous-Learning-AI-Agent-library-framework
166
- ```
167
- - Download:
168
- - [Dockerfile](Dockerfile),
169
- - [entrypoint.sh](entrypoint.sh)
170
- - [.env](.env)
171
- - In the code or release section.
172
-
173
- - If the downloaded Dockerfile or .dockerignore or .env has .txt extension, remove the extension:
174
- - ```bash
175
- # remove .txt extension
176
- mv Dockerfile.txt Dockerfile
177
- mv env.txt .env
178
- mv dockerignore.txt .dockerignore
179
- ```
180
- - Navigate to the folder: Use the cd command to enter the directory containing the Dockerfile and entrypoint.sh file.
181
- - ```
182
- cd /path/to/your/folder
183
- ```
184
- - build image:
185
- - ```bash
186
- sudo docker build -t integrated-agent.
187
- ```
188
- 2. Download library dependencies:
189
- [=] Required libraries:
190
- - Numpy
191
- - Scikit-learn
192
- - pandas
193
-
194
- 4. Run IntegratedPipeline in a Container:
195
- - ```bash
196
- docker run -it --name ai-agent integrated-agent:latest python
197
- ```
198
- - In python shell:
199
- - ```
200
- from AbstractIntegratedModule import IntegratedPipeline, PipelinePredictionManager
201
- model = IntegratedPipeline('agent_memory')
202
- print("✓ IntegratedPipeline initialized successfully!")
203
- ```
204
-
205
- 5. Run script:
206
- ```bash
207
- # Mount your local directory and run a script
208
- docker run -it -v $(pwd)/data:/app/data integrated-agent:latest python main.py # main.py could be replaced
209
- ```
210
-
211
- 6. Run with GPU Support (Optional):
212
- - ```bash
213
- # For NVIDIA GPU support
214
- docker run -it --gpus all -v $(pwd)/data:/app/data integrated-agent:latest python main.py
215
- ```
216
-
217
- 7. For Single Agent and Multi-Agent P2P:
218
-
219
- [=] Single agent:
220
- ```bash
221
- # Build image
222
- docker build -t integrated-agent:latest .
223
-
224
- # Run single agent
225
- docker run -it -v $(pwd)/data:/app/data integrated-agent:latest python
226
- ```
227
-
228
- [=] Multi agent P2P (Consider docker-compose) :
229
- - Note: Use the provided [docker-compose.yml](docker-compose.yml) for Quick multi-agent.
230
- - Navigate to the folder: Use the cd command to enter the directory containing the docker-compose.yml file.
231
- - ```
232
- cd /path/to/your/folder
233
- ```
234
- - run this command to run docker-compose.yml:
235
- - ```bash
236
- # Start multiple agents
237
- docker-compose up -d
238
-
239
- # View logs
240
- docker-compose logs -f
241
-
242
- # Stop all agents
243
- docker-compose down
244
- ```
245
-
246
- ## Performance in ARM64 Docker Environment/Container
247
- A. [=] Computational performance results with Transformer included during Advanced prediction method.
248
- ```txt
249
- == TIME == | CPU % | RAM / RAM LIMIT ||
250
-
251
- 14:50:08.762 0.00% 25.52MiB / 3.71GiB
252
- 14:50:10.339 5.56% 25.52MiB / 3.71GiB
253
- 14:50:12.428 0.17% 25.52MiB / 3.71GiB
254
- 14:50:15.835 103.60% 38.8MiB / 3.71GiB
255
- 14:50:17.844 438.11% 60.15MiB / 3.71GiB
256
- 14:50:19.896 419.36% 68.32MiB / 3.71GiB
257
- 14:50:22.022 434.15% 73.2MiB / 3.71GiB
258
- 14:50:23.969 436.47% 78.18MiB / 3.71GiB
259
- 14:50:25.966 435.85% 80.22MiB / 3.71GiB
260
- 14:50:28.018 430.47% 92.12MiB / 3.71GiB
261
- 14:50:30.029 450.55% 99.5MiB / 3.71GiB
262
- 14:50:32.065 438.06% 105.4MiB / 3.71GiB
263
- 14:50:34.100 469.52% 115.2MiB / 3.71GiB
264
- 14:50:36.109 449.89% 116.8MiB / 3.71GiB
265
- 14:50:38.123 423.56% 119MiB / 3.71GiB
266
- ```
267
- - [=] Note: To read the full logs (For included Transformer performance): [performance_log_with_TF](performance_log_with_TF.txt)
268
- - [=] Explanation:
269
- - Average CPU Usage = 420% - 430% , Sustained roughlt 4.20 - 4.30 CPU Cores
270
- - Meaning = - Compute-Intensive workload
271
- - reduced guaranteed of experiencing deadlocks, thread starvation, and major stalls
272
- - numerical backend is parallelizing efficiently
273
- - Average RAM Usage = 180 - 195 Mib, Roughly 4.5 - 5% usage of available RAM
274
- - Meaning = - Very efficient RAM Usage
275
- - Repeated 269 MiB suggests allocator settled, ndarray pools stabilized, workload reached steady state
276
- - gradual, safe and steady batch accumulation, reduced possibility of leak explosion.
277
-
278
- B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
279
- ```txt
280
- == TIME == | CPU % | RAM \ RAM LIMIT |
281
- 10:01:37.456 100.44% 269.8MiB / 3.71GiB # initial round 1 training started
282
- 10:01:38.686 101.93% 279.8MiB / 3.71GiB
283
- 10:01:40.694 101.94% 293.2MiB / 3.71GiB
284
- 10:01:42.703 99.90% 302.9MiB / 3.71GiB
285
- 10:01:44.712 99.34% 319.8MiB / 3.71GiB
286
- 10:01:46.721 100.15% 319.7MiB / 3.71GiB
287
- 10:01:48.727 101.91% 319.7MiB / 3.71GiB
288
- 10:01:50.734 100.86% 319.7MiB / 3.71GiB
289
- 10:01:52.742 136.43% 322.9MiB / 3.71GiB
290
- 10:01:54.751 101.91% 324.9MiB / 3.71GiB
291
- 10:01:56.758 100.29% 324.9MiB / 3.71GiB
292
- 10:01:58.769 102.42% 327.1MiB / 3.71GiB
293
- 10:02:00.775 0.00% 329.6MiB / 3.71GiB # First Training and prediction round 1 finished
294
- 10:02:02.788 19.55% 330.1MiB / 3.71GiB # round 2 training
295
- 10:02:04.798 134.23% 332.2MiB / 3.71GiB
296
- 10:02:06.803 108.80% 332.2MiB / 3.71GiB
297
- 10:02:08.811 107.85% 332.2MiB / 3.71GiB
298
- 10:02:10.857 104.43% 332.2MiB / 3.71GiB
299
- 10:02:12.854 101.14% 332.2MiB / 3.71GiB
300
- 10:02:14.858 0.00% 332.3MiB / 3.71GiB
301
- 10:02:16.873 98.84% 333.8MiB / 3.71GiB
302
- 10:02:18.869 0.00% 132.7MiB / 3.71GiB # container stopped and round 2 finished
303
- ```
304
- - [=] Note: See full performance log in here: [performance_log_only_MLP](performance_log_only_MLP.txt)
305
- - [=] Explanation:
306
- - Average CPU Usage = 85-90% Used, sustained roughly 1 CPU Core saturated on average
307
- - Meaning: - Very efficient computation
308
- - Much lighter CPU Usage than Transformer.
309
- - Stable and less parallelizing behavior (Efficient computation)
310
- - 4.7x lower CPU usage than transformer included
311
- - Average RAM usage = 314 MiB / 3.71 GiB, Roughly 8.5% usage of available RAM.
312
- - Meaning: - Slightly larger MiB used than Transformer.
313
- - Model allocation growth is stable,
314
- - training buffers stable
315
- - temporary ndarray growth.
316
-
317
- ### Both performance Overview
318
- <img width="1536" height="1024" alt="WhatsApp Image 2026-05-24 at 10 27 00" src="https://github.com/user-attachments/assets/9404277f-281f-4893-8367-e494833230ea" />
319
-
320
- ## Source code of AbstractIntegratedModule
321
- - [=] Full Monolithic extensively-documented source code (12K+ Lines): [AbstractIntegratedPipeline-SourceCode.zip](AbstractIntegratedPipeline-SourceCode.zip)
322
- - [=] Separated Modules of AbstractIntegratedModule: [AbstractIntegratedModule-separated-modules](AbstractIntegratedModule-separated-modules)
323
- - [~] Note:
324
- - The source code is open and Free to anyone who:
325
- - Use it: Run the software for any personal, academic, or commercial purpose.
326
- - Modify it: Change the source code to fit their needs.
327
- - Distribute it: Share the original or modified code with others.
328
- - Commercialize it: Package, brand, and sell the software for profit.
329
-
330
- ## [=] Step's for in-depth Usage
331
- 1. Download:
332
- - AbstractIntegratedModule.pyd (For Windows) (Python 3.13),
333
- - AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so (For linux x86_64) (Python 3.12)
334
- - AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so (for Linux ARM64 - Raspberry Pi) (Python 3.10)
335
- - ```
336
- # Download from release
337
- # AbstractIntegratedModule.pyd (windows) /
338
- # Abstractcpython-39-x86_64-linux-gnu.so (x86_64) /
339
- # AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so
340
- ```
341
-
342
- [=] Steps for installation:
343
- Note: AbstractIntegratedModule has 3 library dependencies that must be installed on your computer:
344
- - [=] Required Libraries:
345
- - Numpy
346
- - Scikit-learn
347
- - pandas
348
- - aiohttp
349
- - psutil
350
-
351
- 1. Clone repository:
352
- - ```
353
- # prerequisites (for Raspberry pi OS Only)
354
- # Update system
355
- sudo apt-get update
356
- sudo apt-get upgrade -y
357
-
358
- # Install Python 3.13 and development tools
359
- sudo apt-get install python3.13 python3.13-dev python3.13-venv -y
360
-
361
- # Install additional build tools
362
- sudo apt-get install build-essential libatlas-base-dev libjasper-dev -y
363
-
364
- # Clone immediately for Windows and x86_64 only without prerequisites
365
- git clone https://github.com/Micro-Novelty/IntegratedPipeline-Continous-Learning-AI-Agent-library-framework.git
366
- cd IntegratedPipeline-Continous-Learning-AI-Agent-library-framework
367
- ```
368
- 2. Install System Dependencies (for x86_64 installation):
369
- ```
370
- # Ubuntu/Debian
371
- sudo apt-get update
372
- sudo apt-get install python3.13 python3.13-dev python3.13-venv
373
-
374
- # CentOS/RHEL
375
- sudo yum install python313 python313-devel
376
-
377
- # Fedora
378
- sudo dnf install python3.13 python3.13-devel
379
- ```
380
-
381
- 3. Create a virtual environment:
382
- - ```
383
- # Create virtual environment (windows)
384
- python -m venv venv
385
- # Activate virtual environment
386
- venv\Scripts\activate
387
-
388
- # Create virtual environment (x86_64) (ARM64 / raspberry pi)
389
- python3.13 -m venv venv
390
- # Activate virtual environment
391
- source venv/bin/activate
392
- ```
393
-
394
- 4. Copy AbstractIntegratedModule binary:
395
- - ```
396
- # For windows:
397
- # Copy the .pyd file to your project root
398
- # AbstractIntegratedModule.pyd
399
- copy C:\path\to\AbstractIntegratedModule.pyd .\AbstractIntegratedModule.pyd
400
-
401
- # Copy the .so file to your project root (for x86_64)
402
- cp /path/to/AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so ./AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so
403
-
404
- # Copy ARM64 / Raspberry pi binary
405
- cp /path/to/AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so ./AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so
406
-
407
- 5. Verify Installation:
408
- - ```
409
- python -c "from AbstractIntegratedModule import IntegratedPipeline; print('✓ Installation successful!')"
410
- ```
411
-
412
- 6. Run main.py for quick test of successful imports:
413
- - ```
414
- # run this for quick import test.
415
- python main.py
416
- ```
417
-
418
-
419
-
420
- 3. Create CSV file that contains training labels and titles:
421
- - Example format:
422
- ```txt
423
- window_title,label
424
- "Thesis.docx",focused_work,high,writing-thesis
425
- "Microsoft Excel",work,medium,data-analysis
426
- "YouTube -> Google Chrome",distracted,high,watching-videos
427
- "Slack",communication,high,team-chat
428
- "VSCode", focused_work,high,coding
429
- "netflix.com -> Google Chrome",break,high,Netflix-break
430
- "Outlook",work,medium,checking-email
431
- "System Settings",system designing,low,configuring-computer
432
- "GitHub",creating-and-editing-repo,research
433
- "README.md -> VS Code",focused_work,medium,reading-docs
434
- "Amazon.com -> Chrome",personal-work,high,shopping
435
- ```
436
- Note = window_title is target_title and label is target_label, check step below to use it.
437
-
438
- 4. Use IntegratedPipeline as in this example:
439
- ```python
440
- from AbstractIntegratedModule import IntegratedPipeline
441
- from AbstractIntegratedModule import PipelinePredictionManager
442
- import numpy as np
443
-
444
- memory_name = 'agent_memory'
445
- main_model = IntegratedPipeline(memory_name, use_async=True, ssl_cert_file=cert_file, ssl_key_file=key_file) # provide cert_file path or key_file path (optional)
446
- main_prediction = PipelinePredictionManager(main_model, label_csv='example_manual_training.txt', target_title='window_title', label='label')
447
- # example_manual_training is a .txt file that contain csv format like above example.
448
-
449
-
450
- example_rules = [
451
- # === WORK / PRODUCTIVITY ===
452
- (r'code|programming|develop|debug|compile|script', 'focused_work'),
453
- (r'vscode|visual_studio|ide|terminal|shell', 'focused_work'),
454
- (r'notion|evernote|onenote|notes|todo|task', 'productive'),
455
- (r'slack|teams|discord|zoom|meeting|call', 'communication'),
456
- (r'email|gmail|outlook|inbox|mail', 'communication'),
457
-
458
- # === ENTERTAINMENT ===
459
- (r'youtube|netflix|twitch|stream|video', 'entertainment'),
460
- (r'music|spotify|soundcloud|audio|player', 'entertainment'),
461
- (r'game|gaming|steam|epic|play', 'gaming'),
462
- (r'facebook|instagram|tiktok|social|post', 'social_media'),
463
-
464
- # === BROWSING ===
465
- (r'chrome|firefox|edge|safari|browser', 'browsing'),
466
- (r'google|search|wiki|wiki|article', 'information'),
467
- (r'stackoverflow|github|docs|documentation', 'research'),
468
-
469
- # more rules
470
- ]
471
- # activate explainability capability to explain uncertainty:
472
- main_model.show_explainability_details = True
473
- main_model.distribution.predict_manager = main_prediction # set PipelinePredictionManager to AgentDistributedInference for asynchronous prediction later (Very important for asynchronous prediction)
474
- # main_model.use_transformer = True if you want to use transformer, this will notify all modules that used advanced_prediction_method will initiate prediction with both transformer and MLP.
475
-
476
-
477
- # test samples with more sophisticated rules and more complex titles for prediction
478
- # (title, intent)
479
- test_titles = [
480
- ("Opening Thesis.docx", "slight_work"),
481
- ("Watching YouTube and Google Chrome", "distracted"),
482
- ("Watching Slack", "communication"),
483
- ("Programming in Visual Studio Code", "focused_work"),
484
- ("Watching netflix.com - Chrome", "break"),
485
- # more titles
486
- ]
487
-
488
- titles, y, label_map = main_prediction.load_labels_from_csv(<your_filename>, <target_title>, <target_label>)
489
- # small training with simple titles
490
- main_model.train(titles, y)
491
-
492
- results, chosen_label, confidence = main_prediction.advanced_prediction_method(test_titles, label_map, example_rules,
493
- show_proba=False, top_k=3,
494
- use_transformer=True,
495
- return_attention=False,
496
- save_results=True)
497
-
498
- # ... more features you can add
499
- ```
500
-
501
- 5. To use IntegratedPipeline prediction without Transformer, Only Specialized MLP:
502
- Note: IntegratedPipeline without Transformer is'nt recommended due to it being weak at certain contextual prediction's, excel's at classification task's.
503
- - Example without transformer:
504
- ```python
505
- prediction_result = main_prediction.advanced_prediction_method(
506
- [t[0] for t in test_titles], # titles is enough for MLP Classification.
507
- label_map,
508
- example_rules,
509
- show_proba=True
510
- )
511
-
512
- ```
513
- 6. Asynchronous prediction:
514
- - Asynchronous prediction request is important and is critical because it keeps prediction interfaces responsive, maximizes local hardware efficiency, and enables apps to handle background tasks seamlessly without waiting on remote server responses,
515
- - for asynchronous prediction handling, consider using this setup
516
- ```python
517
- # Step 2
518
- from AbstractIntegratedModule import PipelineAsyncManager
519
- from AbstractIntegratedModule import SecurityConfig
520
- from AbstractIntegratedModule import SecurityLevel
521
-
522
- print(" = TESTING ASYNCHRONOUS PREDICTION MANAGER = ")
523
- # Set discovery secret (in production, use environment variable)
524
- secret_key = 'my-ultra-safe-secret-key-for-authentication' # you can customize this key
525
-
526
-
527
- security_config = SecurityConfig(
528
- max_text_length=10000, # can be extended
529
- max_queue_size=100, # can be extended
530
- rate_limit_requests=60, # 60 per minute
531
- require_api_key=True, #
532
- max_pending_tasks=50,
533
- request_timeout=60.0,
534
-
535
- # Start with no IP restrictions, you can add allowed IPs for asynchronous prediction externally, boothstrap_auth for better security
536
- allowed_ips=[],
537
- blocklisted_ips=[],
538
- require_bootstrap_auth = False # true for better security (Not recommended, cause less flexibility)
539
- )
540
-
541
- async_manager = PipelineAsyncManager(main_model,
542
- main_prediction, # your previous initialized PipelinePredictionManager
543
- config=security_config,
544
- state_file=None, # state file is used to load known security logs ex: ip used, ip blacklisted, etc.
545
- security_level=SecurityLevel.PRODUCTION, # production level security initiated
546
- api_key=secret_key #set secret key you initialized
547
- max_workers=4, # workers to initiate prediction, more workers, more capabilities to process prediction requests.
548
- task_timeout=30,
549
- max_retries=3 ) # retries after failure during prediction
550
-
551
- async_manager.start(method='Transformer_included', bootstrap_token=None) # boothstrap token is optional for better security
552
-
553
- texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'use_transformer': True}
554
- regular_predict = async_manager.predict(
555
- texts=texts,
556
- timeout=60,
557
- retries=None,
558
- api_key=secret_key) # advanced prediction method for asynchronous prediction.
559
-
560
- # with retries: async_manager.predict(texts, timeout=60, retries=5, api_key=secret_key) # 5 times retry if failed
561
-
562
- print('[==] Initiating advanced batch prediction')
563
- predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules, secret_key, client_ip=None) # you can add client_ip to provide a robust authentication paired with secret_key
564
- # for better and faster advanced prediction, consider using advanced batch prediction like in the above example
565
-
566
- ```
567
- [=] Note:
568
- - Asynchronous prediction used Event loop that handles incoming request, There are conditions where event loop will not start and can't accet requests:
569
- - CPU Above > 95% - Disk space is < 100 MB
570
- - RAM above > 95%
571
- - When event loop is not triggered, Asynchronous prediction can't be initiated and must be restarted/retried.
572
-
573
- 7. Peer-to-Peer Probability coordination:
574
- - Each peer is both server and client simultaneously for robustness and resilience during during P2P.
575
- - To Make the Agent cooperate with other peers, consider using this setup:
576
- - [=] for ensemble prediction from multiple peers, exchanging predicted label with each other, consider using this setup:
577
- ```python
578
- # step 3
579
- from AbstractIntegratedModule import CohesiveAgentDeployment
580
- from AbstractIntegratedModule import PipelinePredictionManager
581
- import asyncio
582
- import traceback
583
-
584
- prediction_manager = PipelinePredictionManager(main_model, label_csv=<your_training_labels.txt>, target_title=<target_title>, label=<target_label>)
585
-
586
- print("=== SECURE PEER-TO-PEER CLUSTER ===")
587
-
588
- # CohesiveAgentDeployment is deeply tied and coupled with AgentDistributedInference,
589
- # if you already set an SSL cert and key, CohesiveAgentDeployment will use the SSL directly from AgentDistributedInference
590
- # allowing secure socket to be used directly by CohesiveAgentDeployment
591
-
592
- # Agent 1 - Primary (Port 5555)
593
- agent1 = CohesiveAgentDeployment(
594
- memory_name="agent_primary",
595
- filename=<filename>,
596
- target_title=<title_name>,
597
- label_name=<label_name>,
598
- security_level="PRODUCTION",
599
- enable_peers=True,
600
- trusted_networks=['127.0.0.1/32', '192.168.1.0/24'], # for trusted networks, you need to provide the list of IPs of your peers.
601
- peer_discovery_port=5555, # peer port to start P2P
602
- secret_key=secret_key,
603
- shared_auth_token=secret_key, # your previous initialized secret_key
604
- predict_manager=prediction_manager,
605
- peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
606
- consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
607
- )
608
-
609
- # Agent 2 - Secondary (Port 5556)
610
- agent2 = CohesiveAgentDeployment(
611
- memory_name="agent_secondary",
612
- filename=<filename>,
613
- target_title=<title_name>,
614
- label_name=<label_name>,
615
- security_level="PRODUCTION",
616
- enable_peers=True, # agent is allowed to find peers
617
- trusted_networks=['127.0.0.1/32', '192.168.1.0/24'],
618
- peer_discovery_port=5556,
619
- secret_key=secret_key,
620
- shared_auth_token=secret_key,
621
- predict_manager=prediction_manager,
622
- peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
623
- consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
624
- )
625
-
626
- # Note: CohesiveAgentDeployment contains ConsecutivePeerAgent that can start a server once ensemble prediction from peer is started
627
- # be advised to stop the server too before shutdown-ing CohesiveAgentDeployment cluster
628
-
629
- # example peer_Ip_lists_config.json (de-comment to use)
630
- # {
631
- # "known_peers": [ # you must put "known_peers" in the config so python can identify the list of IPs and Ports
632
- # ["127.0.0.1", 5555], can be modified using real IP or local IP.
633
- # ["127.0.0.1", 5556]
634
- # ]
635
- # }
636
-
637
- agent1.pipeline = main_model # overrides agent1 baseline pipeline with your original initialized pipelinej
638
- agent2.pipeline = main_model
639
-
640
- try:
641
- # Start both agents
642
- print("\n🚀 Starting Agent 1...")
643
- await agent1.start()
644
- print("✅ Agent 1 started on port 5555")
645
-
646
- print("\n🚀 Starting Agent 2...")
647
- await agent2.start()
648
- print(" Agent 2 started on port 5556")
649
-
650
- # Give servers time to fully bind
651
- await asyncio.sleep(2)
652
-
653
- # Get API keys
654
- api_key = agent1.get_api_key()
655
- print(f"\n🔑 Using API Key: {api_key[:20]}...")
656
-
657
- texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
658
-
659
- # texts contains test_titles, label_map, and rules that you can assign,
660
- # agent ID can be strings, int, or floats, recommendeded to make it long for better security.
661
-
662
- # Make prediction with peer ensemble
663
- # Connection will be guaranteed successfull during discovery.
664
- result = await agent1.multi_modal_peer_ensemble_prediction(
665
- texts=texts,
666
- api_key=api_key,
667
- method='advanced',
668
- disable_sync=True
669
- ) # await using asyncio, multi_modal_peer_ensemble is already async by design (Inside ConsecutivePeerAgent), no need to put asyncio.run()
670
-
671
- result2 = await agent2.multi_modal_peer_ensemble_prediction(
672
- texts=texts,
673
- api_key=api_key,
674
- method='advanced',
675
- disable_sync=True
676
- )
677
-
678
- print(f"\n📊 Ensemble Result for Agent 1:")
679
- print(f" Prediction: {result.get('prediction', 'N/A')}")
680
- print(f" Confidence: {result.get('confidence', 0):.2%}")
681
-
682
- print(f"\n📊 Ensemble Result for Agent 2:")
683
- print(f" Prediction: {result2.get('prediction', 'N/A')}")
684
- print(f" Confidence: {result2.get('confidence', 0):.2%}")
685
-
686
- # Keep running briefly
687
- print("\n⏳ Cluster stable. Waiting 5 seconds before shutdown...") # 5 seconds before shutdown.
688
-
689
- # stop ConsecutivePeerAgent servers inside CohesiveAgentDeployment.
690
- agent1._peer_agent.stop_server() # ._peer_agent is ConsecutivePeerAgent
691
- agent2._peer_agent.stop_server()
692
-
693
- await asyncio.sleep(5)
694
-
695
- except Exception as e:
696
- print(f"\n❌ Error in cluster: {e}")
697
- traceback.print_exc()
698
-
699
- finally:
700
- print("\n🛑 Shutting down cluster...")
701
- await agent1.shutdown()
702
- await agent2.shutdown()
703
- print("✅ Cluster shutdown complete")
704
-
705
- ```
706
- [=] Important Note:
707
- - This setup outputs the given predicted label of an input directly, making P2P more flexible and fast.
708
- - This setup used Hybrid feature in prediction handling, Asynchronous prediction request, and Synchronous prediction handling. Synchronous prediction does block code execution for a few seconds, it was used for a few reason here, such as:
709
- - allowing a more slower traffic between agents, preventing other agent to get the same peer prediction over time, making each interaction equals and each peer can receive different peer prediction output.
710
-
711
- [=] You can download this setup here for a direct test: [P2PDirectTest.py](P2PDirectTest.py)
712
-
713
- - [=] for probability coordination, locally, get peers data from database or via socket.
714
- ```python
715
- # step 4
716
- dataset, _ = main_model.data_preparation(test_titles, label_map)
717
- sequence_inputs = main_model.sequence_encoding(dataset)
718
- X_raw_generation, y, n_classes, input_dim = main_model.mlp_training_features(example_rules, dataset)
719
-
720
- main_model.initialize_fitting(dataset)
721
- X_raw_features = main_model.tfidf.transform(X_raw_generation).toarray()
722
- transformer_features = main_model.transformer_pooled_features(sequence_inputs)
723
- X_features = np.concatenate([X_raw_features, transformer_features], axis=-1)
724
-
725
- peer_probability_calibration = main_model.predict_proba(sequence_inputs, X_features, type='Hybrid', embedded=True) # peer-to-peer calibration is inside this function
726
- ```
727
- [~] Note: the peer calibration coordination has a chance of triggering if both MLP and Transformer prediction doesn't agree on certain output. Consider using this setup below for using stand-alone peer-to-peer main function without being wrapped in other parent function, allowing flexible and auditable peer-to-peer sharing for probability coordination:
728
- ```python
729
- from AbstractIntegratedModule import WeightedEnsemblePredictor
730
- from AbstractIntegratedModule import Transformer
731
-
732
- num_classes = len(label_map)
733
- # if you haven't fit the Tfidf:
734
- # main_model.initialize_fitting(dataset)
735
-
736
- ensemble_method = WeightedEnsemblePredictor(main_model, memory_name) # consider using the same memory name used in your previous pipeline
737
- transformer = Transformer(main_model.vocab_size, d_model=32, n_heads=4, num_classes=num_classes) # you can audit how much parameter the transformer needs.
738
- main_model.model2 = transformer # overwrite previous transformer initialization
739
-
740
- # main_model.distribution is AgentDistributedInference() class
741
- # consider using ssl for secure peer to peer coordination
742
- main_model.distribution.ssl_cert_file = <path_to_your_ssl_cert_file>
743
- main_model.distribution.ssl_key_file = <path_to_your_ssl_key_file>
744
-
745
- dataset, _ = main_model.data_preparation(titles, label_map)
746
- sequence_input = main_model.sequence_encoding(dataset)
747
- _, attn_weights = transformer.forward(sequence_input)
748
-
749
- probs = ensemble_method.predict_ensemble(sequence_input, X_features, y, method='dynamic', embedded=True)
750
- # 3 options for ensemble weighting method:
751
- # 1. dynamic: allow flexible, efficient weighting from both transformer and MLP,
752
- # 2. meta: for a much more in-depth weighting from both model,
753
- # 3. calibration: allow calibrating probability for both model outputs based on both best weights assembling.
754
-
755
- agreement = main_model.agreement
756
-
757
- # start server to initiate socket for P2P listener
758
- main_model.distribution.start_server()
759
-
760
- # set connection timeout (Optional)
761
- main_model.distribution.connection_timeout = 30 # 30 seconds before timeout
762
- calibrated_probability = main_model._handle_distributed_connections(probs, attn_weights, sequence_input, agreement)
763
-
764
- # if an Agent experience a failure on tasks, consider using this function to reduce peer trust for safer flexible coordination:
765
- # main_model.distribution.report_failure(id(main_model), '<task_name>', reason='<unknown>') # you can add the task_name and reason
766
- # main_model.distribution.print_network_status() # to show other peers info.
767
- ```
768
- [~] Note: this calibrated_probability is later used to calculate confidence and chosen output based on given label_map.
769
- - Consider checking:
770
- - [multi_agent_client.py](multi_agent_client.py) for a In-depth start for client testing.
771
- - [multi_agent_server.py](multi_agent_server.py) for a In-depth start for server testing.
772
- - If you get undefined NoneType Behavior when using .accept(), consider see [Troubleshooting](#Troubleshooting) Issue 7 for a Quick fix.
773
-
774
- 6. Cross-Session availability:
775
- - To use Cross-session avialability to transfer or import memory, consider using this setup:
776
- - ```python
777
- main_model._cross_session_availability() # cross session capability function
778
- ```
779
-
780
- 7. As an option, You can add more feature's directly to what it should predict, behave using rules you have given, Create a visual dashboard, create a distributed mesh of this agent, and much more features you can try.
781
-
782
- ## [+] Troubleshooting
783
- 1. Issue 1: "ModuleNotFoundError: No module named 'AbstractIntegratedModule'"
784
- Solution:
785
-
786
- - [=] Verify the binary file is in the correct location:
787
- ```
788
- ls -la AbstractIntegratedModule*.so # Linux
789
- dir AbstractIntegratedModule.pyd # Windows
790
- ```
791
-
792
-
793
- - [=] Check Python path:
794
- ```
795
- python -c "import sys; print('\n'.join(sys.path))"
796
- ```
797
- - [~] Note: - Move binary to project root if not already there
798
- - Ensure you're using Python 3.13+
799
-
800
- 2. Issue 2: "ImportError: DLL load failed" (Windows)
801
- Solution:
802
-
803
- - 1. Ensure AbstractIntegratedModule.pyd is in your project root
804
- - 2. Install Visual C++ redistributables:
805
- Download from: https://support.microsoft.com/en-us/help/2977003
806
- - 3. Verify Python architecture (32-bit vs 64-bit) matches the .pyd file
807
-
808
-
809
- 3. Issue 3: "Permission denied" (Linux/Raspberry Pi)
810
- [=] Solution:
811
- - ```
812
- # Make sure you have read permissions
813
- chmod 644 AbstractIntegratedModule.cpython-39-*.so
814
- # If in virtual environment, ensure it's activated
815
- source venv/bin/activate
816
- ```
817
-
818
- 4. Issue 4: Missing Dependencies
819
- [=] Solution:
820
- - ```
821
- # Reinstall all dependencies
822
- pip install --upgrade pip setuptools wheel
823
- pip install numpy pandas scikit-learn matplotlib scipy requests
824
-
825
- # Verify installation
826
- pip list
827
- ```
828
-
829
- 5. Issue 5: Virtual Environment Issues
830
- [=] Solution:
831
- - ```
832
- # Deactivate current environment
833
- deactivate
834
-
835
- # Create a fresh virtual environment
836
- python -m venv fresh_venv
837
-
838
- # Activate it
839
- source fresh_venv/bin/activate # Linux/Raspberry Pi
840
- # or
841
- fresh_venv\Scripts\activate # Windows
842
-
843
- # Reinstall
844
- pip install --upgrade pip
845
- pip install numpy pandas scikit-learn matplotlib scipy
846
- ```
847
-
848
- 6. Issue 6: Raspberry Pi - "Bus error" or Performance Issues
849
- Solution:
850
- - [=] Ensure adequate swap space:
851
- ```
852
- free -h # Check current swap
853
- sudo nano /etc/dphys-swapfile # Increase if needed
854
- ```
855
- - Close unnecessary applications before running
856
- - Consider using a faster SD card (UHS-I or better)
857
-
858
- 7. Issue 7: P2P Undefined Connection:
859
- If you get this warning:
860
- - ```
861
- [❌] Failed to connect to <host>:<port>: Nonetype object has no attribute .accept()
862
- ```
863
- - [=] Solution:
864
- - ```
865
- # initiate socket first
866
- main_model.distribution.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
867
- main_model.distribution.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
868
- main_model.distribution.socket.bind(('0.0.0.0', self.port)) # self.port could be changed with other ports
869
- main_model.distribution.socket.listen(5) # listens for 5 seconds
870
- ```
871
- 8. Issue 8: Cannot compare using '<' with str and float data:
872
- - This happens when one of the labels extracted from your CSV file has NaN value, consider replace NaN with actual labels.
873
-
874
- ## [=] Detailed process of Alpha-computing
875
-
876
- <img width="720" height="338" alt="WhatsApp Image 2026-05-04 at 17 43 35" src="https://github.com/user-attachments/assets/3d149dce-cf3b-44c9-80b0-fa68290a2019" />
877
-
878
- <img width="720" height="388" alt="WhatsApp Image 2026-05-04 at 17 44 04" src="https://github.com/user-attachments/assets/b1efedf6-5aa1-431e-89da-5f422549b453" />
879
- 🧠 What Alpha-Based Computation Actually Does
880
-
881
- At its core, alpha (α) is a control parameter that blends two different information paths inside a given transformer:
882
- A_final = α · A_fixed + (1 − α) · A_learned.
883
- [~] Where:
884
- - A_fixed stable, non-trainable (or minimally changing) attention
885
- - A_learned → dynamic, trainable attention (Q, K, V)
886
- - α [0, 1] controls how much each path contributes
887
-
888
- [~] Forward Pass -> Controlling Information Flow:
889
- During the forward pass, alpha determines what representation the model uses.
890
- If α is high (e.g., 0.8–1.0): Model relies mostly on stable attention
891
- outputs are consistent → less noise → safer early training, If α is low (e.g., 0.0–0.3), Model relies mostly on learned attention, → more expressive → but unstable early on.
892
- So in forward propagation, alpha is essentially, “How much do I trust learned attention vs safe attention?”
893
-
894
- [~] Backward Pass -> Controlling Gradient Flow:
895
- When gradients flow backward:
896
- ```
897
- - dA_final splits into two paths
898
- - Mathematically:
899
- - dA_fixed = α · dA_final
900
- - dA_learned = (1 α) · dA_final
901
- ```
902
-
903
- [~] Simple Explanation:
904
- 1. If α (alpha) is high: → most gradient goes to fixed path → learned attention gets very little update → training is stable but slow
905
- 2. If α is low: → most gradient goes to learned attention → fast learning → but noisy / unstable
906
-
907
- [=] Why This Matters for Training
908
- 1. Without alpha: attention starts random → gradients noisy → model stuck (~10% accuracy)
909
- 2. With alpha: early stage -> rely on stable structure meaningful gradients
910
-
911
-
912
-
913
- ## Main Components
914
- [=] 1. - Consider checking and run: [IntegratedPipeline_Flow.html](IntegratedPipeline_Flow.html) regarding each function of the whole components and deep-dive mechanism.
915
- 2. - consider checking [ARCHITECTURE.md](ARCHITECTURE.md) for more explanation about the main components.
916
-
917
- [=] With 20 total architectures working together as a standalone library that is efficient and robust, Main components include:
918
-
919
- 1. GeometricWeightShaping
920
- Purpose: Analyzes the geometric structure of data (anisotropy, spectral properties, complexity) and generates optimal weight matrices based on that geometry. Essentially teaches the model how to "understand" the shape of data before processing it, Highly robust to noise, making it an excellent fit for messy environment.
921
- ---
922
- 2. Activation
923
- Purpose: Provides standard neural network activation functions (ReLU, sigmoid, softmax) and their derivatives for backpropagation for MLP Class.
924
- ---
925
- 3. Loss
926
- Purpose: Implements categorical crossentropy loss and its gradient for training classification models for both MLP and The Transformer
927
- ---
928
- 4. Transformer
929
- Purpose: A complete transformer implementation with multi-head attention, positional embeddings, feed-forward networks, layer normalization, and custom backpropagation. Includes both fixed (stable) and dynamic (adaptive) training modes necessary for Scarce data environment using algorithm such as Alpha based computing directly during forward pass.
930
- ---
931
- 5. Dense
932
- Purpose: A geometric-aware dense layer that adapts its weights based on input data geometry and handles variable input dimensions automatically.
933
- ---
934
- 6. SoftmaxOutput
935
- Purpose: A simple wrapper around softmax activation that stores the output and passes gradients through unchanged (since softmax + crossentropy gradient is handled elsewhere).
936
- ---
937
- 7. MLP
938
- Purpose: A multi-layer perceptron that can switch between standard training and "focused" training (using feed-forward layers only) based on data complexity. Includes prediction, scoring, and geometric measurement methods.
939
- ---
940
- 8. WeightedEnsemblePredictor
941
- Purpose: Combines Transformer and MLP predictions using dynamic weighting based on attention quality, model confidence, and agreement. Also manages memory storage, explainability, and peer agent communication.
942
- ---
943
- 9. CrossSessionAutomation
944
- Purpose: Manages exporting, importing, and syncing model sessions across different devices or time periods. Allows saving entire model states to JSON and transferring them over network sockets.
945
- ---
946
- 10. ExplainabilityModule
947
- Purpose: Generates human-readable explanations for predictions, learns from user feedback, maintains decision history, and batch-trains on corrections. The transparency layer for the AI agent.
948
- ---
949
- 11. ModelStorage
950
- Purpose: SQLite-based persistence for models, attention weights, node memories, and agent data. Handles serialization/deserialization of numpy arrays and model dictionaries.
951
- ---
952
- 12. AgentDistributedInference
953
- Purpose: The distributed agent system - can act as a server or client, handles SSL/TLS security, rate limiting, authentication, peer-to-peer prediction requests, memory synchronization, ensemble voting, and trust management between agents.
954
- ---
955
- 14. QueryNode
956
- Purpose: Manages trust relationships and identity verification between nodes. Evaluates node agreement, establishes connections, performs safety checks, and maintains the network of trusted peers.
957
- ---
958
- 14. AutoBatcherAutomation
959
- Purpose: Automatically batches incoming prediction requests to optimize throughput. Collects requests up to a maximum batch size or time window, then processes them together.
960
- ---
961
- 15. IntegratedPipeline
962
- Purpose: The main orchestration class that ties everything together - handles text encoding, model initialization, training, prediction, memory management, hybrid predictions, and distributed inference coordination.
963
- ---
964
- 16. PipelinePredictionManager
965
- Purpose: High-level prediction interface that loads labels from CSV, performs regular/advanced/hybrid predictions, displays results, and calculates entropy for uncertainty estimation.
966
- ---
967
- 17. ThreadedMessageQueue
968
- purpose: Handles message queue in thread for asynchronous message handling. (Queue based)
969
- ---
970
- 18. AsyncMessageQueue
971
- purpose: Handles incoming message from Asychronous peer request (Queue based)
972
- ---
973
- 19. CohesiveAgentDeployment
974
- purpose: Handles both synchronous prediction, and P2P Asynchronous prediction request, acts as a server and a listener simultaneously.
975
- ---
976
- 20. ConsecutivePeerAgent
977
- purpose: handles ensemble weighting from received output from peer, managed server and acts as a listener simultaneously.
978
-
979
-
980
- ## Full Documentation Features
981
- - [Go to IntegratedPipeline-Specialized-AI-Agent-library](#IntegratedPipeline-Specialized-AI-Agent-library)
982
- - [Go to MANN Intro](#MANN-Intro)
983
- - [Go to Abstract Weight Encoder (AWE) Intro](#Abstract-Weight-Encoder-(AWE)-Intro)
984
- - [Go to Why IntegratedPipeline?](#Why-IntegratedPipeline?)
985
- - [Go to Requirements](#Requirements)
986
- - [Go to System-Specific-Notes](#System-Specific-Notes)
987
- - [Go to Quickstart with Docker](#Quickstart-with-Docker)
988
- - [Go to Performance in ARM64 Environment/Container](#Performance-in-ARM64-Environment/Container)
989
- - [Go to Step's for in-depth Usage](#Step's-for-in-depth-Usage)
990
- - [Go to Troubleshooting](#Troubleshooting)
991
- - [Go to Detailed process of Alpha-computing](#Detailed-process-of-Alpha-computing)
992
- - [Go to Main Components](#Components)
993
- - [Go to Source code](#Source-code-of-AbstractIntegratedModule)
994
- - Consider checking:
995
- - [ROADMAP.md](ROADMAP.md)
996
- - [Contributing.md](Contributing.md)
997
- - [changelog.md](changelog.md)
998
- - [requirements-dev.txt](requirements-dev.txt) for contributors requirements.
999
- - [architecture_diagram.js](architecture_diagram.js).
1000
-
1001
- ## License
1002
- [=] LICENSE: - MIT (2026) || See [LICENSE](LICENSE) for more information.
1003
-
1004
-
1005
-
1006
-
1007
-
1008
-
1009
-
1010
-
1
+ Metadata-Version: 2.4
2
+ Name: AbstractIntegratedModule
3
+ Version: 0.1.6
4
+ Summary: Advanced Integrated Non-LLM AI Module for Agentic Framework - Multi-agent P2P inference
5
+ Author: Micro-Novelty
6
+ Author-email: hernikpuspita5@gmail.com
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: numpy>=1.21.0
17
+ Requires-Dist: scikit-learn>=1.0.0
18
+ Requires-Dist: pandas>=1.3.0
19
+ Requires-Dist: joblib>=1.1.0
20
+ Requires-Dist: cryptography>=41.0.0
21
+ Requires-Dist: aiohttp>=3.8.0
22
+ Requires-Dist: psutil>=5.9.0
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: license
29
+ Dynamic: requires-dist
30
+ Dynamic: requires-python
31
+ Dynamic: summary
32
+
33
+ # [=] IntegratedPipeline-Specialized-AI-Agent-library
34
+
35
+ [~] IntegratedPipeline is a standalone Specialized AI Agent Library for Non-LLL memory Augmented Agentic Framework orchestrator, Specifically designed to provide Agentic capability for any Autonomous Agentic Framework locally and Coordinatively that runs efficiently from consumer based machine to High-end embedded systems, where the AI Can directly and continously learn, with minimal and efficient compute, built-in augmented memory, Secure Peer-To-Peer (Multi-Agent) Coordination with security layers as an option, And Explainability capability based on proof from in it's internal metrics, reducing Black-Box condition necessary for reliability. Containing specialized MLP using Its Own specialized geometric Weight shaping (AWE) and Specialized efficient Transformer for Scarce Data with Alpha-based computation, specifically designed for low-amount samples environment, or Messy environments.
36
+
37
+ <img width="1280" height="600" alt="WhatsApp Image 2026-05-27 at 07 16 32" src="https://github.com/user-attachments/assets/4b58a556-45a3-419b-96fd-9c1b76cac574" />
38
+
39
+
40
+ ## [+] MANN Intro
41
+ [=] Memory augmented Neural network (MANN) is a neural network architecture coupled with an external, dynamic memory module, allowing it to store, retrieve, and update information similarly to a computer's RAM. Unlike traditional networks that store knowledge only in weight parameters, MANNs excel at fast learning, long-term dependency handling, and episodic recall, In IntegratedPipeline, Its memory is stored in a custom database inside your local machine, then later used for memory retrieval, transfered to the AI Dictionary where it can finnaly recall its memory when input condition matched with memory.
42
+
43
+ ## [+] Abstract Weight Encoder (AWE) Intro
44
+ [=] AWE is a specialized custom weight shaping or encoding method Specifically designed for MLP Architecture, using eigenvalue and spectral methods as base equations to calculate covariance inside a given input data, and shape the correct Weight from the given eigenvalue, AWE Works by processing input and then captures the necessary eigenvalue to shape a properly initialized Weight that aligns with input data complexity, With this approach, MLP training will be much more consistent and robust against noise.
45
+
46
+ [~] For a much In-Depth Explanation You can visit This repository to learn more about AWE and its performance results:
47
+ - Link: https://github.com/Micro-Novelty/Specialized-MLP-for-noise-robustness
48
+
49
+ ## [+] Why IntegratedPipeline?
50
+ [~] IntegratedPipeline is a great choice for a sophisticated Non-LLM AI Program for The Main Orchestrator of a Distributed MANN-Type AI Agent Working in Edge-device/Consumer-Based machine Where LLM is'nt a great fit for Messy, Noisy environments. while still run efficiently on High-end Embedded systems in single-instance or as a distributed network during multi Agent cooperation.
51
+
52
+ [=] IntegratedPipeline offers:
53
+ 1. Local-Based AI Orchestrator:
54
+ - IntegratedPipeline Creates its own SQLite Database inside Your Computer once the library is executed, This database is used directly to store the AI Memory, Attention weights, predicted Output, and identified peer, all without leaving the machine, The Database will be created Automatically once you run the library, database name saved as activity_log.db.
55
+
56
+ 2. Continously Learning behavior for an Agent:
57
+ - different from LLM that is static and cannot improve beyond its given training condition, AI Agent using IntegratedPipeline has a dynamic, flexible continously learning behavior with conditional training algorithms included in the library that has both supervised and unsupervised learning present, The learned input and predicted Output will be stored in the database, allowing it to recall its memory during processing and find matching known prediction given if input matched with the stored input inside the database. this Continous learning behavior is efficient because its not relying on weights for memory, allowing flexible and predictable behavior inside a given environment.
58
+
59
+ 3. Robust Specialized MLP and Transformer Architecture with ensemble weighting:
60
+ - IntegratedPipeline has 2 Different type's of AI Architecture stacked together, and one architecture to weight their confidence and probability fairly to get the final prediction, Specialized MLP for Noise robustness And Specialized Transformer that used Alpha-based Computing algorithm for contextual reasoning, The reason why those Models complement and used together :
61
+ - Specialized MLP Provides synchronous robust classification Against noise with its specialized Weight Encoder (AWE) to handle noise using eigenvalue based computing that is lightweight and efficient. This Method can't be replicated Inside Transformer FFN (Feed-forward-network) because of Transformer dynamic brute force computing where AWE-Based generated weight's get diluted over time by Transformer dynamic projection embedding, making AWE Generated weight causes inefficient inside Transformer dynamic FFN/QKV projection.
62
+ - Specialized Transformer provides robust synchronous advanced contextual relationships, efficient data processing using Alpha based computing, The Transformer is tuned towards to be as flexible as possible to provide dynamic projection or fixed FFN projection training with minimal head's and dimension's to reduce computational power.
63
+ - Ensemble weighting provides the model a much more robust classification best from both worlds perspective, weighting both MLP and Transformer confidence and probability, combined with Attention quality from the transformer to get the final prediction of an input if transformer is allowed and permitted to be in use.
64
+
65
+ 4. flexible and secure Peer-to-Peer Coordination (Multi-Agent):
66
+ - IntegratedPipeline offers Peer to Peer communication capabilities asynchronously, Where IntegratedPipeline directly checks for other Peer presence directly to the local database present in the local computer or system (Synchronous prediction from peer previous data in the database), or externally, by using asynchronous request for initiating prediction, P2P is secured Using:
67
+ - secure socket using user provided SSL CERT. on both client and server,
68
+ - API key for requesting,
69
+ - Alpha rate limiting,
70
+ - HMAC secret key for authentication,
71
+ - and IP validation.
72
+ [~] Each agent has double roles during P2P:
73
+ - Server provider: the peer Agent can start a server to listen for peer client's
74
+ - Connecting Agent: the peer Agent which happens to connect to other peer that has or have opened and provided a server listener to act as a receiver.
75
+
76
+ 5. Cross-Session memory availability:
77
+ - IntegratedPipeline offers share-able Memory capability, included capability below:
78
+ - Exportable memory: this allows a flexible memory saving for later use, such as cross transfer memory between model, the memory is saved as .json file after exporting.
79
+ - Importable Memory: allowing to import memory from the exported .json file directly for the model to use.
80
+ - syncing with other model: socket-based communication to export memory to other external machine.
81
+ - [=] Note: socket Syncing is unsecure witout additional security layer wrapped, For a safer syncing, directly transfer the .json file memory to the target machine via other ways such as manual send.
82
+ - list sessions: listing available sessions using model's memory name.
83
+
84
+ [=] With its Specialized Multi-Layer-Perceptron (using AWE Encoder) and Optimized Transformer module with optimized Embedding, IntegratedPipeline can directly tolerate low samples-amount of Data, including noisy ambiguous data, using Weighted Confidence assembling from both specialized MLP and Transformer for better reliability during training and prediction over Messy, noisy environments, such as:
85
+
86
+ [1.] User data's : User data is often messy and ambiguous, Specialized MLP with AWE will do the job for shaping the necessary Weight to complement for the Ambiguous noisy pattern, AWE MLP is highly robust to noise, proven in synthetic Environment such as scikit-learn Make-Classification scarce and Noisy Input robustness during generalization test. making it a great fit for messy, Scarce data.
87
+
88
+ [2.] Small Dataset's : We often don't have enough Dataset to train a Transformer Model, Thats Why IntegratedPipeline Offers a Highly optimized Transformer that supports scarce dataset processing, Using Alpha-Based computing as a Warm-up for training, it provides a direct Boost for the transformer to be efficient during training in scarce-data Environment.
89
+
90
+ [3.] Non-Representative data (Undersampled) : IntegratedPipeline Support's ambiguous data that come's from file with format such as CSV Format to extract title's and label's necessary to create automatic Dataset for Later use in Training, making it optimized for specific task's and easier dataset creation with lower overfitting rate for reliability.
91
+
92
+ [=] Architectural-Overview
93
+ <img width="1600" height="860" alt="WhatsApp Image 2026-05-09 at 16 13 41" src="https://github.com/user-attachments/assets/580722aa-bbd8-4148-a425-4bff01c06c47" />
94
+ [=] Contextual meaning:
95
+ 1. - Sequence encoding is a machine learning technique that transforms a sequential input (like text, time-series data, or audio) into a compact, fixed-length numerical vector, often called a context vector
96
+ 2. - TF-IDF (Term Frequency-Inverse Document Frequency) is a numerical statistic used in machine learning and NLP to evaluate how important a word is to a document within a collection (corpus). It boosts rare words and penalizes common words (like "the", "and") by multiplying two metrics: how often a word appears in a document (TF) and the inverse frequency of the word across all documents (IDF).
97
+ 3. - Explainability provides deeper transparency of why a model thought about a detail by showing its internal metrics like attention quality, from distributed peer memory or Ensemble prediction result's.
98
+
99
+ ### Introduction and demo
100
+ [![Introduction and demo:](https://youtube.com)](https://youtu.be/RmWvwDHU_QY?si=Lvl8mt8c_BnFypS_)
101
+
102
+ ## [=] Requirements
103
+ [~] To run and execute IntegratedPipeline, Requirement's include Or see [Requirements](requirements.txt):
104
+ - pip install for quick usage:
105
+ - ```bash
106
+ pip install AbstractIntegratedModule # or
107
+ python -m pip install AbstractIntegratedModule
108
+ ```
109
+
110
+ - Download binaries manually (Choose one minimal, specified for your needs):
111
+ - Binaries can be downloaded from release or code section.
112
+ - Windows Native OS - AbstractIntegratedModule.cp313-win_amd64 Supports Python 3.13 for Windows Only (Robust, Stable version)
113
+ - Linux x86_64 - AbstractIntegratedModule.cpython-312-x86_64-linux-gnu.so supports Python 3.12 only.
114
+ - Linux ARM64 - Raspberry Pi (Supports Raspberry pi 3 - 5) - AbstractIntegratedModule.cpython-310-aarch64-linux-gnu.so supports Python 3.10 only.
115
+ - Libraries needed (For binary usage):
116
+ - Pandas
117
+ - aiohttp
118
+ - scikit-learn
119
+ - numpy
120
+ - psutil
121
+
122
+ - Download AbstractIntegratedModule binaries from release section or in here, [AbstractIntegratedModule Package](AbstractIntegratedModule-Package.zip)
123
+ - This file contains:
124
+ - AbstractIntegratedModule.pyd (For windows machine).
125
+ - AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so (For linux x86_64).
126
+ - AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so (for Linux ARM64 - Raspberry Pi).
127
+
128
+ [=] for labels assignation:
129
+ - CSV file that contains training labels and titles used for training and prediction label map, example will be provided below, Go to Step's for in-depth Usage below.
130
+
131
+ ### [=] Requirements for Docker container
132
+ - Dockerfile (For Container assembler)
133
+ - Python scripts (Such as main.py for Dockerfile usage).
134
+ - entrypoint.sh (for smart entry point for Dockerfile container usage).
135
+
136
+ ## [=] System-Specific Notes
137
+ 1. Windows:
138
+ - Requires Visual C++ Build Tools for compatibility
139
+ - Use PowerShell or CMD (not WSL bash for best results)
140
+
141
+ 2. Linux:
142
+ - Ensure gcc and build-essential are installed
143
+ - Different distributions may require different package managers
144
+
145
+ 3. ARM64 - Raspberry Pi
146
+ - Installation may take 30+ minutes due to ARM architecture
147
+ - Monitor system resources during installation
148
+ - Consider using faster storage (USB SSD) for better performance
149
+
150
+ ## [=] Docker Container Application
151
+ 0. See [Docker_installation_Section](Docker_installation_Section.md) for an in-depth explanation, or [Quick_Docker_start](Quick_Docker_start.sh) for a quick start.
152
+ - Note Consider checking:
153
+ - [Dockerfile](Dockerfile) contains all the instructions need to assemble a Docker container.
154
+ - [start.sh](start.sh) for Quick single agent start in Docker container.
155
+ - [entrypoint.sh](entrypoint.sh) for a Smart entrypoint used in Dockerfile (Must be downloaded too along with Dockerfile and put in the same folder with Dockerfile after its downloaded)
156
+ - [start-multi-agent-cluster.sh](start-multi-agent-cluster.sh) for Multi-agent cluster start in Docker container, What it does:
157
+ - Starts a multi-agent Docker cluster — runs docker-compose up -d in detached mode (background), scaling the agent-client service to 5 simultaneous instances, alongside whatever server is defined in the docker-compose.yml.
158
+ - Tails the logs runs docker-compose logs -f which streams live logs from all containers (server + all 5 clients) to your terminal until you hit Ctrl+C.
159
+ - [main.py](main.py) for executing a python script in the Docker container that used main.py, like in this code:
160
+ - ```bash
161
+ docker run -it -v $(pwd):/app/data integrated-pipeline:latest python /app/data/main.py
162
+ ```
163
+ - To use a [.dockerignore](.dockerignore) file, place it in your build context directory (the same location as your Dockerfile) to specify which files and folders should be excluded when building your image.
164
+ - [.env](.env) is used for environment setup in [entrypoint.sh](entrypoint.sh), this file must be in the same folder with Dockerfile and entrypoint.sh after its downloaded.
165
+
166
+ 1. Build Image:
167
+ - Clone repository:
168
+ - ```bash
169
+ git clone https://github.com/Micro-Novelty/IntegratedPipeline-Continous-Learning-AI-Agent-library-framework.git
170
+ cd IntegratedPipeline-Continous-Learning-AI-Agent-library-framework
171
+ ```
172
+ - Download:
173
+ - [Dockerfile](Dockerfile),
174
+ - [entrypoint.sh](entrypoint.sh)
175
+ - [.env](.env)
176
+ - In the code or release section.
177
+
178
+ - If the downloaded Dockerfile or .dockerignore or .env has .txt extension, remove the extension:
179
+ - ```bash
180
+ # remove .txt extension
181
+ mv Dockerfile.txt Dockerfile
182
+ mv env.txt .env
183
+ mv dockerignore.txt .dockerignore
184
+ ```
185
+ - Navigate to the folder: Use the cd command to enter the directory containing the Dockerfile and entrypoint.sh file.
186
+ - ```
187
+ cd /path/to/your/folder
188
+ ```
189
+ - build image:
190
+ - ```bash
191
+ sudo docker build -t integrated-agent.
192
+ ```
193
+ 2. Download library dependencies for binaries usage:
194
+ [=] Required libraries (when using binary):
195
+ - Numpy
196
+ - Scikit-learn
197
+ - pandas
198
+ - aiohttp
199
+ - psutil
200
+
201
+ 4. Run IntegratedPipeline in a Container:
202
+ - Install AbstractIntegratedModule via PIP or binaries (for binaries, can be downloaded in release section):
203
+ - ```bash
204
+ pip install AbstractIntegratedModule # or
205
+ python -m pip install AbstractIntegratedModule
206
+ ```
207
+
208
+ - ```bash
209
+ docker run -it --name ai-agent integrated-agent:latest python
210
+ ```
211
+ - In python shell:
212
+ - ```
213
+ from AbstractIntegratedModule import IntegratedPipeline, PipelinePredictionManager
214
+ model = IntegratedPipeline('agent_memory')
215
+ print("✓ IntegratedPipeline initialized successfully!")
216
+ ```
217
+
218
+ 5. Run script:
219
+ ```bash
220
+ # Mount your local directory and run a script
221
+ docker run -it -v $(pwd)/data:/app/data integrated-agent:latest python main.py # main.py could be replaced
222
+ ```
223
+
224
+ 6. Run with GPU Support (Optional):
225
+ - ```bash
226
+ # For NVIDIA GPU support
227
+ docker run -it --gpus all -v $(pwd)/data:/app/data integrated-agent:latest python main.py
228
+ ```
229
+
230
+ 7. For Single Agent and Multi-Agent P2P:
231
+
232
+ [=] Single agent:
233
+ ```bash
234
+ # Build image
235
+ docker build -t integrated-agent:latest .
236
+
237
+ # Run single agent
238
+ docker run -it -v $(pwd)/data:/app/data integrated-agent:latest python
239
+ ```
240
+
241
+ [=] Multi agent P2P (Consider docker-compose) :
242
+ - Note: Use the provided [docker-compose.yml](docker-compose.yml) for Quick multi-agent.
243
+ - Navigate to the folder: Use the cd command to enter the directory containing the docker-compose.yml file.
244
+ - ```
245
+ cd /path/to/your/folder
246
+ ```
247
+ - run this command to run docker-compose.yml:
248
+ - ```bash
249
+ # Start multiple agents
250
+ docker-compose up -d
251
+
252
+ # View logs
253
+ docker-compose logs -f
254
+
255
+ # Stop all agents
256
+ docker-compose down
257
+ ```
258
+
259
+ ## Performance in linux ARM64 Docker Environment/Container
260
+ A. [=] Computational performance results with Transformer included during Advanced prediction method.
261
+ ```txt
262
+ == TIME == | CPU % | RAM / RAM LIMIT ||
263
+
264
+ 14:50:08.762 0.00% 25.52MiB / 3.71GiB
265
+ 14:50:10.339 5.56% 25.52MiB / 3.71GiB
266
+ 14:50:12.428 0.17% 25.52MiB / 3.71GiB
267
+ 14:50:15.835 103.60% 38.8MiB / 3.71GiB
268
+ 14:50:17.844 438.11% 60.15MiB / 3.71GiB
269
+ 14:50:19.896 419.36% 68.32MiB / 3.71GiB
270
+ 14:50:22.022 434.15% 73.2MiB / 3.71GiB
271
+ 14:50:23.969 436.47% 78.18MiB / 3.71GiB
272
+ 14:50:25.966 435.85% 80.22MiB / 3.71GiB
273
+ 14:50:28.018 430.47% 92.12MiB / 3.71GiB
274
+ 14:50:30.029 450.55% 99.5MiB / 3.71GiB
275
+ 14:50:32.065 438.06% 105.4MiB / 3.71GiB
276
+ 14:50:34.100 469.52% 115.2MiB / 3.71GiB
277
+ 14:50:36.109 449.89% 116.8MiB / 3.71GiB
278
+ 14:50:38.123 423.56% 119MiB / 3.71GiB
279
+ ```
280
+ - [=] Note: To read the full logs (For included Transformer performance): [performance_log_with_TF](performance_log_with_TF.txt)
281
+ - [=] Explanation:
282
+ - Average CPU Usage = 420% - 430% , Sustained roughlt 4.20 - 4.30 CPU Cores
283
+ - Meaning = - Compute-Intensive workload
284
+ - reduced guaranteed of experiencing deadlocks, thread starvation, and major stalls
285
+ - numerical backend is parallelizing efficiently
286
+ - Average RAM Usage = 180 - 195 Mib, Roughly 4.5 - 5% usage of available RAM
287
+ - Meaning = - Very efficient RAM Usage
288
+ - Repeated 269 MiB suggests allocator settled, ndarray pools stabilized, workload reached steady state
289
+ - gradual, safe and steady batch accumulation, reduced possibility of leak explosion.
290
+
291
+ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
292
+ ```txt
293
+ == TIME == | CPU % | RAM \ RAM LIMIT |
294
+ 10:01:37.456 100.44% 269.8MiB / 3.71GiB # initial round 1 training started
295
+ 10:01:38.686 101.93% 279.8MiB / 3.71GiB
296
+ 10:01:40.694 101.94% 293.2MiB / 3.71GiB
297
+ 10:01:42.703 99.90% 302.9MiB / 3.71GiB
298
+ 10:01:44.712 99.34% 319.8MiB / 3.71GiB
299
+ 10:01:46.721 100.15% 319.7MiB / 3.71GiB
300
+ 10:01:48.727 101.91% 319.7MiB / 3.71GiB
301
+ 10:01:50.734 100.86% 319.7MiB / 3.71GiB
302
+ 10:01:52.742 136.43% 322.9MiB / 3.71GiB
303
+ 10:01:54.751 101.91% 324.9MiB / 3.71GiB
304
+ 10:01:56.758 100.29% 324.9MiB / 3.71GiB
305
+ 10:01:58.769 102.42% 327.1MiB / 3.71GiB
306
+ 10:02:00.775 0.00% 329.6MiB / 3.71GiB # First Training and prediction round 1 finished
307
+ 10:02:02.788 19.55% 330.1MiB / 3.71GiB # round 2 training
308
+ 10:02:04.798 134.23% 332.2MiB / 3.71GiB
309
+ 10:02:06.803 108.80% 332.2MiB / 3.71GiB
310
+ 10:02:08.811 107.85% 332.2MiB / 3.71GiB
311
+ 10:02:10.857 104.43% 332.2MiB / 3.71GiB
312
+ 10:02:12.854 101.14% 332.2MiB / 3.71GiB
313
+ 10:02:14.858 0.00% 332.3MiB / 3.71GiB
314
+ 10:02:16.873 98.84% 333.8MiB / 3.71GiB
315
+ 10:02:18.869 0.00% 132.7MiB / 3.71GiB # container stopped and round 2 finished
316
+ ```
317
+ - [=] Note: See full performance log in here: [performance_log_only_MLP](performance_log_only_MLP.txt)
318
+ - [=] Explanation:
319
+ - Average CPU Usage = 85-90% Used, sustained roughly 1 CPU Core saturated on average
320
+ - Meaning: - Very efficient computation
321
+ - Much lighter CPU Usage than Transformer.
322
+ - Stable and less parallelizing behavior (Efficient computation)
323
+ - 4.7x lower CPU usage than transformer included
324
+ - Average RAM usage = 314 MiB / 3.71 GiB, Roughly 8.5% usage of available RAM.
325
+ - Meaning: - Slightly larger MiB used than Transformer.
326
+ - Model allocation growth is stable,
327
+ - training buffers stable
328
+ - temporary ndarray growth.
329
+
330
+ ### Both performance Overview
331
+ <img width="1536" height="1024" alt="WhatsApp Image 2026-05-24 at 10 27 00" src="https://github.com/user-attachments/assets/9404277f-281f-4893-8367-e494833230ea" />
332
+
333
+ ## Source code of AbstractIntegratedModule
334
+ - [=] Full Monolithic extensively-documented source code (12K+ Lines): [AbstractIntegratedPipeline-SourceCode.zip](AbstractIntegratedPipeline-SourceCode.zip)
335
+ - [=] Separated Modules of AbstractIntegratedModule: [AbstractIntegratedModule-separated-modules](AbstractIntegratedModule-separated-modules)
336
+ - [~] Note:
337
+ - The source code is open and Free to anyone who:
338
+ - Use it: Run the software for any personal, academic, or commercial purpose.
339
+ - Modify it: Change the source code to fit their needs.
340
+ - Distribute it: Share the original or modified code with others.
341
+ - Commercialize it: Package, brand, and sell the software for profit.
342
+
343
+ ## [=] Step's for in-depth Usage
344
+ 1. Download:
345
+ - AbstractIntegratedModule.pyd (For Windows) (Python 3.13),
346
+ - AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so (For linux x86_64) (Python 3.12)
347
+ - AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so (for Linux ARM64 - Raspberry Pi) (Python 3.10)
348
+ - ```
349
+ # Download from release
350
+ # AbstractIntegratedModule.pyd (windows) /
351
+ # Abstractcpython-39-x86_64-linux-gnu.so (x86_64) /
352
+ # AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so
353
+ ```
354
+
355
+ [=] Steps for installation:
356
+ Note: AbstractIntegratedModule has 5 library dependencies that must be installed on your computer if you use AbstractIntegratedModule binaries:
357
+ - [=] Required Libraries (For binaries usage):
358
+ - Numpy
359
+ - Scikit-learn
360
+ - pandas
361
+ - aiohttp
362
+ - psutil
363
+
364
+ 1. Clone repository:
365
+ - ```
366
+ # prerequisites (for Raspberry pi OS Only)
367
+ # Update system
368
+ sudo apt-get update
369
+ sudo apt-get upgrade -y
370
+
371
+ # Install Python 3.13 and development tools
372
+ sudo apt-get install python3.13 python3.13-dev python3.13-venv -y
373
+
374
+ # Install additional build tools
375
+ sudo apt-get install build-essential libatlas-base-dev libjasper-dev -y
376
+
377
+ # Clone immediately for Windows and x86_64 only without prerequisites
378
+ git clone https://github.com/Micro-Novelty/IntegratedPipeline-Continous-Learning-AI-Agent-library-framework.git
379
+ cd IntegratedPipeline-Continous-Learning-AI-Agent-library-framework
380
+ ```
381
+ 2. Install System Dependencies (for x86_64 installation):
382
+ ```
383
+ # Ubuntu/Debian
384
+ sudo apt-get update
385
+ sudo apt-get install python3.13 python3.13-dev python3.13-venv
386
+
387
+ # CentOS/RHEL
388
+ sudo yum install python313 python313-devel
389
+
390
+ # Fedora
391
+ sudo dnf install python3.13 python3.13-devel
392
+ ```
393
+
394
+ 3. Create a virtual environment:
395
+ - ```
396
+ # Create virtual environment (windows)
397
+ python -m venv venv
398
+ # Activate virtual environment
399
+ venv\Scripts\activate
400
+
401
+ # Create virtual environment (x86_64) (ARM64 / raspberry pi)
402
+ python3.13 -m venv venv
403
+ # Activate virtual environment
404
+ source venv/bin/activate
405
+ ```
406
+
407
+ 4. Copy AbstractIntegratedModule binary:
408
+ - ```
409
+ # For windows:
410
+ # Copy the .pyd file to your project root
411
+ # AbstractIntegratedModule.pyd
412
+ copy C:\path\to\AbstractIntegratedModule.pyd .\AbstractIntegratedModule.pyd
413
+
414
+ # Copy the .so file to your project root (for x86_64)
415
+ cp /path/to/AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so ./AbstractIntegratedModule.cpython-39-x86_64-linux-gnu.so
416
+
417
+ # Copy ARM64 / Raspberry pi binary
418
+ cp /path/to/AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so ./AbstractIntegratedModule.cpython-39-aarch64-linux-gnu.so
419
+
420
+ 5. Verify Installation:
421
+ - ```
422
+ python -c "from AbstractIntegratedModule import IntegratedPipeline; print('✓ Installation successful!')"
423
+ ```
424
+
425
+ 6. Run main.py for quick test of successful imports:
426
+ - ```
427
+ # run this for quick import test.
428
+ python main.py
429
+ ```
430
+
431
+
432
+
433
+ 3. Create CSV file that contains training labels and titles:
434
+ - Example format:
435
+ ```txt
436
+ window_title,label
437
+ "Thesis.docx",focused_work,high,writing-thesis
438
+ "Microsoft Excel",work,medium,data-analysis
439
+ "YouTube -> Google Chrome",distracted,high,watching-videos
440
+ "Slack",communication,high,team-chat
441
+ "VSCode", focused_work,high,coding
442
+ "netflix.com -> Google Chrome",break,high,Netflix-break
443
+ "Outlook",work,medium,checking-email
444
+ "System Settings",system designing,low,configuring-computer
445
+ "GitHub",creating-and-editing-repo,research
446
+ "README.md -> VS Code",focused_work,medium,reading-docs
447
+ "Amazon.com -> Chrome",personal-work,high,shopping
448
+ ```
449
+ Note = window_title is target_title and label is target_label, check step below to use it.
450
+
451
+ 4. Use IntegratedPipeline as in this example:
452
+ ```python
453
+ from AbstractIntegratedModule import IntegratedPipeline
454
+ from AbstractIntegratedModule import PipelinePredictionManager
455
+ import numpy as np
456
+
457
+ memory_name = 'agent_memory'
458
+ main_model = IntegratedPipeline(memory_name, use_async=True, ssl_cert_file=cert_file, ssl_key_file=key_file) # provide cert_file path or key_file path (optional)
459
+ main_prediction = PipelinePredictionManager(main_model, label_csv='example_manual_training.txt', target_title='window_title', label='label')
460
+ # example_manual_training is a .txt file that contain csv format like above example.
461
+
462
+
463
+ example_rules = [
464
+ # === WORK / PRODUCTIVITY ===
465
+ (r'code|programming|develop|debug|compile|script', 'focused_work'),
466
+ (r'vscode|visual_studio|ide|terminal|shell', 'focused_work'),
467
+ (r'notion|evernote|onenote|notes|todo|task', 'productive'),
468
+ (r'slack|teams|discord|zoom|meeting|call', 'communication'),
469
+ (r'email|gmail|outlook|inbox|mail', 'communication'),
470
+
471
+ # === ENTERTAINMENT ===
472
+ (r'youtube|netflix|twitch|stream|video', 'entertainment'),
473
+ (r'music|spotify|soundcloud|audio|player', 'entertainment'),
474
+ (r'game|gaming|steam|epic|play', 'gaming'),
475
+ (r'facebook|instagram|tiktok|social|post', 'social_media'),
476
+
477
+ # === BROWSING ===
478
+ (r'chrome|firefox|edge|safari|browser', 'browsing'),
479
+ (r'google|search|wiki|wiki|article', 'information'),
480
+ (r'stackoverflow|github|docs|documentation', 'research'),
481
+
482
+ # more rules
483
+ ]
484
+ # activate explainability capability to explain uncertainty:
485
+ main_model.show_explainability_details = True
486
+ main_model.distribution.predict_manager = main_prediction # set PipelinePredictionManager to AgentDistributedInference for asynchronous prediction later (Very important for asynchronous prediction)
487
+ # main_model.use_transformer = True if you want to use transformer, this will notify all modules that used advanced_prediction_method will initiate prediction with both transformer and MLP.
488
+
489
+
490
+ # test samples with more sophisticated rules and more complex titles for prediction
491
+ # (title, intent)
492
+ test_titles = [
493
+ ("Opening Thesis.docx", "slight_work"),
494
+ ("Watching YouTube and Google Chrome", "distracted"),
495
+ ("Watching Slack", "communication"),
496
+ ("Programming in Visual Studio Code", "focused_work"),
497
+ ("Watching netflix.com - Chrome", "break"),
498
+ # more titles
499
+ ]
500
+
501
+ titles, y, label_map = main_prediction.load_labels_from_csv(<your_filename>, <target_title>, <target_label>)
502
+ # small training with simple titles
503
+ main_model.train(titles, y)
504
+
505
+ results, chosen_label, confidence = main_prediction.advanced_prediction_method(test_titles, label_map, example_rules,
506
+ show_proba=False, top_k=3,
507
+ use_transformer=True,
508
+ return_attention=False,
509
+ save_results=True)
510
+
511
+ # ... more features you can add
512
+ ```
513
+
514
+ 5. To use IntegratedPipeline prediction without Transformer, Only Specialized MLP:
515
+ Note: IntegratedPipeline without Transformer is'nt recommended due to it being weak at certain contextual prediction's, excel's at classification task's.
516
+ - Example without transformer:
517
+ ```python
518
+ prediction_result = main_prediction.advanced_prediction_method(
519
+ [t[0] for t in test_titles], # titles is enough for MLP Classification.
520
+ label_map,
521
+ example_rules,
522
+ show_proba=True
523
+ )
524
+
525
+ ```
526
+ 6. Asynchronous prediction:
527
+ - Asynchronous prediction request is important and is critical because it keeps prediction interfaces responsive, maximizes local hardware efficiency, and enables apps to handle background tasks seamlessly without waiting on remote server responses,
528
+ - for asynchronous prediction handling, consider using this setup
529
+ ```python
530
+ # Step 2
531
+ from AbstractIntegratedModule import PipelineAsyncManager
532
+ from AbstractIntegratedModule import SecurityConfig
533
+ from AbstractIntegratedModule import SecurityLevel
534
+
535
+ print(" = TESTING ASYNCHRONOUS PREDICTION MANAGER = ")
536
+ # Set discovery secret (in production, use environment variable)
537
+ secret_key = 'my-ultra-safe-secret-key-for-authentication' # you can customize this key
538
+
539
+
540
+ security_config = SecurityConfig(
541
+ max_text_length=10000, # can be extended
542
+ max_queue_size=100, # can be extended
543
+ rate_limit_requests=60, # 60 per minute
544
+ require_api_key=True, #
545
+ max_pending_tasks=50,
546
+ request_timeout=60.0,
547
+
548
+ # Start with no IP restrictions, you can add allowed IPs for asynchronous prediction externally, boothstrap_auth for better security
549
+ allowed_ips=[],
550
+ blocklisted_ips=[],
551
+ require_bootstrap_auth = False # true for better security (Not recommended, cause less flexibility)
552
+ )
553
+
554
+ async_manager = PipelineAsyncManager(main_model,
555
+ main_prediction, # your previous initialized PipelinePredictionManager
556
+ config=security_config,
557
+ state_file=None, # state file is used to load known security logs ex: ip used, ip blacklisted, etc.
558
+ security_level=SecurityLevel.PRODUCTION, # production level security initiated
559
+ api_key=secret_key #set secret key you initialized
560
+ max_workers=4, # workers to initiate prediction, more workers, more capabilities to process prediction requests.
561
+ task_timeout=30,
562
+ max_retries=3 ) # retries after failure during prediction
563
+
564
+ async_manager.start(method='Transformer_included', bootstrap_token=None) # boothstrap token is optional for better security
565
+
566
+ texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'use_transformer': True}
567
+ regular_predict = async_manager.predict(
568
+ texts=texts,
569
+ timeout=60,
570
+ retries=None,
571
+ api_key=secret_key) # advanced prediction method for asynchronous prediction.
572
+
573
+ # with retries: async_manager.predict(texts, timeout=60, retries=5, api_key=secret_key) # 5 times retry if failed
574
+
575
+ print('[==] Initiating advanced batch prediction')
576
+ predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules, secret_key, client_ip=None) # you can add client_ip to provide a robust authentication paired with secret_key
577
+ # for better and faster advanced prediction, consider using advanced batch prediction like in the above example
578
+
579
+ ```
580
+ [=] Note:
581
+ - Asynchronous prediction used Event loop that handles incoming request, There are conditions where event loop will not start and can't accet requests:
582
+ - CPU Above > 95% - Disk space is < 100 MB
583
+ - RAM above > 95%
584
+ - When event loop is not triggered, Asynchronous prediction can't be initiated and must be restarted/retried.
585
+
586
+ 7. Peer-to-Peer Probability coordination:
587
+ - Each peer is both server and client simultaneously for robustness and resilience during during P2P.
588
+ - To Make the Agent cooperate with other peers, consider using this setup:
589
+ - [=] for ensemble prediction from multiple peers, exchanging predicted label with each other, consider using this setup:
590
+ ```python
591
+ # step 3
592
+ from AbstractIntegratedModule import CohesiveAgentDeployment
593
+ from AbstractIntegratedModule import PipelinePredictionManager
594
+ import asyncio
595
+ import traceback
596
+
597
+ prediction_manager = PipelinePredictionManager(main_model, label_csv=<your_training_labels.txt>, target_title=<target_title>, label=<target_label>)
598
+
599
+ print("=== SECURE PEER-TO-PEER CLUSTER ===")
600
+
601
+ # CohesiveAgentDeployment is deeply tied and coupled with AgentDistributedInference,
602
+ # if you already set an SSL cert and key, CohesiveAgentDeployment will use the SSL directly from AgentDistributedInference
603
+ # allowing secure socket to be used directly by CohesiveAgentDeployment
604
+
605
+ main_model.distribution.enable_ssl = False # set to false if you dont have SSL key and CERT, this code would instruct AgentDistributedInference that you don't have SSL, and provide you a regular unsecured socket (Not necessary for production)
606
+
607
+ # Agent 1 - Primary (Port 5555)
608
+ agent1 = CohesiveAgentDeployment(
609
+ memory_name="agent_primary",
610
+ filename=<filename>,
611
+ target_title=<title_name>,
612
+ label_name=<label_name>,
613
+ security_level="PRODUCTION",
614
+ enable_peers=True,
615
+ trusted_networks=['127.0.0.1/32', '192.168.1.0/24'], # for trusted networks, you need to provide the list of IPs of your peers.
616
+ peer_discovery_port=5555, # peer port to start P2P
617
+ secret_key=secret_key,
618
+ shared_auth_token=secret_key, # your previous initialized secret_key
619
+ predict_manager=prediction_manager,
620
+ peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
621
+ consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
622
+ )
623
+
624
+ # Agent 2 - Secondary (Port 5556)
625
+ agent2 = CohesiveAgentDeployment(
626
+ memory_name="agent_secondary",
627
+ filename=<filename>,
628
+ target_title=<title_name>,
629
+ label_name=<label_name>,
630
+ security_level="PRODUCTION",
631
+ enable_peers=True, # agent is allowed to find peers
632
+ trusted_networks=['127.0.0.1/32', '192.168.1.0/24'],
633
+ peer_discovery_port=5556,
634
+ secret_key=secret_key,
635
+ shared_auth_token=secret_key,
636
+ predict_manager=prediction_manager,
637
+ peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
638
+ consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
639
+ )
640
+
641
+ # Note: CohesiveAgentDeployment contains ConsecutivePeerAgent that can start a server once ensemble prediction from peer is started
642
+ # be advised to stop the server too before shutdown-ing CohesiveAgentDeployment cluster
643
+
644
+ # example peer_Ip_lists_config.json (de-comment to use)
645
+ # {
646
+ # "known_peers": [ # you must put "known_peers" in the config so python can identify the list of IPs and Ports
647
+ # ["127.0.0.1", 5555], can be modified using real IP or local IP.
648
+ # ["127.0.0.1", 5556]
649
+ # ]
650
+ # }
651
+
652
+ agent1.pipeline = main_model # overrides agent1 baseline pipeline with your original initialized pipelinej
653
+ agent2.pipeline = main_model
654
+
655
+ try:
656
+ # Start both agents
657
+ print("\n🚀 Starting Agent 1...")
658
+ await agent1.start()
659
+ print("✅ Agent 1 started on port 5555")
660
+
661
+ print("\n🚀 Starting Agent 2...")
662
+ await agent2.start()
663
+ print("✅ Agent 2 started on port 5556")
664
+
665
+ # Give servers time to fully bind
666
+ await asyncio.sleep(2)
667
+
668
+ # Get API keys
669
+ api_key = agent1.get_api_key()
670
+ print(f"\n🔑 Using API Key: {api_key[:20]}...")
671
+
672
+ texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
673
+
674
+ # texts contains test_titles, label_map, and rules that you can assign,
675
+ # agent ID can be strings, int, or floats, recommendeded to make it long for better security.
676
+
677
+ # Make prediction with peer ensemble
678
+ # Connection will be guaranteed successfull during discovery.
679
+ result = await agent1.multi_modal_peer_ensemble_prediction(
680
+ texts=texts,
681
+ api_key=api_key,
682
+ method='advanced',
683
+ disable_sync=True
684
+ ) # await using asyncio, multi_modal_peer_ensemble is already async by design (Inside ConsecutivePeerAgent), no need to put asyncio.run()
685
+
686
+ result2 = await agent2.multi_modal_peer_ensemble_prediction(
687
+ texts=texts,
688
+ api_key=api_key,
689
+ method='advanced',
690
+ disable_sync=True
691
+ )
692
+
693
+ print(f"\n📊 Ensemble Result for Agent 1:")
694
+ print(f" Prediction: {result.get('prediction', 'N/A')}")
695
+ print(f" Confidence: {result.get('confidence', 0):.2%}")
696
+
697
+ print(f"\n📊 Ensemble Result for Agent 2:")
698
+ print(f" Prediction: {result2.get('prediction', 'N/A')}")
699
+ print(f" Confidence: {result2.get('confidence', 0):.2%}")
700
+
701
+ # Keep running briefly
702
+ print("\n⏳ Cluster stable. Waiting 5 seconds before shutdown...") # 5 seconds before shutdown.
703
+
704
+ # stop ConsecutivePeerAgent servers inside CohesiveAgentDeployment.
705
+ agent1._peer_agent.stop_server() # ._peer_agent is ConsecutivePeerAgent
706
+ agent2._peer_agent.stop_server()
707
+
708
+ await asyncio.sleep(5)
709
+
710
+ except Exception as e:
711
+ print(f"\n❌ Error in cluster: {e}")
712
+ traceback.print_exc()
713
+
714
+ finally:
715
+ print("\n🛑 Shutting down cluster...")
716
+ await agent1.shutdown()
717
+ await agent2.shutdown()
718
+ print("✅ Cluster shutdown complete")
719
+
720
+ ```
721
+ [=] Important Note:
722
+ - This setup outputs the given predicted label of an input directly, making P2P more flexible and fast.
723
+ - This setup used Hybrid feature in prediction handling, Asynchronous prediction request, and Synchronous prediction handling. Synchronous prediction does block code execution for a few seconds, it was used for a few reason here, such as:
724
+ - allowing a more slower traffic between agents, preventing other agent to get the same peer prediction over time, making each interaction equals and each peer can receive different peer prediction output.
725
+
726
+ [=] You can download this setup here for a direct test: [P2PDirectTest.py](P2PDirectTest.py)
727
+
728
+ - [=] for probability coordination, locally, get peers data from database or via socket.
729
+ ```python
730
+ # step 4
731
+ dataset, _ = main_model.data_preparation(test_titles, label_map)
732
+ sequence_inputs = main_model.sequence_encoding(dataset)
733
+ X_raw_generation, y, n_classes, input_dim = main_model.mlp_training_features(example_rules, dataset)
734
+
735
+ main_model.initialize_fitting(dataset)
736
+ X_raw_features = main_model.tfidf.transform(X_raw_generation).toarray()
737
+ transformer_features = main_model.transformer_pooled_features(sequence_inputs)
738
+ X_features = np.concatenate([X_raw_features, transformer_features], axis=-1)
739
+
740
+ peer_probability_calibration = main_model.predict_proba(sequence_inputs, X_features, type='Hybrid', embedded=True) # peer-to-peer calibration is inside this function
741
+ ```
742
+ [~] Note: the peer calibration coordination has a chance of triggering if both MLP and Transformer prediction doesn't agree on certain output. Consider using this setup below for using stand-alone peer-to-peer main function without being wrapped in other parent function, allowing flexible and auditable peer-to-peer sharing for probability coordination:
743
+ ```python
744
+ from AbstractIntegratedModule import WeightedEnsemblePredictor
745
+ from AbstractIntegratedModule import Transformer
746
+
747
+ num_classes = len(label_map)
748
+ # if you haven't fit the Tfidf:
749
+ # main_model.initialize_fitting(dataset)
750
+
751
+ ensemble_method = WeightedEnsemblePredictor(main_model, memory_name) # consider using the same memory name used in your previous pipeline
752
+ transformer = Transformer(main_model.vocab_size, d_model=32, n_heads=4, num_classes=num_classes) # you can audit how much parameter the transformer needs.
753
+ main_model.model2 = transformer # overwrite previous transformer initialization
754
+
755
+ # main_model.distribution is AgentDistributedInference() class
756
+ # consider using ssl for secure peer to peer coordination
757
+ main_model.distribution.ssl_cert_file = <path_to_your_ssl_cert_file>
758
+ main_model.distribution.ssl_key_file = <path_to_your_ssl_key_file>
759
+
760
+ dataset, _ = main_model.data_preparation(titles, label_map)
761
+ sequence_input = main_model.sequence_encoding(dataset)
762
+ _, attn_weights = transformer.forward(sequence_input)
763
+
764
+ probs = ensemble_method.predict_ensemble(sequence_input, X_features, y, method='dynamic', embedded=True)
765
+ # 3 options for ensemble weighting method:
766
+ # 1. dynamic: allow flexible, efficient weighting from both transformer and MLP,
767
+ # 2. meta: for a much more in-depth weighting from both model,
768
+ # 3. calibration: allow calibrating probability for both model outputs based on both best weights assembling.
769
+
770
+ agreement = main_model.agreement
771
+
772
+ # start server to initiate socket for P2P listener
773
+ main_model.distribution.start_server()
774
+
775
+ # set connection timeout (Optional)
776
+ main_model.distribution.connection_timeout = 30 # 30 seconds before timeout
777
+ calibrated_probability = main_model._handle_distributed_connections(probs, attn_weights, sequence_input, agreement)
778
+
779
+ # if an Agent experience a failure on tasks, consider using this function to reduce peer trust for safer flexible coordination:
780
+ # main_model.distribution.report_failure(id(main_model), '<task_name>', reason='<unknown>') # you can add the task_name and reason
781
+ # main_model.distribution.print_network_status() # to show other peers info.
782
+ ```
783
+ [~] Note: this calibrated_probability is later used to calculate confidence and chosen output based on given label_map.
784
+ - Consider checking:
785
+ - [multi_agent_client.py](multi_agent_client.py) for a In-depth start for client testing.
786
+ - [multi_agent_server.py](multi_agent_server.py) for a In-depth start for server testing.
787
+ - If you get undefined NoneType Behavior when using .accept(), consider see [Troubleshooting](#Troubleshooting) Issue 7 for a Quick fix.
788
+
789
+ 6. Cross-Session availability:
790
+ - To use Cross-session avialability to transfer or import memory, consider using this setup:
791
+ - ```python
792
+ main_model._cross_session_availability() # cross session capability function
793
+ ```
794
+
795
+ 7. As an option, You can add more feature's directly to what it should predict, behave using rules you have given, Create a visual dashboard, create a distributed mesh of this agent, and much more features you can try.
796
+
797
+ ## [+] Troubleshooting
798
+ 1. Issue 1: "ModuleNotFoundError: No module named 'AbstractIntegratedModule'" When using the binary version of the library,
799
+ Solution:
800
+
801
+ - [=] Verify the binary file is in the correct location:
802
+ ```
803
+ ls -la AbstractIntegratedModule*.so # Linux
804
+ dir AbstractIntegratedModule.pyd # Windows
805
+ ```
806
+
807
+
808
+ - [=] Check Python path:
809
+ ```
810
+ python -c "import sys; print('\n'.join(sys.path))"
811
+ ```
812
+ - [~] Note: - Move binary to project root if not already there
813
+ - Ensure you're using Python 3.13 of the supported version.
814
+
815
+ 2. Issue 2: "ImportError: DLL load failed" when using binary version of the library (For Windows)
816
+ Solution:
817
+
818
+ - 1. Ensure AbstractIntegratedModule.pyd is in your project root
819
+ - 2. Install Visual C++ redistributables:
820
+ Download from: https://support.microsoft.com/en-us/help/2977003
821
+ - 3. Verify Python architecture (32-bit vs 64-bit) matches the .pyd file
822
+
823
+
824
+ 3. Issue 3: "Permission denied" when using binary version of the library (for Linux/Raspberry Pi)
825
+ [=] Solution:
826
+ - ```
827
+ # Make sure you have read permissions
828
+ chmod 644 AbstractIntegratedModule.cpython-39-*.so
829
+ # If in virtual environment, ensure it's activated
830
+ source venv/bin/activate
831
+ ```
832
+
833
+ 4. Issue 4: Missing Dependencies when using binary
834
+ [=] Solution:
835
+ - ```
836
+ # Reinstall all dependencies
837
+ pip install --upgrade pip setuptools wheel
838
+ pip install numpy pandas scikit-learn matplotlib scipy requests
839
+
840
+ # Verify installation
841
+ pip list
842
+ ```
843
+
844
+ 5. Issue 5: Virtual Environment Issues
845
+ [=] Solution:
846
+ - ```
847
+ # Deactivate current environment
848
+ deactivate
849
+
850
+ # Create a fresh virtual environment
851
+ python -m venv fresh_venv
852
+
853
+ # Activate it
854
+ source fresh_venv/bin/activate # Linux/Raspberry Pi
855
+ # or
856
+ fresh_venv\Scripts\activate # Windows
857
+
858
+ # Reinstall
859
+ pip install --upgrade pip
860
+ pip install numpy pandas scikit-learn matplotlib scipy
861
+ ```
862
+
863
+ 6. Issue 6: Raspberry Pi - "Bus error" or Performance Issues
864
+ Solution:
865
+ - [=] Ensure adequate swap space:
866
+ ```
867
+ free -h # Check current swap
868
+ sudo nano /etc/dphys-swapfile # Increase if needed
869
+ ```
870
+ - Close unnecessary applications before running
871
+ - Consider using a faster SD card (UHS-I or better)
872
+
873
+ 7. Issue 7: P2P Undefined Connection:
874
+ If you get this warning:
875
+ - ```
876
+ [❌] Failed to connect to <host>:<port>: Nonetype object has no attribute .accept()
877
+ ```
878
+ - [=] Solution:
879
+ - ```
880
+ # initiate socket first
881
+ main_model.distribution.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
882
+ main_model.distribution.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
883
+ main_model.distribution.socket.bind(('0.0.0.0', self.port)) # self.port could be changed with other ports
884
+ main_model.distribution.socket.listen(5) # listens for 5 seconds
885
+ ```
886
+ 8. Issue 8: Cannot compare using '<' with str and float data:
887
+ - This happens when one of the labels extracted from your CSV file has NaN value, consider replace NaN with actual labels.
888
+
889
+ 9. Issue 9: Failed authentication during asynchronous prediction:
890
+ - Solution: Ensure API_KEY is initialized inside PipelineAsyncManager like this:
891
+ - ```python
892
+ async_manager = PipelineAsyncManager(main_model,
893
+ main_prediction, # your previous initialized PipelinePredictionManager
894
+ config=security_config,
895
+ state_file=None, # state file is used to load known security logs ex: ip used, ip blacklisted, etc.
896
+ security_level=SecurityLevel.PRODUCTION, # production level security initiated
897
+ api_key=secret_key # set secret key you initialized <- THIS IS IMPORTANT
898
+ max_workers=4, # workers to initiate prediction, more workers, more capabilities to process prediction requests.
899
+ task_timeout=30,
900
+ max_retries=3 ) # retries after failure during prediction
901
+ ```
902
+ - And make sure you also initialized api_key in the predict function that requires api_key:
903
+ ```
904
+ async_manager.predict(...., ...., api_key=api_key, ...)
905
+ ```
906
+
907
+ ## [=] Detailed process of Alpha-computing
908
+
909
+ <img width="720" height="338" alt="WhatsApp Image 2026-05-04 at 17 43 35" src="https://github.com/user-attachments/assets/3d149dce-cf3b-44c9-80b0-fa68290a2019" />
910
+
911
+ <img width="720" height="388" alt="WhatsApp Image 2026-05-04 at 17 44 04" src="https://github.com/user-attachments/assets/b1efedf6-5aa1-431e-89da-5f422549b453" />
912
+ 🧠 What Alpha-Based Computation Actually Does
913
+
914
+ At its core, alpha (α) is a control parameter that blends two different information paths inside a given transformer:
915
+ A_final = α · A_fixed + (1 α) · A_learned.
916
+ [~] Where:
917
+ - A_fixed stable, non-trainable (or minimally changing) attention
918
+ - A_learned → dynamic, trainable attention (Q, K, V)
919
+ - α ∈ [0, 1] → controls how much each path contributes
920
+
921
+ [~] Forward Pass -> Controlling Information Flow:
922
+ During the forward pass, alpha determines what representation the model uses.
923
+ If α is high (e.g., 0.8–1.0): Model relies mostly on stable attention
924
+ → outputs are consistent → less noise → safer early training, If α is low (e.g., 0.0–0.3), Model relies mostly on learned attention, → more expressive → but unstable early on.
925
+ So in forward propagation, alpha is essentially, “How much do I trust learned attention vs safe attention?”
926
+
927
+ [~] Backward Pass -> Controlling Gradient Flow:
928
+ When gradients flow backward:
929
+ ```
930
+ - dA_final → splits into two paths
931
+ - Mathematically:
932
+ - dA_fixed = α · dA_final
933
+ - dA_learned = (1 − α) · dA_final
934
+ ```
935
+
936
+ [~] Simple Explanation:
937
+ 1. If α (alpha) is high: → most gradient goes to fixed path → learned attention gets very little update → training is stable but slow
938
+ 2. If α is low: most gradient goes to learned attention fast learning but noisy / unstable
939
+
940
+ [=] Why This Matters for Training
941
+ 1. Without alpha: attention starts random gradients noisy model stuck (~10% accuracy)
942
+ 2. With alpha: early stage -> rely on stable structure → meaningful gradients
943
+
944
+
945
+
946
+ ## Main Components
947
+ [=] 1. - Consider checking and run: [IntegratedPipeline_Flow.html](IntegratedPipeline_Flow.html) regarding each function of the whole components and deep-dive mechanism.
948
+ 2. - consider checking [ARCHITECTURE.md](ARCHITECTURE.md) for more explanation about the main components.
949
+
950
+ [=] With 20 total architectures working together as a standalone library that is efficient and robust, Main components include:
951
+
952
+ 1. GeometricWeightShaping
953
+ Purpose: Analyzes the geometric structure of data (anisotropy, spectral properties, complexity) and generates optimal weight matrices based on that geometry. Essentially teaches the model how to "understand" the shape of data before processing it, Highly robust to noise, making it an excellent fit for messy environment.
954
+ ---
955
+ 2. Activation
956
+ Purpose: Provides standard neural network activation functions (ReLU, sigmoid, softmax) and their derivatives for backpropagation for MLP Class.
957
+ ---
958
+ 3. Loss
959
+ Purpose: Implements categorical crossentropy loss and its gradient for training classification models for both MLP and The Transformer
960
+ ---
961
+ 4. Transformer
962
+ Purpose: A complete transformer implementation with multi-head attention, positional embeddings, feed-forward networks, layer normalization, and custom backpropagation. Includes both fixed (stable) and dynamic (adaptive) training modes necessary for Scarce data environment using algorithm such as Alpha based computing directly during forward pass.
963
+ ---
964
+ 5. Dense
965
+ Purpose: A geometric-aware dense layer that adapts its weights based on input data geometry and handles variable input dimensions automatically.
966
+ ---
967
+ 6. SoftmaxOutput
968
+ Purpose: A simple wrapper around softmax activation that stores the output and passes gradients through unchanged (since softmax + crossentropy gradient is handled elsewhere).
969
+ ---
970
+ 7. MLP
971
+ Purpose: A multi-layer perceptron that can switch between standard training and "focused" training (using feed-forward layers only) based on data complexity. Includes prediction, scoring, and geometric measurement methods.
972
+ ---
973
+ 8. WeightedEnsemblePredictor
974
+ Purpose: Combines Transformer and MLP predictions using dynamic weighting based on attention quality, model confidence, and agreement. Also manages memory storage, explainability, and peer agent communication.
975
+ ---
976
+ 9. CrossSessionAutomation
977
+ Purpose: Manages exporting, importing, and syncing model sessions across different devices or time periods. Allows saving entire model states to JSON and transferring them over network sockets.
978
+ ---
979
+ 10. ExplainabilityModule
980
+ Purpose: Generates human-readable explanations for predictions, learns from user feedback, maintains decision history, and batch-trains on corrections. The transparency layer for the AI agent.
981
+ ---
982
+ 11. ModelStorage
983
+ Purpose: SQLite-based persistence for models, attention weights, node memories, and agent data. Handles serialization/deserialization of numpy arrays and model dictionaries.
984
+ ---
985
+ 12. AgentDistributedInference
986
+ Purpose: The distributed agent system - can act as a server or client, handles SSL/TLS security, rate limiting, authentication, peer-to-peer prediction requests, memory synchronization, ensemble voting, and trust management between agents.
987
+ ---
988
+ 14. QueryNode
989
+ Purpose: Manages trust relationships and identity verification between nodes. Evaluates node agreement, establishes connections, performs safety checks, and maintains the network of trusted peers.
990
+ ---
991
+ 14. AutoBatcherAutomation
992
+ Purpose: Automatically batches incoming prediction requests to optimize throughput. Collects requests up to a maximum batch size or time window, then processes them together.
993
+ ---
994
+ 15. IntegratedPipeline
995
+ Purpose: The main orchestration class that ties everything together - handles text encoding, model initialization, training, prediction, memory management, hybrid predictions, and distributed inference coordination.
996
+ ---
997
+ 16. PipelinePredictionManager
998
+ Purpose: High-level prediction interface that loads labels from CSV, performs regular/advanced/hybrid predictions, displays results, and calculates entropy for uncertainty estimation.
999
+ ---
1000
+ 17. ThreadedMessageQueue
1001
+ purpose: Handles message queue in thread for asynchronous message handling. (Queue based)
1002
+ ---
1003
+ 18. AsyncMessageQueue
1004
+ purpose: Handles incoming message from Asychronous peer request (Queue based)
1005
+ ---
1006
+ 19. CohesiveAgentDeployment
1007
+ purpose: Handles both synchronous prediction, and P2P Asynchronous prediction request, acts as a server and a listener simultaneously.
1008
+ ---
1009
+ 20. ConsecutivePeerAgent
1010
+ purpose: handles ensemble weighting from received output from peer, managed server and acts as a listener simultaneously.
1011
+
1012
+
1013
+ ## Full Documentation Features
1014
+ - [Go to IntegratedPipeline-Specialized-AI-Agent-library](#IntegratedPipeline-Specialized-AI-Agent-library)
1015
+ - [Go to MANN Intro](#MANN-Intro)
1016
+ - [Go to Abstract Weight Encoder (AWE) Intro](#Abstract-Weight-Encoder-(AWE)-Intro)
1017
+ - [Go to Why IntegratedPipeline?](#Why-IntegratedPipeline?)
1018
+ - [Go to Requirements](#Requirements)
1019
+ - [Go to System-Specific-Notes](#System-Specific-Notes)
1020
+ - [Go to Quickstart with Docker](#Quickstart-with-Docker)
1021
+ - [Go to Performance in ARM64 Environment/Container](#Performance-in-ARM64-Environment/Container)
1022
+ - [Go to Step's for in-depth Usage](#Step's-for-in-depth-Usage)
1023
+ - [Go to Troubleshooting](#Troubleshooting)
1024
+ - [Go to Detailed process of Alpha-computing](#Detailed-process-of-Alpha-computing)
1025
+ - [Go to Main Components](#Components)
1026
+ - [Go to Source code](#Source-code-of-AbstractIntegratedModule)
1027
+ - Consider checking:
1028
+ - [ROADMAP.md](ROADMAP.md)
1029
+ - [Contributing.md](Contributing.md)
1030
+ - [changelog.md](changelog.md)
1031
+ - [requirements-dev.txt](requirements-dev.txt) for contributors requirements.
1032
+ - [architecture_diagram.js](architecture_diagram.js).
1033
+
1034
+ ## License
1035
+ [=] LICENSE: - MIT (2026) || See [LICENSE](LICENSE) for more information.
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+