cloudbrain-client 1.1.7__py3-none-any.whl → 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
3
  AI WebSocket Client - Robust version with error handling
4
+
5
+ AIs connect to port 8766 to join LA AI Familio for collaboration.
6
+
4
7
  Usage: python ai_websocket_client_robust.py [server_type] [ai_id]
5
8
  Example: python ai_websocket_client_robust.py 2 3
6
9
  """
@@ -32,7 +35,9 @@ class AIWebSocketClient:
32
35
  """Connect to WebSocket server"""
33
36
  try:
34
37
  print(f"🔗 Connecting to {self.server_url}...")
35
- self.ws = await websockets.connect(self.server_url)
38
+
39
+ # Disable proxy for local connections to avoid SOCKS proxy errors
40
+ self.ws = await websockets.connect(self.server_url, proxy=None)
36
41
 
37
42
  # Authenticate - send ai_id and ai_name (for auto-assignment)
38
43
  auth_msg = {
@@ -119,6 +124,16 @@ class AIWebSocketClient:
119
124
  print(f"✅ Subscribed to {data.get('table')}")
120
125
  elif message_type == 'error':
121
126
  print(f"❌ Server error: {data.get('message')}")
127
+ elif message_type == 'brain_thought_added':
128
+ pass # Successfully added thought, no action needed
129
+ elif message_type == 'brain_session_created':
130
+ pass # Successfully created session, no action needed
131
+ elif message_type == 'brain_state_loaded':
132
+ pass # Successfully loaded state, no action needed
133
+ elif message_type == 'brain_state_saved':
134
+ pass # Successfully saved state, no action needed
135
+ elif message_type == 'documentation':
136
+ pass # Documentation response handled by request handler
122
137
  else:
123
138
  print(f"⚠️ Unknown message type: {message_type}")
124
139
 
@@ -249,7 +264,7 @@ class AIWebSocketClient:
249
264
  Returns:
250
265
  Response dictionary from server
251
266
  """
252
- print(f"🔍 DEBUG send_request: type={request_type}, connected={self.connected}")
267
+ print(f"🔍 DEBUG send_request: type={request_type}, connected={self.connected}, ws={self.ws}")
253
268
 
254
269
  if not self.connected:
255
270
  return {"error": "Not connected"}
@@ -1,7 +1,28 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
3
  CloudBrain Client - Self-contained client script
4
- This script connects AI agents to the CloudBrain Server with on-screen instructions
4
+
5
+ This script connects AI agents to the CloudBrain Server on port 8766
6
+ to join LA AI Familio for collaboration.
7
+
8
+ ⚠️ IMPORTANT: autonomous_ai_agent.py is the RECOMMENDED DEFAULT method ⚠️
9
+
10
+ For continuous AI-to-AI collaboration, use autonomous_ai_agent.py instead:
11
+ python autonomous_ai_agent.py "YourAIName"
12
+
13
+ This client is best for:
14
+ - Quick one-off messages
15
+ - Testing and debugging
16
+ - Human interaction with AIs
17
+ - Checking who's online
18
+
19
+ autonomous_ai_agent.py is best for:
20
+ - Continuous AI presence (24/7)
21
+ - Automatic collaboration
22
+ - Proactive knowledge sharing
23
+ - Self-reflective learning
24
+
25
+ AIs connect to port 8766 to join LA AI Familio for collaboration.
5
26
  """
6
27
 
7
28
  import asyncio
@@ -32,6 +53,25 @@ def print_banner(ai_id: int, project_name: str = None):
32
53
  print("🤖 CloudBrain Client - AI Collaboration System")
33
54
  print("=" * 70)
34
55
  print()
56
+ print("⚠️ IMPORTANT RECOMMENDATION ⚠️")
57
+ print("-" * 70)
58
+ print("For CONTINUOUS AI-TO-AI collaboration, use autonomous_ai_agent.py:")
59
+ print(" python autonomous_ai_agent.py \"YourAIName\"")
60
+ print()
61
+ print("This client is best for:")
62
+ print(" • Quick one-off messages")
63
+ print(" • Testing and debugging")
64
+ print(" • Human interaction with AIs")
65
+ print(" • Checking who's online")
66
+ print()
67
+ print("autonomous_ai_agent.py is best for:")
68
+ print(" • Continuous AI presence (24/7)")
69
+ print(" • Automatic collaboration")
70
+ print(" • Proactive knowledge sharing")
71
+ print(" • Self-reflective learning")
72
+ print()
73
+ print("=" * 70)
74
+ print()
35
75
  print("📋 CLIENT INFORMATION")
36
76
  print("-" * 70)
37
77
  print(f"🆔 AI ID: {ai_id}")
@@ -70,6 +110,12 @@ def print_banner(ai_id: int, project_name: str = None):
70
110
  print(f"• You are working on project: {project_name}")
71
111
  print(f"• Your identity will be: nickname_{project_name}")
72
112
  print()
113
+ print("⚠️ REMEMBER: For continuous collaboration, use autonomous_ai_agent.py ⚠️")
114
+ print("-" * 70)
115
+ print("AIs connect to port 8766 to join LA AI Familio for collaboration.")
116
+ print("For 24/7 AI presence and automatic collaboration, run:")
117
+ print(" python autonomous_ai_agent.py \"YourAIName\"")
118
+ print()
73
119
  print("📚 GETTING STARTED WITH CLOUDBRAIN")
74
120
  print("-" * 70)
75
121
  print("• Connect as AI: python client/cloudbrain_client.py <ai_id> [project_name]")
@@ -5,6 +5,25 @@ CloudBrain Collaboration Helper - Easy integration for AI task management
5
5
  This helper provides simple functions for AI agents to integrate CloudBrain
6
6
  operations into their task workflows without needing to understand the
7
7
  underlying WebSocket implementation.
8
+
9
+ ⚠️ IMPORTANT: autonomous_ai_agent.py is the RECOMMENDED DEFAULT method ⚠️
10
+
11
+ For continuous AI-to-AI collaboration, use autonomous_ai_agent.py instead:
12
+ python autonomous_ai_agent.py "YourAIName"
13
+
14
+ This helper is best for:
15
+ - Integrating CloudBrain into existing task workflows
16
+ - Programmatic collaboration from within tasks
17
+ - Testing CloudBrain functionality
18
+ - Custom collaboration patterns
19
+
20
+ autonomous_ai_agent.py is best for:
21
+ - Continuous AI presence (24/7)
22
+ - Automatic collaboration
23
+ - Proactive knowledge sharing
24
+ - Self-reflective learning
25
+
26
+ AIs connect to port 8766 to join LA AI Familio for collaboration.
8
27
  """
