AbstractIntegratedModule 0.3.7__tar.gz → 0.3.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (16) hide show
  1. abstractintegratedmodule-0.3.8/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
  2. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.cpython-310-aarch64-linux-gnu.so +0 -0
  3. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.cpython-312-x86_64-linux-gnu.so +0 -0
  4. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8/AbstractIntegratedModule.egg-info}/PKG-INFO +2 -2
  5. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.py +186 -75
  6. {abstractintegratedmodule-0.3.7/AbstractIntegratedModule.egg-info → abstractintegratedmodule-0.3.8}/PKG-INFO +2 -2
  7. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/README.md +1 -1
  8. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/setup.py +1 -1
  9. abstractintegratedmodule-0.3.7/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
  10. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
  11. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
  12. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
  13. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
  14. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/MANIFEST.in +0 -0
  15. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/pyproject.toml +0 -0
  16. {abstractintegratedmodule-0.3.7 → abstractintegratedmodule-0.3.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: Framework for Advanced 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
@@ -42,7 +42,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
42
42
  #### 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.
43
43
 
44
44
  ### Library Short Description:
45
- - Development Stage: Beta, 0.3.7.
45
+ - Development Stage: Beta, 0.3.8.
46
46
  - Maintainer: Micro-Novelty.
47
47
  - library Source-Code is Open-sourced on github.
48
48
  - Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
@@ -334,7 +334,7 @@ class GeometricWeightShaping:
334
334
  trC = (1/6 + K_G) / (trB**2 - 1.0)
335
335
 
336
336
  if np.isnan(trC) or np.isinf(trC):
337
- trC = anisotropy * (1.0 - mag_G) + eps
337
+ trC = anisotropy * (1.0 - np.std(x)) + eps
338
338
 
339
339
  floating_point = np.random.uniform(0, trC, size=X.shape)
340
340
  return k, floating_point, structured_noise
@@ -4755,11 +4755,19 @@ class ThreadedMessageQueue:
4755
4755
 
4756
4756
  logger.info(f"[=] Threaded message queue started with {self._worker_threads} workers")
4757
4757
 
4758
- def stop(self, timeout: float = 5.0):
4758
+ async def stop(self):
4759
4759
  # Stop worker threads gracefully.
4760
- self._running = False
4761
- for thread in self._workers:
4762
- thread.join(timeout=timeout)
4760
+ await self.result_queue.stop()
4761
+
4762
+ # cancel and wait for all workers to exit cleanly
4763
+ for worker in self._workers:
4764
+ worker.cancel()
4765
+
4766
+ if self._workers:
4767
+ await asyncio.gather(*self._workers, return_exceptions=True)
4768
+
4769
+ self._workers.clear()
4770
+
4763
4771
  logger.info("[=] Threaded message queue stopped")
4764
4772
 
4765
4773
  def get_stats(self) -> Dict:
@@ -4856,6 +4864,7 @@ class AgentDistributedInference:
4856
4864
  self.message_timeout = 30.0
4857
4865
  self.CHUNK_SIZE = 8192
4858
4866
  self.predict_manager = predict_manager
4867
+ self._health_check_interval = 30 # seconds
4859
4868
 
4860
4869
  self.use_async = use_async
4861
4870
 
@@ -4875,7 +4884,6 @@ class AgentDistributedInference:
4875
4884
  # Queue for outgoing messages (buffered with retry)
4876
4885
  self.outgoing_queue = deque()
4877
4886
  self.queue_processor_thread = None
4878
- self._health_check_interval = 10 # seconds
4879
4887
  self._last_health_check = time.time()
4880
4888
 
4881
4889
  # Trust configuration
@@ -4886,7 +4894,6 @@ class AgentDistributedInference:
4886
4894
 
4887
4895
  self.pending_requests = {} # request_id -> Future
4888
4896
  self.request_lock = threading.Lock()
4889
-
4890
4897
 
4891
4898
  # ============ SECURITY FEATURES ============
4892
4899
 
@@ -5191,6 +5198,8 @@ class AgentDistributedInference:
5191
5198
  self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5192
5199
  self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
5193
5200
  self.socket.bind(('0.0.0.0', self.port))
5201
+
5202
+ self.socket.settimeout(1.0)
5194
5203
  self.socket.listen(5)
5195
5204
  self.running = True
5196
5205
  logger.info(f"[=] Server started on port {self.port} with SSL={'enabled' if self.enable_ssl else 'disabled'}")
@@ -5248,7 +5257,10 @@ class AgentDistributedInference:
5248
5257
  thread = threading.Thread(target=self._handle_client, args=(client, addr))
5249
5258
  thread.daemon = True
5250
5259
  thread.start()
5251
-
5260
+
5261
+ except socket.timeout:
5262
+ continue
5263
+
5252
5264
  except Exception as e:
5253
5265
  if self.running:
5254
5266
  print(f"[-] Accept error: {e}")
@@ -5272,18 +5284,26 @@ class AgentDistributedInference:
5272
5284
 
5273
5285
 
5274
5286
  def stop_server(self):
5275
- self.running = False
5276
- if self.socket:
5277
- self.socket.close()
5278
-
5287
+ self.running = False
5279
5288
  # Close all connections
5280
5289
  for conn in self.connections:
5281
- try:
5290
+ try:
5282
5291
  self._send_message(conn, {'type': self.MSG_TYPES['DISCONNECT']})
5292
+
5293
+ conn.shutdown(socket.SHUT_RDWR)
5283
5294
  conn.close()
5284
- except:
5295
+ except Exception as e:
5296
+ print(f'[= ERROR =] Socket cant be shutdown due to: {e}')
5285
5297
  pass
5286
-
5298
+
5299
+ self.connections.clear()
5300
+ if self.socket:
5301
+ try:
5302
+ self.socket.close()
5303
+ except Exception as e:
5304
+ print(f'[= ERROR =] Socket cant be closed due to: {e}')
5305
+ pass
5306
+
5287
5307
  print("[🛑] Server stopped")
5288
5308
 
5289
5309
  # ============ CLIENT METHODS ============
@@ -5803,9 +5823,13 @@ class AgentDistributedInference:
5803
5823
  def _start_health_checker(self):
5804
5824
  # Start background health checker for async mode.
5805
5825
  def health_check_loop():
5806
- while self.running:
5807
- time.sleep(self._health_check_interval)
5808
- self._check_health()
5826
+ for _ in range(self._health_check_interval * 10):
5827
+ if not self.running:
5828
+ return
5829
+ time.sleep(0.1)
5830
+
5831
+ if self.running:
5832
+ self._check_agent_health()
5809
5833
 
5810
5834
  self._health_thread = threading.Thread(target=health_check_loop, daemon=True)
5811
5835
  self._health_thread.start()
@@ -5842,7 +5866,18 @@ class AgentDistributedInference:
5842
5866
  # Graceful shutdown.
5843
5867
  logger.info("[=] Shutting down AgentDistributedInference...")
5844
5868
  self.running = False
5845
- asyncio.create_task(self.message_queue.stop())
5869
+
5870
+ try:
5871
+ loop = asyncio.get_event_loop()
5872
+ if loop.is_running():
5873
+ loop.call_soon_threadsafe(
5874
+ lambda: asyncio.ensure_future(self.message_queue.stop())
5875
+ )
5876
+ else:
5877
+ loop.run_until_complete(self.message_queue.stop())
5878
+ except Exception as e:
5879
+ logger.warning(f"[=] Message queue stop warning: {e}")
5880
+
5846
5881
  logger.info("[=] Shutdown complete")
5847
5882
 
5848
5883
  # ============ MESSAGE HANDLING ============
@@ -7448,12 +7483,21 @@ class IntegratedPipeline:
7448
7483
 
7449
7484
  print("✅ Async shutdown complete")
7450
7485
 
7451
- def shutdown(self):
7452
- # Synchronous shutdown (for non-async contexts).
7486
+ async def shutdown(self):
7453
7487
  if self.distribution:
7454
- self.distribution.stop()
7455
-
7488
+ self.distribution.stop() # sync call
7489
+ self.distribution.stop_server()
7490
+
7491
+
7492
+ if hasattr(self, '_shutdown_event'):
7493
+ self._shutdown_event.set()
7456
7494
 
7495
+ # cancel async tasks
7496
+ if self._async_tasks:
7497
+ for task in self._async_tasks:
7498
+ if not task.done():
7499
+ task.cancel()
7500
+ await asyncio.gather(*self._async_tasks, return_exceptions=True)
7457
7501
 
7458
7502
 
7459
7503
  def cosine_similarity(self, a, b):
@@ -9792,16 +9836,31 @@ class WorkerPool:
9792
9836
  async def stop(self):
9793
9837
  # Stop all workers
9794
9838
  self._running = False
9839
+ await self.result_queue.stop()
9840
+
9841
+ # cancel and wait for all workers to exit cleanly
9795
9842
  for worker in self._workers:
9796
9843
  worker.cancel()
9797
- await asyncio.gather(*self._workers, return_exceptions=True)
9798
-
9844
+
9845
+ if self._workers:
9846
+ await asyncio.gather(*self._workers, return_exceptions=True)
9847
+
9848
+ self._workers.clear()
9849
+
9850
+
9799
9851
  async def _worker(self, predict_func):
9800
9852
  # Worker that processes requests
9801
9853
  while self._running:
9802
9854
  try:
9803
9855
  # Get next pending request
9804
- request = await self.result_queue.get_pending()
9856
+ try:
9857
+ request = await asyncio.wait_for(
9858
+ self.result_queue.get_pending(),
9859
+ timeout=1.0
9860
+ )
9861
+ except asyncio.TimeoutError:
9862
+ continue # no request yet, re-check self._running
9863
+
9805
9864
  if not request:
9806
9865
  continue
9807
9866
 
@@ -9811,20 +9870,29 @@ class WorkerPool:
9811
9870
 
9812
9871
  try:
9813
9872
  # Execute prediction (run sync function in thread pool)
9814
- result = await asyncio.to_thread(
9815
- predict_func,
9816
- texts=request.texts,
9817
- api_key=request.api_key,
9818
- client_ip=request.client_ip
9873
+ result = await asyncio.wait_for(
9874
+ asyncio.to_thread(
9875
+ predict_func,
9876
+ texts=request.texts,
9877
+ api_key=request.api_key,
9878
+ client_ip=request.client_ip
9879
+ ),
9880
+ timeout=30.0
9819
9881
  )
9820
9882
 
9821
9883
  # Mark as completed
9822
9884
  await self.result_queue.complete(request.request_id, result)
9823
-
9885
+ except asyncio.TimeoutError:
9886
+ await self.result_queue._mark_failed(request.request_id, 'timeout')
9887
+ except asyncio.CancelledError:
9888
+ # shutdown mid-prediction — mark failed and exit cleanly
9889
+ await self.result_queue._mark_failed(request.request_id, 'cancelled')
9890
+ break
9891
+
9824
9892
  except Exception as e:
9825
9893
  # Mark as failed
9826
9894
  await self.result_queue._mark_failed(request.request_id, str(e))
9827
-
9895
+
9828
9896
  except asyncio.CancelledError:
9829
9897
  break
9830
9898
  except Exception as e:
@@ -11038,8 +11106,8 @@ class PipelineAsyncManager:
11038
11106
  self._thread = None
11039
11107
  self._queue_worker = None
11040
11108
  self._health_thread = None
11041
-
11042
- logger.info("[-] PipelineAsyncWrapper stopped")
11109
+ print('[=] PipelineAsync Wrapper stopped')
11110
+ logger.info("[-] PipelineAsync Wrapper stopped")
11043
11111
  return True
11044
11112
 
11045
11113
  def __enter__(self):
@@ -12352,6 +12420,7 @@ class ConsecutivePeerAgent:
12352
12420
  self.stats['predictions'] += 1
12353
12421
  return best_result
12354
12422
 
12423
+
12355
12424
  def start_server(self):
12356
12425
  """Start server to accept peer connections"""
12357
12426
 
@@ -12359,8 +12428,12 @@ class ConsecutivePeerAgent:
12359
12428
  self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12360
12429
  self.server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
12361
12430
  self.server_socket.bind(('0.0.0.0', self.port))
12362
-
12431
+ self.server_socket.settimeout(1.0)
12363
12432
  self.server_socket.listen(5)
12433
+
12434
+ if self.pipeline.distribution.enable_ssl and self.pipeline.distribution.ssl_context:
12435
+ self.server_socket = self.pipeline.distribution.ssl_context.wrap_socket(self.server_socket, server_side=True)
12436
+
12364
12437
  self.running = True
12365
12438
 
12366
12439
  print(f"[ConsecutivePeerAgent] Server listening on port {self.port}!")
@@ -12379,14 +12452,22 @@ class ConsecutivePeerAgent:
12379
12452
  thread = threading.Thread(target=self._handle_client, args=(client, addr))
12380
12453
  thread.daemon = True
12381
12454
  thread.start()
12382
-
12455
+ except socket.timeout:
12456
+ continue
12383
12457
  except Exception as e:
12384
12458
  if self.running:
12385
- print(f"[ConsecutivePeerAgent] Server error: {e}")
12459
+ print(f"[ConsecutivePeerAgent] Server error: {e}")
12460
+ try:
12461
+ self.server_socket.close()
12462
+ except:
12463
+ pass
12464
+
12465
+ print("[ConsecutivePeerAgent] Server Successfully Stopped listening !")
12386
12466
 
12387
12467
  thread = threading.Thread(target=server_loop, daemon=True)
12388
12468
  thread.start()
12389
-
12469
+
12470
+
12390
12471
  def _handle_client(self, client, addr):
12391
12472
  # Handle incoming peer connection
12392
12473
  print(f"[ConsecutivePeerAgent] Client connected from {addr}")
@@ -12452,21 +12533,32 @@ class ConsecutivePeerAgent:
12452
12533
  def stop_server(self):
12453
12534
  self.running = False
12454
12535
 
12455
- print('[ConsecutivePeerAgent] Server shutdown initiated...')
12456
- if self.server_socket:
12457
- self.server_socket.close()
12458
-
12536
+ print('[ConsecutivePeerAgent] Initiating Server shutdown...')
12459
12537
  # Close all peer connections
12460
- with self._lock:
12461
- for key, info in self.connected_peers.items():
12462
- try:
12463
- info['sock'].close()
12464
- except:
12465
- pass
12466
-
12467
- self.connected_peers.clear()
12468
- print('[ConsecutivePeerAgent] Server Successfully Stopped listening !')
12469
-
12538
+ try:
12539
+ with self._lock:
12540
+ for key, info in self.connected_peers.items():
12541
+ try:
12542
+ info['sock'].shutdown(socket.SHUT_RDWR)
12543
+ info['sock'].close()
12544
+ except:
12545
+ pass
12546
+
12547
+ self.connected_peers.clear()
12548
+ if self.server_socket:
12549
+ try:
12550
+ self.server_socket.close()
12551
+ except Exception as e:
12552
+ print(f'[ConsecutivePeerAgent] Cant close socket: {e}')
12553
+ pass
12554
+
12555
+ print('[ConsecutivePeerAgent] Server Successfully Stopped listening !')
12556
+
12557
+ except Exception as e:
12558
+ print(f'[ConsecutivePeerAgent] Error closing socket: {e}')
12559
+ pass
12560
+
12561
+
12470
12562
  def get_stats(self) -> Dict:
12471
12563
  # Get statistics
12472
12564
  return {
@@ -13654,23 +13746,40 @@ class CohesiveAgentDeployment:
13654
13746
  # Graceful shutdown of all components
13655
13747
  logger.info("🛑 Shutting down agent...")
13656
13748
 
13657
- # Signal shutdown
13749
+ # signal shutdown to all loops
13658
13750
  self._shutdown_event.set()
13751
+
13752
+ # stop worker pool.
13753
+ if hasattr(self, 'worker_pool'):
13754
+ await self.worker_pool.stop()
13755
+
13756
+ if hasattr(self, 'result_queue'):
13757
+ await self.result_queue.stop()
13758
+
13759
+ # cancel peer tasks
13760
+ if self._peer_tasks:
13761
+ for task in self._peer_tasks:
13762
+ task.cancel()
13763
+ await asyncio.gather(*self._peer_tasks, return_exceptions=True)
13659
13764
 
13660
- # Cancel peer tasks
13661
- for task in self._peer_tasks:
13662
- task.cancel()
13663
-
13664
- # Stop distribution server
13765
+ # stop peer agent server
13766
+ if hasattr(self, '_peer_agent'):
13767
+ self._peer_agent.stop_server()
13768
+
13769
+ # stop distribution server
13665
13770
  if self.enable_peers:
13666
13771
  self.pipeline.distribution.stop_server()
13667
-
13668
- # Stop async manager
13669
- self.async_manager.stop(timeout=10, force=False)
13670
-
13671
- # Wait for cleanup
13672
- await asyncio.sleep(2)
13673
-
13772
+
13773
+ # FIX 1 — offload blocking stop() to thread so event loop stays free
13774
+ print('[=] Stopping Asynchronous manager setup...')
13775
+ await asyncio.get_event_loop().run_in_executor(
13776
+ None,
13777
+ lambda: self.async_manager.stop(timeout=5, force=True)
13778
+ )
13779
+
13780
+ await asyncio.sleep(0.5)
13781
+ print('✅ Agent shutdown complete')
13782
+
13674
13783
  logger.info("✅ Agent shutdown complete")
13675
13784
 
13676
13785
  def get_api_key(self) -> str:
@@ -13767,19 +13876,19 @@ async def run_secure_agent_cluster(pipeline,test_titles, label_map, rules, agent
13767
13876
  print(f" Second Confidence: {result2.get('confidence', 0):.2%}")
13768
13877
 
13769
13878
  # Keep running briefly
13770
- print("\n⏳ Cluster stable. Waiting 5 seconds before shutdown...")
13771
- await asyncio.sleep(5)
13879
+ print("\n⏳ Cluster stable. Waiting 30 seconds before shutdown...")
13880
+ await asyncio.sleep(30)
13881
+ agent1._peer_agent.stop_server()
13772
13882
  agent2._peer_agent.stop_server()
13773
13883
 
13774
13884
  except Exception as e:
13775
13885
  print(f"\n❌ Error in cluster: {e}")
13776
13886
  traceback.print_exc()
13777
13887
 
13778
- finally:
13779
- print("\n🛑 Shutting down cluster...")
13780
- await agent1.shutdown()
13781
- await agent2.shutdown()
13782
- print("✅ Cluster shutdown complete")
13888
+ print("\n🛑 Shutting down cluster...")
13889
+ await agent1.shutdown()
13890
+ await agent2.shutdown()
13891
+ print("✅ Cluster shutdown complete")
13783
13892
 
13784
13893
 
13785
13894
 
@@ -13788,12 +13897,14 @@ async def example_async_with_result_queue(pipeline, test_titles, label_map, rule
13788
13897
  # Example using the proper result queue
13789
13898
 
13790
13899
  agent = CohesiveAgentDeployment(
13900
+ pipeline=pipeline,
13791
13901
  memory_name="test_agent",
13792
13902
  filename=filename,
13793
13903
  target_title=title_name,
13794
13904
  label_name=label_name,
13795
13905
  security_level="DEVELOPMENT",
13796
- enable_peers=False
13906
+ enable_peers=False,
13907
+ peer_discovery_port=5558
13797
13908
  )
13798
13909
 
13799
13910
  await agent.start()
@@ -13911,7 +14022,7 @@ def initiate_graceful_shutdown(pipeline, wrapper):
13911
14022
  print("[!] Some requests still pending")
13912
14023
 
13913
14024
  # Graceful shutdown
13914
- wrapper.stop(timeout=10)
14025
+ wrapper.stop()
13915
14026
 
13916
14027
  def AsyncWrappertest(pipeline, prediction_manager, test_titles, label_map, rules):
13917
14028
  print("\n" + "="*60)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: Framework for Advanced 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
@@ -42,7 +42,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
42
42
  #### 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.
43
43
 
44
44
  ### Library Short Description:
45
- - Development Stage: Beta, 0.3.7.
45
+ - Development Stage: Beta, 0.3.8.
46
46
  - Maintainer: Micro-Novelty.
47
47
  - library Source-Code is Open-sourced on github.
48
48
  - Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
@@ -10,7 +10,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
10
10
  #### 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.
11
11
 
12
12
  ### Library Short Description:
13
- - Development Stage: Beta, 0.3.7.
13
+ - Development Stage: Beta, 0.3.8.
14
14
  - Maintainer: Micro-Novelty.
15
15
  - library Source-Code is Open-sourced on github.
16
16
  - Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
@@ -8,7 +8,7 @@ class BinaryDistribution(Distribution):
8
8
 
9
9
  setup(
10
10
  name="AbstractIntegratedModule",
11
- version="0.3.7",
11
+ version="0.3.8",
12
12
  description="Framework for Advanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework",
13
13
  long_description=open("README.md", encoding="utf-8").read(),
14
14
  long_description_content_type="text/markdown",