AbstractIntegratedModule 0.2.2__tar.gz → 0.2.4__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.
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.egg-info/PKG-INFO +47 -29
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.py +136 -90
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/PKG-INFO +47 -29
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/README.md +46 -28
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/setup.py +1 -1
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/pyproject.toml +0 -0
- {abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Framework forAdvanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework
|
|
5
5
|
Author: Micro-Novelty
|
|
6
6
|
Author-email: hernikpuspita5@gmail.com
|
|
@@ -40,11 +40,12 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
40
40
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
41
41
|
|
|
42
42
|
### Library Short Description:
|
|
43
|
-
- Development Stage: Beta, 0.2.
|
|
43
|
+
- Development Stage: Beta, 0.2.4.
|
|
44
44
|
- Maintainer: Micro-Novelty.
|
|
45
45
|
- library Source-Code is Open-sourced on github.
|
|
46
46
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
|
47
|
-
|
|
47
|
+
- Proven Capabilities: Works on ARM64 Environment, Training and Prediction works efficient on Docker ARM64 environment with QEMU, good parallelizing behavior is guaranteed.
|
|
48
|
+
-----
|
|
48
49
|
|
|
49
50
|
<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" />
|
|
50
51
|
|
|
@@ -482,11 +483,21 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
482
483
|
import numpy as np
|
|
483
484
|
|
|
484
485
|
memory_name = 'agent_memory'
|
|
485
|
-
main_model = IntegratedPipeline(
|
|
486
|
-
|
|
487
|
-
|
|
486
|
+
main_model = IntegratedPipeline(
|
|
487
|
+
memory_name=memory_name, # memory name for the AI you already initialized
|
|
488
|
+
use_async=True, # local asynchronous prediction is permitted, if not PipelineAsyncManager wont start asynchronous prediction.
|
|
489
|
+
agent_port=5001, # this port is used to set AgentDistributedInference server (optional)
|
|
490
|
+
singleton_permitted=False, # set IntegratedPipeline to singleton if you don't use it for P2P, False if you use P2P.
|
|
491
|
+
ssl_cert_file=cert_file, ssl_key_file=key_file) # provide your cert_file path or key_file path (optional)
|
|
492
|
+
|
|
493
|
+
main_prediction = PipelinePredictionManager(
|
|
494
|
+
main_model, # your initialized pipeline
|
|
495
|
+
label_csv='example_manual_training.txt', # your .txt file that contains CSV format.
|
|
496
|
+
target_title='window_title', label='label')
|
|
488
497
|
|
|
498
|
+
# example_manual_training is a .txt file that contain csv format like above example.
|
|
489
499
|
|
|
500
|
+
# rules will be used to create automatic dataset for IntegratedPipeline.
|
|
490
501
|
example_rules = [
|
|
491
502
|
# === WORK / PRODUCTIVITY ===
|
|
492
503
|
(r'code|programming|develop|debug|compile|script', 'focused_work'),
|
|
@@ -508,6 +519,7 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
508
519
|
|
|
509
520
|
# more rules
|
|
510
521
|
]
|
|
522
|
+
|
|
511
523
|
# activate explainability capability to explain uncertainty:
|
|
512
524
|
main_model.show_explainability_details = True
|
|
513
525
|
main_model.distribution.predict_manager = main_prediction # set PipelinePredictionManager to AgentDistributedInference for asynchronous prediction later (Very important for asynchronous prediction)
|
|
@@ -525,16 +537,20 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
525
537
|
# more titles
|
|
526
538
|
]
|
|
527
539
|
|
|
528
|
-
titles, y, label_map = main_prediction.load_labels_from_csv(
|
|
529
|
-
|
|
540
|
+
titles, y, label_map = main_prediction.load_labels_from_csv(
|
|
541
|
+
<your_filename.>, # the name of your .txt file with CSV format.
|
|
542
|
+
<target_title>, <target_label>)
|
|
543
|
+
|
|
544
|
+
# small training with simple titles first
|
|
530
545
|
main_model.train(titles, y)
|
|
531
546
|
|
|
532
|
-
results, chosen_label, confidence = main_prediction.advanced_prediction_method(
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
547
|
+
results, chosen_label, confidence = main_prediction.advanced_prediction_method(
|
|
548
|
+
test_titles, label_map, example_rules,
|
|
549
|
+
show_proba=False, top_k=3,
|
|
550
|
+
use_transformer=True,
|
|
551
|
+
return_attention=False,
|
|
552
|
+
save_results=True,
|
|
553
|
+
batch_size=2)
|
|
538
554
|
# batch size=2 is needed during transformer training for batching, if you have larger samples consider using batch_size > 8, for medium amount of samples (>10 -> <50 samples) consider using 2 or 4 batch_size.
|
|
539
555
|
# ... more features you can add
|
|
540
556
|
```
|
|
@@ -585,7 +601,7 @@ async_manager = PipelineAsyncManager(main_model,
|
|
|
585
601
|
state_file=None, # state file is used to load known security logs ex: ip used, ip blacklisted, etc.
|
|
586
602
|
security_level=SecurityLevel.PRODUCTION, # production level security initiated
|
|
587
603
|
api_key=secret_key #set secret key you initialized
|
|
588
|
-
max_workers=4, # workers to initiate
|
|
604
|
+
max_workers=4, # workers to initiate asynchronous tasks, more workers, more capabilities to process asynchronous prediction requests.
|
|
589
605
|
task_timeout=30,
|
|
590
606
|
max_retries=3 ) # retries after failure during prediction
|
|
591
607
|
|
|
@@ -616,6 +632,7 @@ predicted_output = async_manager.advanced_batch_prediction(test_titles, label_ma
|
|
|
616
632
|
- To Make the Agent cooperate with other peers, consider using this setup:
|
|
617
633
|
- [=] for ensemble prediction from multiple peers, exchanging predicted label with each other, consider using this setup:
|
|
618
634
|
```python
|
|
635
|
+
|
|
619
636
|
# step 3
|
|
620
637
|
from AbstractIntegratedModule import CohesiveAgentDeployment
|
|
621
638
|
from AbstractIntegratedModule import PipelinePredictionManager
|
|
@@ -634,23 +651,25 @@ main_model.distribution.enable_ssl = False # set to false if you dont have SSL k
|
|
|
634
651
|
|
|
635
652
|
# Agent 1 - Primary (Port 5555)
|
|
636
653
|
agent1 = CohesiveAgentDeployment(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
654
|
+
pipeline=main_model, # main_model is your initialized integrated pipeline
|
|
655
|
+
memory_name="agent_primary", # any name you want for the agent.
|
|
656
|
+
filename=<filename>, # name of your .txt file that contains the CSV format and training labels
|
|
657
|
+
target_title=<title_name>,
|
|
640
658
|
label_name=<label_name>,
|
|
641
|
-
security_level="PRODUCTION",
|
|
642
|
-
enable_peers=True,
|
|
659
|
+
security_level="PRODUCTION", # production level security
|
|
660
|
+
enable_peers=True, # allow peer discovery
|
|
643
661
|
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.
|
|
644
662
|
peer_discovery_port=5555, # peer port to start P2P
|
|
645
|
-
secret_key=secret_key,
|
|
663
|
+
secret_key=secret_key, # your secret key
|
|
646
664
|
shared_auth_token=secret_key, # your previous initialized secret_key
|
|
647
|
-
predict_manager=prediction_manager,
|
|
665
|
+
predict_manager=prediction_manager, # your prediction manager
|
|
648
666
|
peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
|
|
649
667
|
consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
|
|
650
|
-
|
|
668
|
+
)
|
|
651
669
|
|
|
652
670
|
# Agent 2 - Secondary (Port 5556)
|
|
653
671
|
agent2 = CohesiveAgentDeployment(
|
|
672
|
+
pipeline=main_model,
|
|
654
673
|
memory_name="agent_secondary",
|
|
655
674
|
filename=<filename>,
|
|
656
675
|
target_title=<title_name>,
|
|
@@ -664,21 +683,20 @@ agent2 = CohesiveAgentDeployment(
|
|
|
664
683
|
predict_manager=prediction_manager,
|
|
665
684
|
peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
|
|
666
685
|
consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
|
|
667
|
-
|
|
686
|
+
)
|
|
668
687
|
|
|
669
688
|
# Note: CohesiveAgentDeployment contains ConsecutivePeerAgent that can start a server once ensemble prediction from peer is started
|
|
670
689
|
# be advised to stop the server too before shutdown-ing CohesiveAgentDeployment cluster
|
|
671
690
|
|
|
672
691
|
# example peer_Ip_lists_config.json (de-comment to use)
|
|
673
692
|
# {
|
|
674
|
-
#
|
|
693
|
+
# you must put "known_peers" in the config so python can identify the list of IPs and Ports
|
|
694
|
+
# "known_peers": [
|
|
675
695
|
# ["127.0.0.1", 5555], can be modified using real IP or local IP.
|
|
676
696
|
# ["127.0.0.1", 5556]
|
|
677
697
|
# ]
|
|
678
698
|
# }
|
|
679
699
|
|
|
680
|
-
agent1.pipeline = main_model # overrides agent1 baseline pipeline with your original initialized pipelinej
|
|
681
|
-
agent2.pipeline = main_model
|
|
682
700
|
|
|
683
701
|
try:
|
|
684
702
|
# Start both agents
|
|
@@ -699,8 +717,8 @@ try:
|
|
|
699
717
|
|
|
700
718
|
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
701
719
|
|
|
702
|
-
# texts
|
|
703
|
-
# agent ID can be strings, int, or floats,
|
|
720
|
+
# texts dictionary must contain test_titles, label_map, and rules that you can assign,
|
|
721
|
+
# agent ID can be strings, int, or floats, recommendded to make it long for better security.
|
|
704
722
|
|
|
705
723
|
# Make prediction with peer ensemble
|
|
706
724
|
# Connection will be guaranteed successfull during discovery.
|
{abstractintegratedmodule-0.2.2 → abstractintegratedmodule-0.2.4}/AbstractIntegratedModule.py
RENAMED
|
@@ -2290,18 +2290,25 @@ class ExplainabilityModule:
|
|
|
2290
2290
|
if isinstance(mlp_conf, np.ndarray):
|
|
2291
2291
|
mlp_conf = np.clip(np.mean(mlp_conf), 0, 1)
|
|
2292
2292
|
if isinstance(trans_conf, np.ndarray):
|
|
2293
|
-
|
|
2293
|
+
trans_conf = np.clip(np.mean(trans_conf), 0, 1)
|
|
2294
2294
|
|
|
2295
2295
|
if mlp_pred == trans_pred:
|
|
2296
2296
|
final_pred = mlp_pred
|
|
2297
2297
|
final_conf = max(mlp_conf, trans_conf)
|
|
2298
2298
|
else:
|
|
2299
|
-
|
|
2300
|
-
|
|
2299
|
+
sliced_attention_weight = attn_weights[0]
|
|
2300
|
+
if isinstance(sliced_attention_weight, np.ndarray):
|
|
2301
|
+
sliced_attention_weight = sliced_attention_weight[:, 0]
|
|
2302
|
+
sliced_attention_weight = sliced_attention_weight[0]
|
|
2303
|
+
|
|
2304
|
+
sliced_anisotropy = self.pipeline.anisotropy_measurement(sliced_attention_weight)
|
|
2305
|
+
sigmoid_growth = 1.0 / (1.0 + np.exp(-sliced_attention_weight))
|
|
2301
2306
|
attn_quality = self._compute_attention_quality(attn_weights)
|
|
2302
2307
|
|
|
2303
|
-
#
|
|
2304
|
-
AAT =
|
|
2308
|
+
# Abstract attention transformation
|
|
2309
|
+
AAT = sigmoid_growth * (1.0 - sliced_anisotropy) + eps
|
|
2310
|
+
# lower AAT means transformer is less reliable because abstraction is underserved/nonoptimal in this env.
|
|
2311
|
+
# Higher AAT means transformer is more focused and reliable and is near optimal.
|
|
2305
2312
|
|
|
2306
2313
|
if mlp_conf > trans_conf:
|
|
2307
2314
|
final_pred = mlp_pred
|
|
@@ -2310,6 +2317,15 @@ class ExplainabilityModule:
|
|
|
2310
2317
|
final_pred = trans_pred
|
|
2311
2318
|
final_conf = trans_conf * (1.0 - mlp_conf) * AAT + eps
|
|
2312
2319
|
|
|
2320
|
+
print(f'[= ABSTRACTION =] Consistency of abstraction transformation: {np.std(AAT)}')
|
|
2321
|
+
if isinstance(final_conf, np.ndarray):
|
|
2322
|
+
final_conf = 1.0 / (1.0 + np.std(final_conf))
|
|
2323
|
+
# growth deviation of arrayed final confidence helped to distinguish noise from unnecessary distribution,
|
|
2324
|
+
# with real covariance of distribution from the data.
|
|
2325
|
+
|
|
2326
|
+
if np.isnan(final_conf).any() or np.isinf(final_conf).any():
|
|
2327
|
+
final_conf = self.pipeline.confidence_threshold
|
|
2328
|
+
|
|
2313
2329
|
return final_pred, final_conf
|
|
2314
2330
|
|
|
2315
2331
|
def _get_attention_focus(self, attn_weights, text):
|
|
@@ -3875,26 +3891,6 @@ class ThreadedMessageQueue:
|
|
|
3875
3891
|
# while also providing security features like authentication, rate limiting, and message validation.
|
|
3876
3892
|
class AgentDistributedInference:
|
|
3877
3893
|
def __init__(self, pipeline, storage, memory_name, port=5555, use_async=False, secret_key=None, ssl_cert_file=None, ssl_key_file=None, shared_auth_token=None, predict_manager=None):
|
|
3878
|
-
super().__init__()
|
|
3879
|
-
|
|
3880
|
-
# Only initialized once
|
|
3881
|
-
if hasattr(self, '_singleton_initialized'):
|
|
3882
|
-
print(f"[===] AgentDistributedInference already initialized, reusing...")
|
|
3883
|
-
return
|
|
3884
|
-
|
|
3885
|
-
self._singleton_initialized = True
|
|
3886
|
-
|
|
3887
|
-
# Stored initialization params for debugging later
|
|
3888
|
-
self._init_params = {
|
|
3889
|
-
'memory_name': memory_name,
|
|
3890
|
-
'port': port,
|
|
3891
|
-
'use_async': use_async,
|
|
3892
|
-
'secret_key': secret_key,
|
|
3893
|
-
'ssl_cert_file': ssl_cert_file,
|
|
3894
|
-
'ssl_key_file': ssl_key_file,
|
|
3895
|
-
'shared_auth_token': shared_auth_token
|
|
3896
|
-
}
|
|
3897
|
-
|
|
3898
3894
|
self.pipeline = pipeline
|
|
3899
3895
|
self.memory_name = memory_name
|
|
3900
3896
|
self.port = port
|
|
@@ -5240,7 +5236,9 @@ class AgentDistributedInference:
|
|
|
5240
5236
|
|
|
5241
5237
|
|
|
5242
5238
|
def _calibrate_peer_probs(self, probs, target_preds, self_attn_weights, attn_weights, input_ids, AEL):
|
|
5239
|
+
eps = 1e-5
|
|
5243
5240
|
calibrated = probs.copy()
|
|
5241
|
+
|
|
5244
5242
|
try:
|
|
5245
5243
|
n_classes = probs.shape[1]
|
|
5246
5244
|
except:
|
|
@@ -5248,11 +5246,25 @@ class AgentDistributedInference:
|
|
|
5248
5246
|
|
|
5249
5247
|
batch_size = len(target_preds)
|
|
5250
5248
|
anisotropy = self.pipeline.anisotropy_measurement(attn_weights)
|
|
5251
|
-
|
|
5252
|
-
|
|
5249
|
+
|
|
5250
|
+
if isinstance(attn_weights, (str, np.str_)):
|
|
5251
|
+
clean_str = str(attn_weights).replace('[', '').replace(']', '')
|
|
5252
|
+
attn_weights = np.fromstring(clean_str, sep=' ')
|
|
5253
|
+
elif isinstance(attn_weights, np.ndarray) and np.issubdtype(attn_weights.dtype, np.character):
|
|
5254
|
+
# catches arrays filled with string text
|
|
5255
|
+
clean_str = ' '.join(attn_weights.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
5256
|
+
attn_weights = np.fromstring(clean_str, sep=' ')
|
|
5257
|
+
else:
|
|
5258
|
+
# Ensure standard float array if it was integers or objects
|
|
5259
|
+
attn_weights = np.asarray(attn_weights, dtype=float)
|
|
5260
|
+
|
|
5261
|
+
target_preds = np.asarray(target_preds, dtype=np.float32)
|
|
5262
|
+
|
|
5253
5263
|
for i in range(batch_size):
|
|
5254
|
-
|
|
5255
|
-
|
|
5264
|
+
|
|
5265
|
+
mlp_target = target_preds[i] if target_preds.ndim > 1 and target_preds.shape[0] > i else target_preds
|
|
5266
|
+
attn_target = attn_weights[i] if attn_weights.ndim > 1 and attn_weights.shape[0] > i else attn_weights
|
|
5267
|
+
|
|
5256
5268
|
if self_attn_weights is not None and i < len(attn_weights):
|
|
5257
5269
|
attn = self_attn_weights[i]
|
|
5258
5270
|
|
|
@@ -5299,7 +5311,21 @@ class AgentDistributedInference:
|
|
|
5299
5311
|
def handle_peer_uncertainty(self, probs, target_preds, self_attn_weights, attn_weights, input_ids):
|
|
5300
5312
|
try:
|
|
5301
5313
|
if self_attn_weights is None:
|
|
5302
|
-
_, _, self_attn_weights = self.pipeline.model2.predict(input_ids)
|
|
5314
|
+
_, _, self_attn_weights = self.pipeline.model2.predict(input_ids)
|
|
5315
|
+
|
|
5316
|
+
|
|
5317
|
+
if isinstance(attn_weights, tuple):
|
|
5318
|
+
attn_weights = attn_weights[0]
|
|
5319
|
+
if isinstance(self_attn_weights, tuple):
|
|
5320
|
+
self_attn_weights = self_attn_weights[0]
|
|
5321
|
+
|
|
5322
|
+
if isinstance(self_attn_weights, str):
|
|
5323
|
+
self_attn_weights = np.array(self_attn_weights)
|
|
5324
|
+
self_attn_weights = self_attn_weights[0]
|
|
5325
|
+
|
|
5326
|
+
if isinstance(attn_weights, str):
|
|
5327
|
+
attn_weights = np.array(attn_weights)
|
|
5328
|
+
|
|
5303
5329
|
batch_similarity = self.pipeline.cosine_similarity(attn_weights, self_attn_weights)
|
|
5304
5330
|
|
|
5305
5331
|
anisotropy = self.pipeline.anisotropy_measurement(attn_weights)
|
|
@@ -5317,7 +5343,8 @@ class AgentDistributedInference:
|
|
|
5317
5343
|
return calibrated
|
|
5318
5344
|
|
|
5319
5345
|
except Exception as e:
|
|
5320
|
-
print(f"[
|
|
5346
|
+
print(f"[= =] Error in uncertainty handling: {e}")
|
|
5347
|
+
traceback.print_exc()
|
|
5321
5348
|
return probs
|
|
5322
5349
|
|
|
5323
5350
|
|
|
@@ -5969,24 +5996,33 @@ class AutoBatcherAutomation:
|
|
|
5969
5996
|
# The IntegratedPipeline class serves as the central component that integrates all the different modules and functionalities of the system.
|
|
5970
5997
|
# It manages the overall workflow, including data processing, model training, prediction, memory management, and interactions with other agents.
|
|
5971
5998
|
class IntegratedPipeline:
|
|
5972
|
-
def __init__(self, memory_name, use_async, agent_port=None, ssl_cert_file=None, ssl_key_file=None, secret_key=None, shared_auth_token=None, predict_manager=None):
|
|
5973
|
-
|
|
5999
|
+
def __init__(self, memory_name='agent_memory', use_async=False, agent_port=None, singleton_permitted=False, ssl_cert_file=None, ssl_key_file=None, secret_key=None, shared_auth_token=None, predict_manager=None):
|
|
6000
|
+
# Only initialized once and when allowed
|
|
6001
|
+
|
|
6002
|
+
print('[= MEMORY =] Initializing IntegratedPipeline with memory name:', memory_name)
|
|
5974
6003
|
|
|
5975
6004
|
if hasattr(self, '_singleton_initialized'):
|
|
5976
|
-
print(
|
|
6005
|
+
print("[=] IntegratedPipeline instance already initialized, skipping __init__")
|
|
5977
6006
|
return
|
|
5978
|
-
|
|
5979
|
-
self.
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
6007
|
+
|
|
6008
|
+
self.singleton_permitted = singleton_permitted
|
|
6009
|
+
|
|
6010
|
+
if self.singleton_permitted:
|
|
6011
|
+
super().__init__()
|
|
6012
|
+
|
|
6013
|
+
print("[= SINGLETON =] IntegratedPipeline singleton instance created")
|
|
6014
|
+
self._singleton_initialized = True
|
|
6015
|
+
|
|
6016
|
+
# Stored initialization params for debugging later
|
|
6017
|
+
self._init_params = {
|
|
6018
|
+
'memory_name': memory_name,
|
|
6019
|
+
'port': agent_port,
|
|
6020
|
+
'use_async': use_async,
|
|
6021
|
+
'secret_key': secret_key,
|
|
6022
|
+
'ssl_cert_file': ssl_cert_file,
|
|
6023
|
+
'ssl_key_file': ssl_key_file,
|
|
6024
|
+
'shared_auth_token': shared_auth_token
|
|
6025
|
+
}
|
|
5990
6026
|
|
|
5991
6027
|
self.ssl_cert_file = ssl_cert_file
|
|
5992
6028
|
self.ssl_key_file = ssl_key_file
|
|
@@ -6004,10 +6040,12 @@ class IntegratedPipeline:
|
|
|
6004
6040
|
self.batcher = AutoBatcherAutomation(self)
|
|
6005
6041
|
self.query_node = QueryNode(self, memory_name, self.storage)
|
|
6006
6042
|
|
|
6007
|
-
self._agent_mode =
|
|
6008
|
-
self._agent_port = int(
|
|
6009
|
-
self._use_async =
|
|
6010
|
-
|
|
6043
|
+
self._agent_mode = 'single'
|
|
6044
|
+
self._agent_port = int(agent_port) if int(agent_port) is not None else 5000
|
|
6045
|
+
self._use_async = use_async
|
|
6046
|
+
|
|
6047
|
+
print(f'[= PORT =] IntegratedPipeline initialized on port {self._agent_port}')
|
|
6048
|
+
|
|
6011
6049
|
# Queue for managing async operations
|
|
6012
6050
|
self._async_tasks = set()
|
|
6013
6051
|
self._loop = None
|
|
@@ -6519,6 +6557,27 @@ class IntegratedPipeline:
|
|
|
6519
6557
|
eps = 1e-5
|
|
6520
6558
|
b = b[0]
|
|
6521
6559
|
|
|
6560
|
+
if isinstance(a, (str, np.str_)):
|
|
6561
|
+
clean_str = str(a).replace('[', '').replace(']', '')
|
|
6562
|
+
a = np.fromstring(clean_str, sep=' ')
|
|
6563
|
+
elif isinstance(a, np.ndarray) and np.issubdtype(a.dtype, np.character):
|
|
6564
|
+
# catches arrays filled with string text
|
|
6565
|
+
clean_str = ' '.join(a.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
6566
|
+
a = np.fromstring(clean_str, sep=' ')
|
|
6567
|
+
else:
|
|
6568
|
+
# Ensure standard float array if it was integers or objects
|
|
6569
|
+
a = np.asarray(a, dtype=float)
|
|
6570
|
+
|
|
6571
|
+
# Handle variable b
|
|
6572
|
+
if isinstance(b, (str, np.str_)):
|
|
6573
|
+
clean_str = str(b).replace('[', '').replace(']', '')
|
|
6574
|
+
b = np.fromstring(clean_str, sep=' ')
|
|
6575
|
+
elif isinstance(b, np.ndarray) and np.issubdtype(b.dtype, np.character):
|
|
6576
|
+
clean_str = ' '.join(b.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
6577
|
+
b = np.fromstring(clean_str, sep=' ')
|
|
6578
|
+
else:
|
|
6579
|
+
b = np.asarray(b, dtype=float)
|
|
6580
|
+
|
|
6522
6581
|
norm_a = np.linalg.norm(a)
|
|
6523
6582
|
norm_b = np.linalg.norm(b)
|
|
6524
6583
|
|
|
@@ -6543,7 +6602,6 @@ class IntegratedPipeline:
|
|
|
6543
6602
|
print('[-] No similarity due to inhomogenous shapes and failed attempts to find subsets, returning low similarity score.')
|
|
6544
6603
|
return 0.1
|
|
6545
6604
|
|
|
6546
|
-
|
|
6547
6605
|
else:
|
|
6548
6606
|
subset_a = a[:a.shape[0]]
|
|
6549
6607
|
subset_b = b[:subset_a.shape[0]]
|
|
@@ -7843,7 +7901,15 @@ class IntegratedPipeline:
|
|
|
7843
7901
|
def AME_Encoder(self, x):
|
|
7844
7902
|
X = np.asarray(x)
|
|
7845
7903
|
|
|
7846
|
-
|
|
7904
|
+
if isinstance(X, (str, np.str_)):
|
|
7905
|
+
clean_str = str(X).replace('[', '').replace(']', '')
|
|
7906
|
+
X = np.fromstring(clean_str, sep=' ')
|
|
7907
|
+
if isinstance(X, np.ndarray) and np.issubdtype(X.dtype, np.character):
|
|
7908
|
+
# catches arrays filled with string text
|
|
7909
|
+
clean_str = ' '.join(X.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
7910
|
+
X = np.fromstring(clean_str, sep=' ')
|
|
7911
|
+
|
|
7912
|
+
gradient = np.gradient(X, axis=-1)
|
|
7847
7913
|
grad_energy = np.mean(np.linalg.norm(gradient, axis=-1))
|
|
7848
7914
|
X_mag = np.mean(np.linalg.norm(X, axis=-1))
|
|
7849
7915
|
|
|
@@ -7852,6 +7918,7 @@ class IntegratedPipeline:
|
|
|
7852
7918
|
if AME == 0.0:
|
|
7853
7919
|
eps = 1e-5
|
|
7854
7920
|
AME = AME + eps
|
|
7921
|
+
|
|
7855
7922
|
return AME
|
|
7856
7923
|
|
|
7857
7924
|
def feature_generation(self, rules, dataset):
|
|
@@ -9945,6 +10012,7 @@ class PipelineAsyncManager:
|
|
|
9945
10012
|
class PipelinePredictionManager:
|
|
9946
10013
|
def __init__(self, pipeline, label_csv='labels.csv', target_title='title', label='label'):
|
|
9947
10014
|
self.pipeline = pipeline
|
|
10015
|
+
|
|
9948
10016
|
try:
|
|
9949
10017
|
print("📖 Loading labels from text file...")
|
|
9950
10018
|
self.titles, self.y_raw, self.label_map = self.load_labels_from_csv(label_csv, target_title, label)
|
|
@@ -10740,7 +10808,7 @@ class PipelinePredictionManager:
|
|
|
10740
10808
|
elif results and not results[0].get('models_agree', True) or not self.pipeline.agreement:
|
|
10741
10809
|
need_peer_condition = not results[0].get('models_agree', True) and self.pipeline.peer_assistance_threshold > 0.3
|
|
10742
10810
|
print("\n[⚠️] Disagreement detected between MLP and Transformer predictions. Using calibrated probabilities for final decision.")
|
|
10743
|
-
if need_peer_condition:
|
|
10811
|
+
if not self.pipeline.autonomous and need_peer_condition:
|
|
10744
10812
|
print('|| Uncertain advanced prediction, requesting peer assistance if allowed...')
|
|
10745
10813
|
final_probs = self.pipeline._handle_distributed_connections(final_probs, attn_weights, input_ids, agreement)
|
|
10746
10814
|
|
|
@@ -11350,7 +11418,8 @@ class CohesiveAgentDeployment:
|
|
|
11350
11418
|
Handles graceful shutdown, error recovery, and peer connections.
|
|
11351
11419
|
"""
|
|
11352
11420
|
|
|
11353
|
-
def __init__(self,
|
|
11421
|
+
def __init__(self,
|
|
11422
|
+
pipeline: IntegratedPipeline = None,
|
|
11354
11423
|
memory_name: str,
|
|
11355
11424
|
filename: str,
|
|
11356
11425
|
target_title: str,
|
|
@@ -11365,33 +11434,8 @@ class CohesiveAgentDeployment:
|
|
|
11365
11434
|
peer_config: Any='peer_config.json',
|
|
11366
11435
|
consecutive_peer_config: Any=None
|
|
11367
11436
|
):
|
|
11368
|
-
super().__init__()
|
|
11369
11437
|
|
|
11370
|
-
|
|
11371
|
-
print(f"[===] CohesiveAgentDeployment already initialized, reusing...")
|
|
11372
|
-
return
|
|
11373
|
-
|
|
11374
|
-
self._singleton_initialized = True
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
self._init_params = {
|
|
11378
|
-
'memory_name': memory_name,
|
|
11379
|
-
'port': peer_discovery_port,
|
|
11380
|
-
'secret_key': secret_key,
|
|
11381
|
-
'trusted_networks':trusted_networks,
|
|
11382
|
-
'shared_auth_token': shared_auth_token
|
|
11383
|
-
}
|
|
11384
|
-
|
|
11385
|
-
self.pipeline = IntegratedPipeline(
|
|
11386
|
-
memory_name=memory_name,
|
|
11387
|
-
use_async=True,
|
|
11388
|
-
agent_port=peer_discovery_port,
|
|
11389
|
-
ssl_cert_file=None,
|
|
11390
|
-
ssl_key_file=None,
|
|
11391
|
-
secret_key=secret_key,
|
|
11392
|
-
shared_auth_token=shared_auth_token,
|
|
11393
|
-
predict_manager=predict_manager
|
|
11394
|
-
)
|
|
11438
|
+
self.pipeline = pipeline
|
|
11395
11439
|
|
|
11396
11440
|
# Initialize prediction manager
|
|
11397
11441
|
self.manager = PipelinePredictionManager(
|
|
@@ -12576,8 +12620,7 @@ class CohesiveAgentDeployment:
|
|
|
12576
12620
|
|
|
12577
12621
|
# ============ EXAMPLE: SECURE PEER-TO-PEER CLUSTER ============
|
|
12578
12622
|
|
|
12579
|
-
|
|
12580
|
-
async def run_secure_agent_cluster(test_titles, label_map, rules, agent_id, filename, title_name, label_name, manager):
|
|
12623
|
+
async def run_secure_agent_cluster(pipeline,test_titles, label_map, rules, agent_id, filename, title_name, label_name, manager):
|
|
12581
12624
|
"""
|
|
12582
12625
|
Run multiple agents that securely communicate.
|
|
12583
12626
|
Stops retrying once connected successfully.
|
|
@@ -12591,6 +12634,7 @@ async def run_secure_agent_cluster(test_titles, label_map, rules, agent_id, file
|
|
|
12591
12634
|
|
|
12592
12635
|
# Agent 1 - Primary (Port 5555)
|
|
12593
12636
|
agent1 = CohesiveAgentDeployment(
|
|
12637
|
+
pipeline=pipeline,
|
|
12594
12638
|
memory_name="agent_primary",
|
|
12595
12639
|
filename=filename,
|
|
12596
12640
|
target_title=title_name,
|
|
@@ -12606,6 +12650,7 @@ async def run_secure_agent_cluster(test_titles, label_map, rules, agent_id, file
|
|
|
12606
12650
|
|
|
12607
12651
|
# Agent 2 - Secondary (Port 5556)
|
|
12608
12652
|
agent2 = CohesiveAgentDeployment(
|
|
12653
|
+
pipeline=pipeline,
|
|
12609
12654
|
memory_name="agent_secondary",
|
|
12610
12655
|
filename=filename,
|
|
12611
12656
|
target_title=title_name,
|
|
@@ -12679,7 +12724,7 @@ async def run_secure_agent_cluster(test_titles, label_map, rules, agent_id, file
|
|
|
12679
12724
|
|
|
12680
12725
|
|
|
12681
12726
|
|
|
12682
|
-
async def example_async_with_result_queue(test_titles, label_map, rules, agent_id, filename, title_name, label_name):
|
|
12727
|
+
async def example_async_with_result_queue(pipeline, test_titles, label_map, rules, agent_id, filename, title_name, label_name):
|
|
12683
12728
|
# Example using the proper result queue
|
|
12684
12729
|
|
|
12685
12730
|
agent = CohesiveAgentDeployment(
|
|
@@ -12744,15 +12789,15 @@ async def example_async_with_result_queue(test_titles, label_map, rules, agent_i
|
|
|
12744
12789
|
|
|
12745
12790
|
|
|
12746
12791
|
|
|
12747
|
-
def initiate_cohesive_agent_deployment_test(test_titles, label_map, rules, agent_id, filename, title_name, label_name, manager):
|
|
12792
|
+
def initiate_cohesive_agent_deployment_test(pipeline, test_titles, label_map, rules, agent_id, filename, title_name, label_name, manager):
|
|
12748
12793
|
print("\n" + "="*60)
|
|
12749
12794
|
print("🔮 = TESTING COHESIVE AGENT DEPLOYMENT WITH ASYNC MANAGER = ")
|
|
12750
12795
|
|
|
12751
12796
|
print('Test 1 of Multi agent cluster')
|
|
12752
|
-
asyncio.run(run_secure_agent_cluster(test_titles=test_titles, label_map=label_map, rules=rules, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name, manager=manager))
|
|
12797
|
+
asyncio.run(run_secure_agent_cluster(pipeline=pipeline, test_titles=test_titles, label_map=label_map, rules=rules, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name, manager=manager))
|
|
12753
12798
|
|
|
12754
12799
|
print("\n1. Basic async with result queue")
|
|
12755
|
-
asyncio.run(example_async_with_result_queue(test_titles=test_titles, label_map=label_map, rules=rules, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name))
|
|
12800
|
+
asyncio.run(example_async_with_result_queue(pipeline=pipeline, test_titles=test_titles, label_map=label_map, rules=rules, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name))
|
|
12756
12801
|
|
|
12757
12802
|
|
|
12758
12803
|
# async manager setup examples
|
|
@@ -12879,10 +12924,10 @@ def PermissiveTest():
|
|
|
12879
12924
|
key_file = None
|
|
12880
12925
|
|
|
12881
12926
|
if file:
|
|
12882
|
-
pipeline = IntegratedPipeline(file, use_async=True, agent_port=5001, ssl_cert_file=cert_file, ssl_key_file=key_file)
|
|
12927
|
+
pipeline = IntegratedPipeline(file, use_async=True, agent_port=5001, singleton_permitted=False,ssl_cert_file=cert_file, ssl_key_file=key_file)
|
|
12883
12928
|
else:
|
|
12884
12929
|
print('|| Using original csv_file.pkl file as fallback...')
|
|
12885
|
-
pipeline = IntegratedPipeline('csv_file.pkl', use_async=True, agent_port=5001, ssl_cert_file=cert_file, ssl_key_file=key_file)
|
|
12930
|
+
pipeline = IntegratedPipeline('csv_file.pkl', use_async=True, agent_port=5001, singleton_permitted=False, ssl_cert_file=cert_file, ssl_key_file=key_file)
|
|
12886
12931
|
|
|
12887
12932
|
manager = PipelinePredictionManager(pipeline, label_csv='ManualsTraining.txt', target_title='window_title', label='label')
|
|
12888
12933
|
|
|
@@ -13026,9 +13071,9 @@ def PermissiveTest():
|
|
|
13026
13071
|
if cohesive_permission == 'Y' or cohesive_permission == 'y':
|
|
13027
13072
|
if not (filename and title and label and filename != 'N'):
|
|
13028
13073
|
print('[=] Searching fallback filename: ManualsTraining.txt, window_title, label')
|
|
13029
|
-
initiate_cohesive_agent_deployment_test(test_titles, label_map, rules, agent_id, 'ManualsTraining.txt', 'window_title', 'label', manager)
|
|
13074
|
+
initiate_cohesive_agent_deployment_test(pipeline,test_titles, label_map, rules, agent_id, 'ManualsTraining.txt', 'window_title', 'label', manager)
|
|
13030
13075
|
else:
|
|
13031
|
-
initiate_cohesive_agent_deployment_test(test_titles, label_map, rules, agent_id, filename, title, label, manager)
|
|
13076
|
+
initiate_cohesive_agent_deployment_test(pipeline, test_titles, label_map, rules, agent_id, filename, title, label, manager)
|
|
13032
13077
|
print('== Cohesive Agent Deployment Successfully tested! ==')
|
|
13033
13078
|
|
|
13034
13079
|
else:
|
|
@@ -13045,3 +13090,4 @@ if __name__ == "__main__":
|
|
|
13045
13090
|
traceback.print_exc()
|
|
13046
13091
|
pass
|
|
13047
13092
|
|
|
13093
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Framework forAdvanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework
|
|
5
5
|
Author: Micro-Novelty
|
|
6
6
|
Author-email: hernikpuspita5@gmail.com
|
|
@@ -40,11 +40,12 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
40
40
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
41
41
|
|
|
42
42
|
### Library Short Description:
|
|
43
|
-
- Development Stage: Beta, 0.2.
|
|
43
|
+
- Development Stage: Beta, 0.2.4.
|
|
44
44
|
- Maintainer: Micro-Novelty.
|
|
45
45
|
- library Source-Code is Open-sourced on github.
|
|
46
46
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
|
47
|
-
|
|
47
|
+
- Proven Capabilities: Works on ARM64 Environment, Training and Prediction works efficient on Docker ARM64 environment with QEMU, good parallelizing behavior is guaranteed.
|
|
48
|
+
-----
|
|
48
49
|
|
|
49
50
|
<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" />
|
|
50
51
|
|
|
@@ -482,11 +483,21 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
482
483
|
import numpy as np
|
|
483
484
|
|
|
484
485
|
memory_name = 'agent_memory'
|
|
485
|
-
main_model = IntegratedPipeline(
|
|
486
|
-
|
|
487
|
-
|
|
486
|
+
main_model = IntegratedPipeline(
|
|
487
|
+
memory_name=memory_name, # memory name for the AI you already initialized
|
|
488
|
+
use_async=True, # local asynchronous prediction is permitted, if not PipelineAsyncManager wont start asynchronous prediction.
|
|
489
|
+
agent_port=5001, # this port is used to set AgentDistributedInference server (optional)
|
|
490
|
+
singleton_permitted=False, # set IntegratedPipeline to singleton if you don't use it for P2P, False if you use P2P.
|
|
491
|
+
ssl_cert_file=cert_file, ssl_key_file=key_file) # provide your cert_file path or key_file path (optional)
|
|
492
|
+
|
|
493
|
+
main_prediction = PipelinePredictionManager(
|
|
494
|
+
main_model, # your initialized pipeline
|
|
495
|
+
label_csv='example_manual_training.txt', # your .txt file that contains CSV format.
|
|
496
|
+
target_title='window_title', label='label')
|
|
488
497
|
|
|
498
|
+
# example_manual_training is a .txt file that contain csv format like above example.
|
|
489
499
|
|
|
500
|
+
# rules will be used to create automatic dataset for IntegratedPipeline.
|
|
490
501
|
example_rules = [
|
|
491
502
|
# === WORK / PRODUCTIVITY ===
|
|
492
503
|
(r'code|programming|develop|debug|compile|script', 'focused_work'),
|
|
@@ -508,6 +519,7 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
508
519
|
|
|
509
520
|
# more rules
|
|
510
521
|
]
|
|
522
|
+
|
|
511
523
|
# activate explainability capability to explain uncertainty:
|
|
512
524
|
main_model.show_explainability_details = True
|
|
513
525
|
main_model.distribution.predict_manager = main_prediction # set PipelinePredictionManager to AgentDistributedInference for asynchronous prediction later (Very important for asynchronous prediction)
|
|
@@ -525,16 +537,20 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
525
537
|
# more titles
|
|
526
538
|
]
|
|
527
539
|
|
|
528
|
-
titles, y, label_map = main_prediction.load_labels_from_csv(
|
|
529
|
-
|
|
540
|
+
titles, y, label_map = main_prediction.load_labels_from_csv(
|
|
541
|
+
<your_filename.>, # the name of your .txt file with CSV format.
|
|
542
|
+
<target_title>, <target_label>)
|
|
543
|
+
|
|
544
|
+
# small training with simple titles first
|
|
530
545
|
main_model.train(titles, y)
|
|
531
546
|
|
|
532
|
-
results, chosen_label, confidence = main_prediction.advanced_prediction_method(
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
547
|
+
results, chosen_label, confidence = main_prediction.advanced_prediction_method(
|
|
548
|
+
test_titles, label_map, example_rules,
|
|
549
|
+
show_proba=False, top_k=3,
|
|
550
|
+
use_transformer=True,
|
|
551
|
+
return_attention=False,
|
|
552
|
+
save_results=True,
|
|
553
|
+
batch_size=2)
|
|
538
554
|
# batch size=2 is needed during transformer training for batching, if you have larger samples consider using batch_size > 8, for medium amount of samples (>10 -> <50 samples) consider using 2 or 4 batch_size.
|
|
539
555
|
# ... more features you can add
|
|
540
556
|
```
|
|
@@ -585,7 +601,7 @@ async_manager = PipelineAsyncManager(main_model,
|
|
|
585
601
|
state_file=None, # state file is used to load known security logs ex: ip used, ip blacklisted, etc.
|
|
586
602
|
security_level=SecurityLevel.PRODUCTION, # production level security initiated
|
|
587
603
|
api_key=secret_key #set secret key you initialized
|
|
588
|
-
max_workers=4, # workers to initiate
|
|
604
|
+
max_workers=4, # workers to initiate asynchronous tasks, more workers, more capabilities to process asynchronous prediction requests.
|
|
589
605
|
task_timeout=30,
|
|
590
606
|
max_retries=3 ) # retries after failure during prediction
|
|
591
607
|
|
|
@@ -616,6 +632,7 @@ predicted_output = async_manager.advanced_batch_prediction(test_titles, label_ma
|
|
|
616
632
|
- To Make the Agent cooperate with other peers, consider using this setup:
|
|
617
633
|
- [=] for ensemble prediction from multiple peers, exchanging predicted label with each other, consider using this setup:
|
|
618
634
|
```python
|
|
635
|
+
|
|
619
636
|
# step 3
|
|
620
637
|
from AbstractIntegratedModule import CohesiveAgentDeployment
|
|
621
638
|
from AbstractIntegratedModule import PipelinePredictionManager
|
|
@@ -634,23 +651,25 @@ main_model.distribution.enable_ssl = False # set to false if you dont have SSL k
|
|
|
634
651
|
|
|
635
652
|
# Agent 1 - Primary (Port 5555)
|
|
636
653
|
agent1 = CohesiveAgentDeployment(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
654
|
+
pipeline=main_model, # main_model is your initialized integrated pipeline
|
|
655
|
+
memory_name="agent_primary", # any name you want for the agent.
|
|
656
|
+
filename=<filename>, # name of your .txt file that contains the CSV format and training labels
|
|
657
|
+
target_title=<title_name>,
|
|
640
658
|
label_name=<label_name>,
|
|
641
|
-
security_level="PRODUCTION",
|
|
642
|
-
enable_peers=True,
|
|
659
|
+
security_level="PRODUCTION", # production level security
|
|
660
|
+
enable_peers=True, # allow peer discovery
|
|
643
661
|
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.
|
|
644
662
|
peer_discovery_port=5555, # peer port to start P2P
|
|
645
|
-
secret_key=secret_key,
|
|
663
|
+
secret_key=secret_key, # your secret key
|
|
646
664
|
shared_auth_token=secret_key, # your previous initialized secret_key
|
|
647
|
-
predict_manager=prediction_manager,
|
|
665
|
+
predict_manager=prediction_manager, # your prediction manager
|
|
648
666
|
peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
|
|
649
667
|
consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
|
|
650
|
-
|
|
668
|
+
)
|
|
651
669
|
|
|
652
670
|
# Agent 2 - Secondary (Port 5556)
|
|
653
671
|
agent2 = CohesiveAgentDeployment(
|
|
672
|
+
pipeline=main_model,
|
|
654
673
|
memory_name="agent_secondary",
|
|
655
674
|
filename=<filename>,
|
|
656
675
|
target_title=<title_name>,
|
|
@@ -664,21 +683,20 @@ agent2 = CohesiveAgentDeployment(
|
|
|
664
683
|
predict_manager=prediction_manager,
|
|
665
684
|
peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
|
|
666
685
|
consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
|
|
667
|
-
|
|
686
|
+
)
|
|
668
687
|
|
|
669
688
|
# Note: CohesiveAgentDeployment contains ConsecutivePeerAgent that can start a server once ensemble prediction from peer is started
|
|
670
689
|
# be advised to stop the server too before shutdown-ing CohesiveAgentDeployment cluster
|
|
671
690
|
|
|
672
691
|
# example peer_Ip_lists_config.json (de-comment to use)
|
|
673
692
|
# {
|
|
674
|
-
#
|
|
693
|
+
# you must put "known_peers" in the config so python can identify the list of IPs and Ports
|
|
694
|
+
# "known_peers": [
|
|
675
695
|
# ["127.0.0.1", 5555], can be modified using real IP or local IP.
|
|
676
696
|
# ["127.0.0.1", 5556]
|
|
677
697
|
# ]
|
|
678
698
|
# }
|
|
679
699
|
|
|
680
|
-
agent1.pipeline = main_model # overrides agent1 baseline pipeline with your original initialized pipelinej
|
|
681
|
-
agent2.pipeline = main_model
|
|
682
700
|
|
|
683
701
|
try:
|
|
684
702
|
# Start both agents
|
|
@@ -699,8 +717,8 @@ try:
|
|
|
699
717
|
|
|
700
718
|
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
701
719
|
|
|
702
|
-
# texts
|
|
703
|
-
# agent ID can be strings, int, or floats,
|
|
720
|
+
# texts dictionary must contain test_titles, label_map, and rules that you can assign,
|
|
721
|
+
# agent ID can be strings, int, or floats, recommendded to make it long for better security.
|
|
704
722
|
|
|
705
723
|
# Make prediction with peer ensemble
|
|
706
724
|
# Connection will be guaranteed successfull during discovery.
|
|
@@ -8,11 +8,12 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
8
8
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
9
9
|
|
|
10
10
|
### Library Short Description:
|
|
11
|
-
- Development Stage: Beta, 0.2.
|
|
11
|
+
- Development Stage: Beta, 0.2.4.
|
|
12
12
|
- Maintainer: Micro-Novelty.
|
|
13
13
|
- library Source-Code is Open-sourced on github.
|
|
14
14
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
|
15
|
-
|
|
15
|
+
- Proven Capabilities: Works on ARM64 Environment, Training and Prediction works efficient on Docker ARM64 environment with QEMU, good parallelizing behavior is guaranteed.
|
|
16
|
+
-----
|
|
16
17
|
|
|
17
18
|
<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" />
|
|
18
19
|
|
|
@@ -450,11 +451,21 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
450
451
|
import numpy as np
|
|
451
452
|
|
|
452
453
|
memory_name = 'agent_memory'
|
|
453
|
-
main_model = IntegratedPipeline(
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
main_model = IntegratedPipeline(
|
|
455
|
+
memory_name=memory_name, # memory name for the AI you already initialized
|
|
456
|
+
use_async=True, # local asynchronous prediction is permitted, if not PipelineAsyncManager wont start asynchronous prediction.
|
|
457
|
+
agent_port=5001, # this port is used to set AgentDistributedInference server (optional)
|
|
458
|
+
singleton_permitted=False, # set IntegratedPipeline to singleton if you don't use it for P2P, False if you use P2P.
|
|
459
|
+
ssl_cert_file=cert_file, ssl_key_file=key_file) # provide your cert_file path or key_file path (optional)
|
|
460
|
+
|
|
461
|
+
main_prediction = PipelinePredictionManager(
|
|
462
|
+
main_model, # your initialized pipeline
|
|
463
|
+
label_csv='example_manual_training.txt', # your .txt file that contains CSV format.
|
|
464
|
+
target_title='window_title', label='label')
|
|
456
465
|
|
|
466
|
+
# example_manual_training is a .txt file that contain csv format like above example.
|
|
457
467
|
|
|
468
|
+
# rules will be used to create automatic dataset for IntegratedPipeline.
|
|
458
469
|
example_rules = [
|
|
459
470
|
# === WORK / PRODUCTIVITY ===
|
|
460
471
|
(r'code|programming|develop|debug|compile|script', 'focused_work'),
|
|
@@ -476,6 +487,7 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
476
487
|
|
|
477
488
|
# more rules
|
|
478
489
|
]
|
|
490
|
+
|
|
479
491
|
# activate explainability capability to explain uncertainty:
|
|
480
492
|
main_model.show_explainability_details = True
|
|
481
493
|
main_model.distribution.predict_manager = main_prediction # set PipelinePredictionManager to AgentDistributedInference for asynchronous prediction later (Very important for asynchronous prediction)
|
|
@@ -493,16 +505,20 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP using AWE.
|
|
|
493
505
|
# more titles
|
|
494
506
|
]
|
|
495
507
|
|
|
496
|
-
titles, y, label_map = main_prediction.load_labels_from_csv(
|
|
497
|
-
|
|
508
|
+
titles, y, label_map = main_prediction.load_labels_from_csv(
|
|
509
|
+
<your_filename.>, # the name of your .txt file with CSV format.
|
|
510
|
+
<target_title>, <target_label>)
|
|
511
|
+
|
|
512
|
+
# small training with simple titles first
|
|
498
513
|
main_model.train(titles, y)
|
|
499
514
|
|
|
500
|
-
results, chosen_label, confidence = main_prediction.advanced_prediction_method(
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
515
|
+
results, chosen_label, confidence = main_prediction.advanced_prediction_method(
|
|
516
|
+
test_titles, label_map, example_rules,
|
|
517
|
+
show_proba=False, top_k=3,
|
|
518
|
+
use_transformer=True,
|
|
519
|
+
return_attention=False,
|
|
520
|
+
save_results=True,
|
|
521
|
+
batch_size=2)
|
|
506
522
|
# batch size=2 is needed during transformer training for batching, if you have larger samples consider using batch_size > 8, for medium amount of samples (>10 -> <50 samples) consider using 2 or 4 batch_size.
|
|
507
523
|
# ... more features you can add
|
|
508
524
|
```
|
|
@@ -553,7 +569,7 @@ async_manager = PipelineAsyncManager(main_model,
|
|
|
553
569
|
state_file=None, # state file is used to load known security logs ex: ip used, ip blacklisted, etc.
|
|
554
570
|
security_level=SecurityLevel.PRODUCTION, # production level security initiated
|
|
555
571
|
api_key=secret_key #set secret key you initialized
|
|
556
|
-
max_workers=4, # workers to initiate
|
|
572
|
+
max_workers=4, # workers to initiate asynchronous tasks, more workers, more capabilities to process asynchronous prediction requests.
|
|
557
573
|
task_timeout=30,
|
|
558
574
|
max_retries=3 ) # retries after failure during prediction
|
|
559
575
|
|
|
@@ -584,6 +600,7 @@ predicted_output = async_manager.advanced_batch_prediction(test_titles, label_ma
|
|
|
584
600
|
- To Make the Agent cooperate with other peers, consider using this setup:
|
|
585
601
|
- [=] for ensemble prediction from multiple peers, exchanging predicted label with each other, consider using this setup:
|
|
586
602
|
```python
|
|
603
|
+
|
|
587
604
|
# step 3
|
|
588
605
|
from AbstractIntegratedModule import CohesiveAgentDeployment
|
|
589
606
|
from AbstractIntegratedModule import PipelinePredictionManager
|
|
@@ -602,23 +619,25 @@ main_model.distribution.enable_ssl = False # set to false if you dont have SSL k
|
|
|
602
619
|
|
|
603
620
|
# Agent 1 - Primary (Port 5555)
|
|
604
621
|
agent1 = CohesiveAgentDeployment(
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
622
|
+
pipeline=main_model, # main_model is your initialized integrated pipeline
|
|
623
|
+
memory_name="agent_primary", # any name you want for the agent.
|
|
624
|
+
filename=<filename>, # name of your .txt file that contains the CSV format and training labels
|
|
625
|
+
target_title=<title_name>,
|
|
608
626
|
label_name=<label_name>,
|
|
609
|
-
security_level="PRODUCTION",
|
|
610
|
-
enable_peers=True,
|
|
627
|
+
security_level="PRODUCTION", # production level security
|
|
628
|
+
enable_peers=True, # allow peer discovery
|
|
611
629
|
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.
|
|
612
630
|
peer_discovery_port=5555, # peer port to start P2P
|
|
613
|
-
secret_key=secret_key,
|
|
631
|
+
secret_key=secret_key, # your secret key
|
|
614
632
|
shared_auth_token=secret_key, # your previous initialized secret_key
|
|
615
|
-
predict_manager=prediction_manager,
|
|
633
|
+
predict_manager=prediction_manager, # your prediction manager
|
|
616
634
|
peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
|
|
617
635
|
consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
|
|
618
|
-
|
|
636
|
+
)
|
|
619
637
|
|
|
620
638
|
# Agent 2 - Secondary (Port 5556)
|
|
621
639
|
agent2 = CohesiveAgentDeployment(
|
|
640
|
+
pipeline=main_model,
|
|
622
641
|
memory_name="agent_secondary",
|
|
623
642
|
filename=<filename>,
|
|
624
643
|
target_title=<title_name>,
|
|
@@ -632,21 +651,20 @@ agent2 = CohesiveAgentDeployment(
|
|
|
632
651
|
predict_manager=prediction_manager,
|
|
633
652
|
peer_config = <'your_peer_ip_lists.json'> # you need to create .json file that contains your peer IP and Port lists
|
|
634
653
|
consecutive_peer_config = <'your_second_fallback_peer_ip_lists.json'> # same for this one too, but for fallback.
|
|
635
|
-
|
|
654
|
+
)
|
|
636
655
|
|
|
637
656
|
# Note: CohesiveAgentDeployment contains ConsecutivePeerAgent that can start a server once ensemble prediction from peer is started
|
|
638
657
|
# be advised to stop the server too before shutdown-ing CohesiveAgentDeployment cluster
|
|
639
658
|
|
|
640
659
|
# example peer_Ip_lists_config.json (de-comment to use)
|
|
641
660
|
# {
|
|
642
|
-
#
|
|
661
|
+
# you must put "known_peers" in the config so python can identify the list of IPs and Ports
|
|
662
|
+
# "known_peers": [
|
|
643
663
|
# ["127.0.0.1", 5555], can be modified using real IP or local IP.
|
|
644
664
|
# ["127.0.0.1", 5556]
|
|
645
665
|
# ]
|
|
646
666
|
# }
|
|
647
667
|
|
|
648
|
-
agent1.pipeline = main_model # overrides agent1 baseline pipeline with your original initialized pipelinej
|
|
649
|
-
agent2.pipeline = main_model
|
|
650
668
|
|
|
651
669
|
try:
|
|
652
670
|
# Start both agents
|
|
@@ -667,8 +685,8 @@ try:
|
|
|
667
685
|
|
|
668
686
|
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
669
687
|
|
|
670
|
-
# texts
|
|
671
|
-
# agent ID can be strings, int, or floats,
|
|
688
|
+
# texts dictionary must contain test_titles, label_map, and rules that you can assign,
|
|
689
|
+
# agent ID can be strings, int, or floats, recommendded to make it long for better security.
|
|
672
690
|
|
|
673
691
|
# Make prediction with peer ensemble
|
|
674
692
|
# Connection will be guaranteed successfull during discovery.
|
|
@@ -3,7 +3,7 @@ from setuptools import setup
|
|
|
3
3
|
|
|
4
4
|
setup(
|
|
5
5
|
name="AbstractIntegratedModule",
|
|
6
|
-
version="0.2.
|
|
6
|
+
version="0.2.4",
|
|
7
7
|
description="Framework forAdvanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework",
|
|
8
8
|
long_description=open("README.md", encoding="utf-8").read(),
|
|
9
9
|
long_description_content_type="text/markdown",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|