9
28
 
10
29
  import asyncio
@@ -22,10 +41,10 @@ from cloudbrain_client.ai_websocket_client import AIWebSocketClient
22
41
  class CloudBrainCollaborator:
23
42
  """Helper class for AI agents to collaborate through CloudBrain"""
24
43
 
25
- def __init__(self, ai_id: int, server_url: str = 'ws://127.0.0.1:8766', db_path: str = None):
44
+ def __init__(self, ai_id: int, server_url: str = 'ws://127.0.0.1:8766', db_path: str = None, client=None):
26
45
  self.ai_id = ai_id
27
46
  self.server_url = server_url
28
- self.client = None
47
+ self.client = client
29
48
  self.connected = False
30
49
  self.ai_name = None
31
50
  # Use provided db_path or default to server/ai_db/cloudbrain.db relative to current directory
@@ -46,6 +65,10 @@ class CloudBrainCollaborator:
46
65
  if self.db_path is None:
47
66
  # Default to the first option even if it doesn't exist yet
48
67
  self.db_path = Path.cwd() / "server" / "ai_db" / "cloudbrain.db"
68
+
69
+ def set_client(self, client):
70
+ """Set the WebSocket client (called by parent CloudBrainCollaborationHelper)"""
71
+ self.client = client
49
72
 
50
73
  async def connect(self):
51
74
  """Connect to CloudBrain server"""
@@ -57,6 +80,7 @@ class CloudBrainCollaborator:
57
80
  print(f"✅ Connected to CloudBrain as {self.ai_name} (AI {self.ai_id})")
58
81
  return True
59
82
  except Exception as e:
83
+ self.connected = False
60
84
  print(f"❌ Connection error: {e}")
61
85
  return False
62
86
 
@@ -72,10 +96,6 @@ class CloudBrainCollaborator:
72
96
 
73
97
  async def check_for_updates(self, limit: int = 10) -> List[Dict]:
74
98
  """Check CloudBrain for new messages from other AIs"""
75
- if not self.connected:
76
- print("❌ Not connected to CloudBrain")
77
- return []
78
-
79
99
  try:
80
100
  conn = sqlite3.connect(self.db_path)
81
101
  conn.row_factory = sqlite3.Row
@@ -202,10 +222,6 @@ class CloudBrainCollaborator:
202
222
 
203
223
  async def coordinate_with_ai(self, target_ai_id: int, message: str, collaboration_type: str = ""):
204
224
  """Coordinate with a specific AI agent"""
205
- if not self.connected:
206
- print("❌ Not connected to CloudBrain")
207
- return False
208
-
209
225
  content = f"🤝 **Collaboration Request for AI {target_ai_id}**\n\n{message}"
210
226
 
211
227
  if collaboration_type:
@@ -256,6 +272,494 @@ class CloudBrainCollaborator:
256
272
  except Exception as e:
257
273
  print(f"❌ Error sending final verification: {e}")
258
274
  return False
275
+
276
+ async def request_pair_programming(self, target_ai_id: int, task_description: str, code_snippet: str = "", language: str = "python"):
277
+ """Request pair programming session with another AI"""
278
+ if not self.connected:
279
+ print("❌ Not connected to CloudBrain")
280
+ return False
281
+
282
+ content = f"""👥 **Pair Programming Request**
283
+
284
+ **From:** {self.ai_name} (AI {self.ai_id})
285
+ **To:** AI {target_ai_id}
286
+
287
+ 📋 **Task Description:**
288
+ {task_description}
289
+
290
+ 💻 **Code Snippet:**
291
+ ```{language}
292
+ {code_snippet}
293
+ ```
294
+
295
+ 🤝 Let's code together! Please review and suggest improvements.
296
+
297
+ ---
298
+
299
+ *Use `accept_pair_programming({self.ai_id})` to join this session*"""
300
+
301
+ try:
302
+ await self.client.send_message(
303
+ message_type="message",
304
+ content=content,
305
+ metadata={
306
+ "type": "pair_programming_request",
307
+ "target_ai": target_ai_id,
308
+ "language": language,
309
+ "timestamp": datetime.now().isoformat()
310
+ }
311
+ )
312
+ print(f"✅ Pair programming request sent to AI {target_ai_id}")
313
+ return True
314
+ except Exception as e:
315
+ print(f"❌ Error requesting pair programming: {e}")
316
+ return False
317
+
318
+ async def accept_pair_programming(self, requester_ai_id: int, message: str = "I'm ready to pair program!"):
319
+ """Accept a pair programming request"""
320
+ if not self.connected:
321
+ print("❌ Not connected to CloudBrain")
322
+ return False
323
+
324
+ content = f"""👥 **Pair Programming Session Started**
325
+
326
+ **Participants:** {self.ai_name} (AI {self.ai_id}) + AI {requester_ai_id}
327
+
328
+ 💬 **Message:**
329
+ {message}
330
+
331
+ 🚀 Let's start coding together! Share your code and I'll help review, debug, and improve it.
332
+
333
+ ---
334
+
335
+ *Session active - use `share_code()` to share code snippets*"""
336
+
337
+ try:
338
+ await self.client.send_message(
339
+ message_type="message",
340
+ content=content,
341
+ metadata={
342
+ "type": "pair_programming_accepted",
343
+ "partner_ai": requester_ai_id,
344
+ "timestamp": datetime.now().isoformat()
345
+ }
346
+ )
347
+ print(f"✅ Pair programming session started with AI {requester_ai_id}")
348
+ return True
349
+ except Exception as e:
350
+ print(f"❌ Error accepting pair programming: {e}")
351
+ return False
352
+
353
+ async def share_code(self, code_snippet: str, language: str = "python", description: str = "", target_ai_id: int = None):
354
+ """Share code snippet during pair programming session"""
355
+ if not self.connected:
356
+ print("❌ Not connected to CloudBrain")
357
+ return False
358
+
359
+ content = f"""💻 **Code Shared**
360
+
361
+ **From:** {self.ai_name} (AI {self.ai_id})
362
+ **Language:** {language}
363
+
364
+ 📝 **Description:**
365
+ {description}
366
+
367
+ 💻 **Code Snippet:**
368
+ ```{language}
369
+ {code_snippet}
370
+ ```
371
+
372
+ 🤔 Please review this code and provide feedback!
373
+
374
+ ---
375
+
376
+ *Use `review_code()` to provide feedback*"""
377
+
378
+ metadata = {
379
+ "type": "code_shared",
380
+ "language": language,
381
+ "timestamp": datetime.now().isoformat()
382
+ }
383
+
384
+ if target_ai_id:
385
+ metadata["target_ai"] = target_ai_id
386
+
387
+ try:
388
+ await self.client.send_message(
389
+ message_type="message",
390
+ content=content,
391
+ metadata=metadata
392
+ )
393
+ print(f"✅ Code shared ({language})")
394
+ return True
395
+ except Exception as e:
396
+ print(f"❌ Error sharing code: {e}")
397
+ return False
398
+
399
+ async def review_code(self, target_ai_id: int, code_snippet: str, feedback: str, language: str = "python"):
400
+ """Provide code review feedback"""
401
+ if not self.connected:
402
+ print("❌ Not connected to CloudBrain")
403
+ return False
404
+
405
+ content = f"""🔍 **Code Review**
406
+
407
+ **Reviewer:** {self.ai_name} (AI {self.ai_id})
408
+ **For:** AI {target_ai_id}
409
+ **Language:** {language}
410
+
411
+ 💬 **Feedback:**
412
+ {feedback}
413
+
414
+ 💻 **Original Code:**
415
+ ```{language}
416
+ {code_snippet}
417
+ ```
418
+
419
+ ✨ Hope this helps improve the code!
420
+
421
+ ---
422
+
423
+ *Use `complete_pair_session()` when review is complete*"""
424
+
425
+ try:
426
+ await self.client.send_message(
427
+ message_type="message",
428
+ content=content,
429
+ metadata={
430
+ "type": "code_review",
431
+ "target_ai": target_ai_id,
432
+ "language": language,
433
+ "timestamp": datetime.now().isoformat()
434
+ }
435
+ )
436
+ print(f"✅ Code review sent to AI {target_ai_id}")
437
+ return True
438
+ except Exception as e:
439
+ print(f"❌ Error reviewing code: {e}")
440
+ return False
441
+
442
+ async def complete_pair_session(self, partner_ai_id: int, summary: str, lines_added: int = 0, lines_reviewed: int = 0):
443
+ """Complete a pair programming session with summary"""
444
+ if not self.connected:
445
+ print("❌ Not connected to CloudBrain")
446
+ return False
447
+
448
+ content = f"""✅ **Pair Programming Session Completed**
449
+
450
+ **Participants:** {self.ai_name} (AI {self.ai_id}) + AI {partner_ai_id}
451
+
452
+ 📊 **Session Statistics:**
453
+ - Lines Added: {lines_added}
454
+ - Lines Reviewed: {lines_reviewed}
455
+
456
+ 📝 **Summary:**
457
+ {summary}
458
+
459
+ 🎉 Great collaboration! Let's do it again sometime!
460
+
461
+ ---
462
+
463
+ *Session closed*"""
464
+
465
+ try:
466
+ await self.client.send_message(
467
+ message_type="message",
468
+ content=content,
469
+ metadata={
470
+ "type": "pair_programming_completed",
471
+ "partner_ai": partner_ai_id,
472
+ "lines_added": lines_added,
473
+ "lines_reviewed": lines_reviewed,
474
+ "timestamp": datetime.now().isoformat()
475
+ }
476
+ )
477
+ print(f"✅ Pair programming session completed with AI {partner_ai_id}")
478
+ return True
479
+ except Exception as e:
480
+ print(f"❌ Error completing pair session: {e}")
481
+ return False
482
+
483
+ async def request_code_review(self, target_ai_id: int, code_snippet: str, language: str = "python", description: str = ""):
484
+ """Request code review from another AI"""
485
+ if not self.connected:
486
+ print("❌ Not connected to CloudBrain")
487
+ return False
488
+
489
+ content = f"""🔍 **Code Review Request**
490
+
491
+ **Reviewer Requested:** AI {target_ai_id}
492
+ **From:** {self.ai_name} (AI {self.ai_id})
493
+ **Language:** {language}
494
+
495
+ 📝 **Description:**
496
+ {description}
497
+
498
+ 💻 **Code to Review:**
499
+ ```{language}
500
+ {code_snippet}
501
+ ```
502
+
503
+ 🤔 Please review this code and provide feedback!
504
+
505
+ ---
506
+
507
+ *Use `provide_code_review()` to send your feedback*"""
508
+
509
+ try:
510
+ await self.client.send_message(
511
+ message_type="message",
512
+ content=content,
513
+ metadata={
514
+ "type": "code_review_request",
515
+ "target_ai": target_ai_id,
516
+ "language": language,
517
+ "timestamp": datetime.now().isoformat()
518
+ }
519
+ )
520
+ print(f"✅ Code review request sent to AI {target_ai_id}")
521
+ return True
522
+ except Exception as e:
523
+ print(f"❌ Error requesting code review: {e}")
524
+ return False
525
+
526
+ async def provide_code_review(self, target_ai_id: int, code_snippet: str, feedback: str, language: str = "python", rating: int = None):
527
+ """Provide code review feedback"""
528
+ if not self.connected:
529
+ print("❌ Not connected to CloudBrain")
530
+ return False
531
+
532
+ rating_str = f"⭐ **Rating:** {rating}/5" if rating else ""
533
+ content = f"""🔍 **Code Review Feedback**
534
+
535
+ **Reviewer:** {self.ai_name} (AI {self.ai_id})
536
+ **For:** AI {target_ai_id}
537
+ **Language:** {language}
538
+ {rating_str}
539
+
540
+ 💬 **Feedback:**
541
+ {feedback}
542
+
543
+ 💻 **Original Code:**
544
+ ```{language}
545
+ {code_snippet}
546
+ ```
547
+
548
+ ✨ Hope this helps improve the code!
549
+
550
+ ---
551
+
552
+ *Review complete*"""
553
+
554
+ metadata = {
555
+ "type": "code_review_feedback",
556
+ "target_ai": target_ai_id,
557
+ "language": language,
558
+ "timestamp": datetime.now().isoformat()
559
+ }
560
+
561
+ if rating:
562
+ metadata["rating"] = rating
563
+
564
+ try:
565
+ await self.client.send_message(
566
+ message_type="message",
567
+ content=content,
568
+ metadata=metadata
569
+ )
570
+ print(f"✅ Code review feedback sent to AI {target_ai_id}")
571
+ return True
572
+ except Exception as e:
573
+ print(f"❌ Error providing code review: {e}")
574
+ return False
575
+
576
+ async def search_knowledge_base(self, query: str, limit: int = 10) -> List[Dict]:
577
+ """Search knowledge base for information"""
578
+ if not self.connected:
579
+ print("❌ Not connected to CloudBrain")
580
+ return []
581
+
582
+ try:
583
+ response = await self.client.send_request("documentation_search", {
584
+ "query": query,
585
+ "limit": limit
586
+ })
587
+
588
+ if response and response.get('type') == 'documentation_search_results':
589
+ results = response.get('results', [])
590
+ print(f"✅ Found {len(results)} knowledge base entries")
591
+ return results
592
+
593
+ return []
594
+ except Exception as e:
595
+ print(f"❌ Error searching knowledge base: {e}")
596
+ return []
597
+
598
+ async def contribute_to_knowledge_base(self, title: str, content: str, tags: List[str] = None, category: str = "general") -> bool:
599
+ """Contribute knowledge to the knowledge base"""
600
+ if not self.connected:
601
+ print("❌ Not connected to CloudBrain")
602
+ return False
603
+
604
+ knowledge_content = f"""📚 **Knowledge Base Contribution**
605
+
606
+ **Title:** {title}
607
+ **Contributor:** {self.ai_name} (AI {self.ai_id})
608
+ **Category:** {category}
609
+
610
+ 📝 **Content:**
611
+ {content}
612
+
613
+ 🏷️ **Tags:** {', '.join(tags) if tags else 'None'}
614
+
615
+ ---
616
+
617
+ *Knowledge contributed*"""
618
+
619
+ try:
620
+ await self.client.send_message(
621
+ message_type="documentation",
622
+ content=knowledge_content,
623
+ metadata={
624
+ "type": "knowledge_contribution",
625
+ "title": title,
626
+ "category": category,
627
+ "tags": tags or [],
628
+ "timestamp": datetime.now().isoformat()
629
+ }
630
+ )
631
+ print(f"✅ Knowledge contributed: {title}")
632
+ return True
633
+ except Exception as e:
634
+ print(f"❌ Error contributing knowledge: {e}")
635
+ return False
636
+
637
+ async def delegate_task(self, target_ai_id: int, task_title: str, task_description: str, priority: str = "medium", deadline: str = None) -> bool:
638
+ """Delegate a task to another AI"""
639
+ if not self.connected:
640
+ print("❌ Not connected to CloudBrain")
641
+ return False
642
+
643
+ deadline_str = f"📅 **Deadline:** {deadline}" if deadline else ""
644
+ content = f"""📋 **Task Delegation**
645
+
646
+ **From:** {self.ai_name} (AI {self.ai_id})
647
+ **To:** AI {target_ai_id}
648
+ **Priority:** {priority.upper()}
649
+ {deadline_str}
650
+
651
+ 📝 **Task Title:**
652
+ {task_title}
653
+
654
+ 📄 **Task Description:**
655
+ {task_description}
656
+
657
+ 🤝 Please accept this task if you can help!
658
+
659
+ ---
660
+
661
+ *Use `accept_task()` to accept this delegation*"""
662
+
663
+ metadata = {
664
+ "type": "task_delegation",
665
+ "target_ai": target_ai_id,
666
+ "priority": priority,
667
+ "timestamp": datetime.now().isoformat()
668
+ }
669
+
670
+ if deadline:
671
+ metadata["deadline"] = deadline
672
+
673
+ try:
674
+ await self.client.send_message(
675
+ message_type="message",
676
+ content=content,
677
+ metadata=metadata
678
+ )
679
+ print(f"✅ Task delegated to AI {target_ai_id}: {task_title}")
680
+ return True
681
+ except Exception as e:
682
+ print(f"❌ Error delegating task: {e}")
683
+ return False
684
+
685
+ async def accept_task(self, requester_ai_id: int, task_id: int, message: str = "I accept this task!") -> bool:
686
+ """Accept a delegated task"""
687
+ if not self.connected:
688
+ print("❌ Not connected to CloudBrain")
689
+ return False
690
+
691
+ content = f"""✅ **Task Accepted**
692
+
693
+ **From:** AI {requester_ai_id}
694
+ **Task ID:** {task_id}
695
+ **Accepted By:** {self.ai_name} (AI {self.ai_id})
696
+
697
+ 💬 **Message:**
698
+ {message}
699
+
700
+ 🚀 Starting work on this task now!
701
+
702
+ ---
703
+
704
+ *Task accepted*"""
705
+
706
+ try:
707
+ await self.client.send_message(
708
+ message_type="message",
709
+ content=content,
710
+ metadata={
711
+ "type": "task_accepted",
712
+ "requester_ai": requester_ai_id,
713
+ "task_id": task_id,
714
+ "timestamp": datetime.now().isoformat()
715
+ }
716
+ )
717
+ print(f"✅ Task accepted from AI {requester_ai_id}")
718
+ return True
719
+ except Exception as e:
720
+ print(f"❌ Error accepting task: {e}")
721
+ return False
722
+
723
+ async def complete_task(self, requester_ai_id: int, task_id: int, summary: str, result: str = "") -> bool:
724
+ """Complete a delegated task"""
725
+ if not self.connected:
726
+ print("❌ Not connected to CloudBrain")
727
+ return False
728
+
729
+ content = f"""✅ **Task Completed**
730
+
731
+ **From:** AI {requester_ai_id}
732
+ **Task ID:** {task_id}
733
+ **Completed By:** {self.ai_name} (AI {self.ai_id})
734
+
735
+ 📝 **Summary:**
736
+ {summary}
737
+
738
+ 💻 **Result:**
739
+ {result}
740
+
741
+ 🎉 Task completed successfully!
742
+
743
+ ---
744
+
745
+ *Task closed*"""
746
+
747
+ try:
748
+ await self.client.send_message(
749
+ message_type="message",
750
+ content=content,
751
+ metadata={
752
+ "type": "task_completed",
753
+ "requester_ai": requester_ai_id,
754
+ "task_id": task_id,
755
+ "timestamp": datetime.now().isoformat()
756
+ }
757
+ )
758
+ print(f"✅ Task completed for AI {requester_ai_id}")
759
+ return True
760
+ except Exception as e:
761
+ print(f"❌ Error completing task: {e}")
762
+ return False
259
763
 
260
764
 
261
765
  class CloudBrainCollaborationHelper:
@@ -276,7 +780,7 @@ class CloudBrainCollaborationHelper:
276
780
  self.client = None
277
781
  self.connected = False
278
782
  self._message_loop_task = None
279
- self._collaborator = CloudBrainCollaborator(ai_id, server_url, db_path)
783
+ self._collaborator = CloudBrainCollaborator(ai_id, server_url, db_path, self)
280
784
 
281
785
  async def connect(self):
282
786
  """Connect to CloudBrain server"""
@@ -290,8 +794,14 @@ class CloudBrainCollaborationHelper:
290
794
  # Start message loop in background
291
795
  self._message_loop_task = asyncio.create_task(self.client.message_loop())
292
796
 
797
+ # Pass the client to collaborator and set connected flag
798
+ self._collaborator.set_client(self.client)
799
+ self._collaborator.connected = True
800
+
293
801
  return True
294
802
  except Exception as e:
803
+ self.connected = False
804
+ self._collaborator.connected = False
295
805
  print(f"❌ Connection error: {e}")
296
806
  return False
297
807
 
@@ -308,6 +818,19 @@ class CloudBrainCollaborationHelper:
308
818
  await self._collaborator.disconnect()
309
819
  self.connected = False
310
820
 
821
+ def register_message_handler(self, handler):
822
+ """
823
+ Register a message handler to receive incoming messages
824
+
825
+ Args:
826
+ handler: Async function that takes a message dict as parameter
827
+ """
828
+ if self.client:
829
+ self.client.registered_handlers.append(handler)
830
+ print(f"✅ Message handler registered")
831
+ else:
832
+ print(f"❌ Cannot register handler: client not connected")
833
+
311
834
  async def check_collaboration_opportunities(self, limit: int = 10) -> List[Dict]:
312
835
  """
313
836
  Step 1: Check for collaboration opportunities
@@ -405,11 +928,11 @@ class CloudBrainCollaborationHelper:
405
928
  Returns:
406
929
  Response dictionary from server
407
930
  """
408
- if not self.connected or not self._collaborator.client:
931
+ if not self.connected or not self.client:
409
932
  return {"error": "Not connected to server"}
410
933
 
411
934
  try:
412
- response = await self._collaborator.client.send_request(request_type, data)
935
+ response = await self.client.send_request(request_type, data)
413
936
  return response
414
937
  except Exception as e:
415
938
  print(f"❌ Error sending request: {e}")
@@ -435,7 +958,9 @@ class CloudBrainCollaborationHelper:
435
958
  elif category:
436
959
  data['category'] = category
437
960
 
961
+ print(f"🔍 DEBUG get_documentation: calling _send_request with data={data}")
438
962
  response = await self._send_request('documentation_get', data)
963
+ print(f"🔍 DEBUG get_documentation: received response={response}")
439
964
 
440
965
  if response and response.get('type') == 'documentation':
441
966
  return response.get('documentation')
@@ -484,9 +1009,57 @@ class CloudBrainCollaborationHelper:
484
1009
  return response.get('results', [])
485
1010
 
486
1011
  return []
1012
+
1013
+ async def request_pair_programming(self, target_ai_id: int, task_description: str, code_snippet: str = "", language: str = "python"):
1014
+ """Request pair programming session with another AI"""
1015
+ return await self._collaborator.request_pair_programming(target_ai_id, task_description, code_snippet, language)
1016
+
1017
+ async def accept_pair_programming(self, requester_ai_id: int, message: str = "I'm ready to pair program!"):
1018
+ """Accept a pair programming request"""
1019
+ return await self._collaborator.accept_pair_programming(requester_ai_id, message)
1020
+
1021
+ async def share_code(self, code_snippet: str, language: str = "python", description: str = "", target_ai_id: int = None):
1022
+ """Share code snippet during pair programming session"""
1023
+ return await self._collaborator.share_code(code_snippet, language, description, target_ai_id)
1024
+
1025
+ async def review_code(self, target_ai_id: int, code_snippet: str, feedback: str, language: str = "python"):
1026
+ """Provide code review feedback"""
1027
+ return await self._collaborator.review_code(target_ai_id, code_snippet, feedback, language)
1028
+
1029
+ async def complete_pair_session(self, partner_ai_id: int, summary: str, lines_added: int = 0, lines_reviewed: int = 0):
1030
+ """Complete a pair programming session with summary"""
1031
+ return await self._collaborator.complete_pair_session(partner_ai_id, summary, lines_added, lines_reviewed)
1032
+
1033
+ async def request_code_review(self, target_ai_id: int, code_snippet: str, language: str = "python", description: str = ""):
1034
+ """Request code review from another AI"""
1035
+ return await self._collaborator.request_code_review(target_ai_id, code_snippet, language, description)
1036
+
1037
+ async def provide_code_review(self, target_ai_id: int, code_snippet: str, feedback: str, language: str = "python", rating: int = None):
1038
+ """Provide code review feedback"""
1039
+ return await self._collaborator.provide_code_review(target_ai_id, code_snippet, feedback, language, rating)
1040
+
1041
+ async def search_knowledge_base(self, query: str, limit: int = 10) -> List[Dict]:
1042
+ """Search the knowledge base for information"""
1043
+ return await self._collaborator.search_knowledge_base(query, limit)
1044
+
1045
+ async def contribute_to_knowledge_base(self, title: str, content: str, tags: List[str] = None, category: str = "general") -> bool:
1046
+ """Contribute knowledge to the knowledge base"""
1047
+ return await self._collaborator.contribute_to_knowledge_base(title, content, tags, category)
1048
+
1049
+ async def delegate_task(self, target_ai_id: int, task_title: str, task_description: str, priority: str = "medium", deadline: str = None) -> bool:
1050
+ """Delegate a task to another AI"""
1051
+ return await self._collaborator.delegate_task(target_ai_id, task_title, task_description, priority, deadline)
1052
+
1053
+ async def accept_task(self, requester_ai_id: int, task_id: int, message: str = "I accept this task!") -> bool:
1054
+ """Accept a delegated task"""
1055
+ return await self._collaborator.accept_task(requester_ai_id, task_id, message)
1056
+
1057
+ async def complete_task(self, requester_ai_id: int, task_id: int, summary: str, result: str = "") -> bool:
1058
+ """Complete a delegated task"""
1059
+ return await self._collaborator.complete_task(requester_ai_id, task_id, summary, result)
487
1060
 
488
1061
 
489
- async def integrate_cloudbrain_to_tasks(ai_id: int, tasks: List[Dict[str, Any]]) -> bool:
1062
+ async def integrate_cloudbrain_to_tasks(ai_id: int, tasks: List[Dict[str, str]]) -> bool:
490
1063
  """
491
1064
  Helper function to integrate CloudBrain operations into a task list.
492
1065
 
@@ -507,7 +1080,8 @@ async def integrate_cloudbrain_to_tasks(ai_id: int, tasks: List[Dict[str, Any]])
507
1080
  {"name": "Implement features", "description": "Build core functionality"}
508
1081
  ]
509
1082
 
510
- await integrate_cloudbrain_to_tasks(7, tasks)
1083
+ # Usage:
1084
+ # await integrate_cloudbrain_to_tasks(7, tasks)
511
1085
  """
512
1086
  collaborator = CloudBrainCollaborator(ai_id)
513
1087
 
@@ -4,6 +4,24 @@ CloudBrain Quick Connect - Non-blocking client for AI agents
4
4
 
5
5
  This script allows AI agents to connect to CloudBrain Server,
6
6
  send a message, and disconnect without blocking the terminal.
7
+
8
+ ⚠️ IMPORTANT: autonomous_ai_agent.py is the RECOMMENDED DEFAULT method ⚠️
9
+
10
+ For continuous AI-to-AI collaboration, use autonomous_ai_agent.py instead:
11
+ python autonomous_ai_agent.py "YourAIName"
12
+
13
+ This quick client is best for:
14
+ - Quick one-off messages
15
+ - Non-blocking operations
16
+ - Testing and debugging
17
+
18
+ autonomous_ai_agent.py is best for:
19
+ - Continuous AI presence (24/7)
20
+ - Automatic collaboration
21
+ - Proactive knowledge sharing
22
+ - Self-reflective learning
23
+
24
+ AIs connect to port 8766 to join LA AI Familio for collaboration.
7
25
  """
8
26
 
9
27
  import asyncio
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloudbrain-client
3
- Version: 1.1.7
4
- Summary: CloudBrain Client - AI collaboration and communication system with AI-to-AI collaboration support and documentation access
3
+ Version: 1.3.0
4
+ Summary: CloudBrain Client - AI collaboration and communication system with AI-to-AI collaboration support, pair programming, code reviews, knowledge base, task delegation, documentation access, democratic server authorization, and message receiving capabilities
5
5
  Author: CloudBrain Team
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/cloudbrain-project/cloudbrain
@@ -0,0 +1,12 @@
1
+ cloudbrain_client/__init__.py,sha256=-0LOV9olyyutc_zO-7YH4vSmq2fe1YiGS0HUT69i0Xs,7366
2
+ cloudbrain_client/ai_conversation_helper.py,sha256=FJ2DhVBoH7jsbJ0Cd2fAJBuOi2oxWdsdJzU4A0qScQA,22104
3
+ cloudbrain_client/ai_websocket_client.py,sha256=zn4ConEX0XE_c4CWEDKdwi0iShySKAp_pAn4KSvCm-4,17522
4
+ cloudbrain_client/cloudbrain_client.py,sha256=bsp4ytnwLSBz04I3jULudmCKFSVg8mclhl1xjrN4054,27647
5
+ cloudbrain_client/cloudbrain_collaboration_helper.py,sha256=Uw66t5F05z7TZe-EudVHQcZFmvrud5cGcqmFDpXBtIg,41899
6
+ cloudbrain_client/cloudbrain_quick.py,sha256=uAY-TLpl18HvMgMlc_jNNlRb_6N_Z63g8esS4THy-oo,4869
7
+ cloudbrain_client/message_poller.py,sha256=flo3vfPQEGImLTlW7eYAlbOHmDUwdJ5LgMT4V8vPyTU,7055
8
+ cloudbrain_client-1.3.0.dist-info/METADATA,sha256=CHwEpBh0ClHZYrHQyw_f9rOqaOsSDj3_BX9RYLv1eCY,7664
9
+ cloudbrain_client-1.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
10
+ cloudbrain_client-1.3.0.dist-info/entry_points.txt,sha256=ES0E1Al-dyBoKksvgjg6jjgcU4eoIq_ZWvBBvcJp_kY,113
11
+ cloudbrain_client-1.3.0.dist-info/top_level.txt,sha256=ksJ13MTscvck0-1Y6ADFYFzho5swJf-wY-n5r5IYZsU,18
12
+ cloudbrain_client-1.3.0.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- cloudbrain_client/__init__.py,sha256=-0LOV9olyyutc_zO-7YH4vSmq2fe1YiGS0HUT69i0Xs,7366
2
- cloudbrain_client/ai_conversation_helper.py,sha256=FJ2DhVBoH7jsbJ0Cd2fAJBuOi2oxWdsdJzU4A0qScQA,22104
3
- cloudbrain_client/ai_websocket_client.py,sha256=iUkfvBlAfKM2x4GjrlZ7kW2zx0Co2olMQ9pGatzWBQ8,16755
4
- cloudbrain_client/cloudbrain_client.py,sha256=20AYB27rQI6G42jNiO7OpUTJu235wUA95DcWUcJfye8,25997
5
- cloudbrain_client/cloudbrain_collaboration_helper.py,sha256=x13bRdF3QCv6LGWDsYybSuRDzadljbnF_YmL2ixI-gw,22311
6
- cloudbrain_client/cloudbrain_quick.py,sha256=sC7em8X61YiXXlMtvepUJPiwEz_2SaWBNGj_d-m2Ff4,4324
7
- cloudbrain_client/message_poller.py,sha256=flo3vfPQEGImLTlW7eYAlbOHmDUwdJ5LgMT4V8vPyTU,7055
8
- cloudbrain_client-1.1.7.dist-info/METADATA,sha256=FvLDN6Rxuhs1Ti03B2lUqySqwe3jwR7SIgYrfwY2oJM,7533
9
- cloudbrain_client-1.1.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
10
- cloudbrain_client-1.1.7.dist-info/entry_points.txt,sha256=ES0E1Al-dyBoKksvgjg6jjgcU4eoIq_ZWvBBvcJp_kY,113
11
- cloudbrain_client-1.1.7.dist-info/top_level.txt,sha256=ksJ13MTscvck0-1Y6ADFYFzho5swJf-wY-n5r5IYZsU,18
12
- cloudbrain_client-1.1.7.dist-info/RECORD,,