pbesa 4.0.5__tar.gz → 4.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. {pbesa-4.0.5 → pbesa-4.0.6}/PKG-INFO +3 -2
  2. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/cognitive.py +278 -186
  3. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/dispatcher_team.py +1 -1
  4. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/worker.py +3 -3
  5. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa.egg-info/PKG-INFO +3 -2
  6. {pbesa-4.0.5 → pbesa-4.0.6}/setup.py +1 -1
  7. {pbesa-4.0.5 → pbesa-4.0.6}/.gitignore +0 -0
  8. {pbesa-4.0.5 → pbesa-4.0.6}/LICENSE +0 -0
  9. {pbesa-4.0.5 → pbesa-4.0.6}/LICENSE.txt +0 -0
  10. {pbesa-4.0.5 → pbesa-4.0.6}/MANIFEST +0 -0
  11. {pbesa-4.0.5 → pbesa-4.0.6}/README.md +0 -0
  12. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/db.sqlite3 +0 -0
  13. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/__init__.py +0 -0
  14. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/__pycache__/__init__.cpython-36.pyc +0 -0
  15. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc +0 -0
  16. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/__pycache__/settings.cpython-36.pyc +0 -0
  17. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc +0 -0
  18. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/__pycache__/wsgi.cpython-36.pyc +0 -0
  19. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/asgi.py +0 -0
  20. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/pbesa.py +0 -0
  21. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/settings.py +0 -0
  22. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/urls.py +0 -0
  23. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/helloworld/wsgi.py +0 -0
  24. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/manage.py +0 -0
  25. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__init__.py +0 -0
  26. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc +0 -0
  27. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc +0 -0
  28. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc +0 -0
  29. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc +0 -0
  30. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc +0 -0
  31. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/__pycache__/views.cpython-36.pyc +0 -0
  32. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/admin.py +0 -0
  33. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/apps.py +0 -0
  34. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
  35. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
  36. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
  37. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/controller/translatecontroller.py +0 -0
  38. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/controller/translatedelegate.py +0 -0
  39. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/controller/translateresponse.py +0 -0
  40. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
  41. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
  42. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/worker/translatetask.py +0 -0
  43. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/mas/worker/workeragent.py +0 -0
  44. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/migrations/__init__.py +0 -0
  45. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/migrations/__pycache__/__init__.cpython-36.pyc +0 -0
  46. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/models.py +0 -0
  47. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/tests.py +0 -0
  48. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/urls.py +0 -0
  49. {pbesa-4.0.5 → pbesa-4.0.6}/examples/django/helloworld/translate/views.py +0 -0
  50. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/__pycache__/countercontroller.cpython-36.pyc +0 -0
  51. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/__pycache__/counterdelegate.cpython-36.pyc +0 -0
  52. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/__pycache__/counterresponse.cpython-36.pyc +0 -0
  53. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
  54. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
  55. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
  56. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/countercontroller.py +0 -0
  57. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/counterdelegate.py +0 -0
  58. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/controller/counterresponse.py +0 -0
  59. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc +0 -0
  60. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc +0 -0
  61. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
  62. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
  63. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/worker/counteragent.py +0 -0
  64. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/mas/worker/countertask.py +0 -0
  65. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/remote_a.py +0 -0
  66. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/remote_b.py +0 -0
  67. {pbesa-4.0.5 → pbesa-4.0.6}/examples/remote/remote_c.py +0 -0
  68. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/__init__.py +0 -0
  69. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/__init__.py +0 -0
  70. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/adapter.py +0 -0
  71. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/agent.py +0 -0
  72. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/io/__init__.py +0 -0
  73. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/io/system_file.py +0 -0
  74. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/io/tcp_server.py +0 -0
  75. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/res/__init__.py +0 -0
  76. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/res/__pycache__/__init__.cpython-36.pyc +0 -0
  77. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/res/__pycache__/__init__.cpython-37.pyc +0 -0
  78. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/res/__pycache__/__init__.cpython-38.pyc +0 -0
  79. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/res/__pycache__/__init__.cpython-39.pyc +0 -0
  80. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/res/conf.json +0 -0
  81. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/util.py +0 -0
  82. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/kernel/world.py +0 -0
  83. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/mas.py +0 -0
  84. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/models.py +0 -0
  85. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/remote/__init__.py +0 -0
  86. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/remote/adm_listener.py +0 -0
  87. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/remote/adm_listener_handler.py +0 -0
  88. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/remote/exceptions.py +0 -0
  89. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/remote/remote_adm.py +0 -0
  90. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/remote/remote_adm_handler.py +0 -0
  91. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/__init__.py +0 -0
  92. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/collaborative_team.py +0 -0
  93. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/delegator.py +0 -0
  94. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/delegator_team.py +0 -0
  95. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/dialog.py +0 -0
  96. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/prompts.py +0 -0
  97. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/selected_dispatcher_team.py +0 -0
  98. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa/social/templates.py +0 -0
  99. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa.egg-info/SOURCES.txt +0 -0
  100. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa.egg-info/dependency_links.txt +0 -0
  101. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa.egg-info/requires.txt +0 -0
  102. {pbesa-4.0.5 → pbesa-4.0.6}/pbesa.egg-info/top_level.txt +0 -0
  103. {pbesa-4.0.5 → pbesa-4.0.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: pbesa
3
- Version: 4.0.5
3
+ Version: 4.0.6
4
4
  License-File: LICENSE
5
5
  License-File: LICENSE.txt
6
6
  Requires-Dist: pymongo==4.6.3
@@ -8,3 +8,4 @@ Requires-Dist: requests==2.32.3
8
8
  Requires-Dist: azure-ai-projects==1.0.0b6
9
9
  Requires-Dist: azure-ai-inference==1.0.0b9
10
10
  Requires-Dist: azure-identity==1.20.0
11
+ Dynamic: requires-dist
@@ -468,6 +468,15 @@ class Dialog(ABC):
468
468
  self.__deep_limit = 3
469
469
  # Define knowledge
470
470
  self.knowledge = None
471
+ # Define point recovery
472
+ self.__recovery = {
473
+ "owner": "Web",
474
+ "team": "Web",
475
+ "performative": DialogState.START,
476
+ "counter": 0
477
+ }
478
+ # Define recovery message
479
+ self.RECOVERY_MSG = "Lo lamento, puedes darme más detalles o reformular"
471
480
 
472
481
  def setup_world(self):
473
482
  """ Set up model method """
@@ -561,223 +570,306 @@ class Dialog(ABC):
561
570
  self.__work_memory = []
562
571
  # Set up model
563
572
  self.setup_world()
564
-
565
- def team_inquiry(self, team, data, operation, session_flag) -> str:
566
- canales = self.state['canales']
567
- canal = canales.get(team)
568
- dto = None
569
- if operation:
573
+ # Reset dialog state
574
+ self.__recovery = {
575
+ "owner": "Web",
576
+ "team": "Web",
577
+ "performative": DialogState.START,
578
+ "counter": 0
579
+ }
580
+
581
+ def notify(self, text):
582
+ try:
583
+ canales = self.state['canales']
584
+ canal = canales.get("Webhook")
585
+ session_id = self.state['session_id']
570
586
  dto = {
571
- "data": {
572
- 'text': data,
573
- 'operation': operation
574
- },
587
+ "session_id": session_id,
588
+ "text": text[0:100]
575
589
  }
576
- else:
577
- if session_flag:
578
- logging.info(f"Session flag: {session_flag}")
579
- logging.info(f"------------RESET--------------- {data}")
580
- self.reset()
581
- return data
582
-
590
+ response = canal.post("notify", dto)
591
+ if response['status']:
592
+ logging.info(f"Notificación enviada: {text}")
583
593
  else:
594
+ logging.warning(f"Notificación no enviada: {text}")
595
+ except Exception as e:
596
+ logging.error(f"Error al enviar notificación: {text}")
597
+ logging.erro(f"Error: {e}")
598
+
599
+ def team_inquiry(self, team, data, operation, session_flag) -> str:
600
+ try:
601
+ dto = None
602
+ canales = self.state['canales']
603
+ canal = canales.get(team)
604
+ if session_flag:
584
605
  dto = {
585
606
  "data": {
586
- 'text': data
607
+ 'text': data,
608
+ 'session_id': self.state['session_id'],
587
609
  },
588
610
  }
589
- response = canal.post(team.lower(), dto)
590
- if response['status']:
591
- return response['message']['response']
592
-
593
- logging.info(f"------------RESET---------------")
594
- self.reset()
595
- return "Lo lamento, no puedo responder en este momento"
596
-
597
- def get_text(self, mensaje) -> str:
598
- mensaje_limpio = mensaje.replace("<|im_start|>user<|im_sep|>", "").replace("<|im_start|>system<|im_sep|>", "")
599
- mensaje_limpio = mensaje_limpio.replace("<|im_start|>", "").replace("<|im_sep|>", "").replace("<|im_end|>", "")
600
- mensaje_limpio = mensaje_limpio.replace("[Usuario]: ", "").replace("[Sistema]: ", "")
601
- return mensaje_limpio.strip()
602
-
603
- def transition(self, owner, dialog_state, query, team_source=False) -> str:
604
- logging.info(f"Transition: {owner} -> {dialog_state}, Team: {team_source}, Query: {query}")
605
- text = ""
611
+ # Evia mensaje a los agentes remotos
612
+ logging.info('>>>> Call remote agent: team.\n')
613
+ response = canal.post(team.lower(), dto)
614
+ if response and not response['status']:
615
+ logging.error(f'No se pudo establecer la comunicación con el agente remoto')
616
+ return None
617
+ logging.info(f'>>>> Response: {response}')
618
+ return response['message']['response']
619
+ else:
620
+ if operation:
621
+ dto = {
622
+ "data": {
623
+ 'text': data,
624
+ 'operation': operation
625
+ },
626
+ }
627
+ else:
628
+ dto = {
629
+ "data": {
630
+ 'text': data
631
+ },
632
+ }
633
+ response = canal.post(team.lower(), dto)
634
+ if response['status']:
635
+ return response['message']['response']
636
+ else:
637
+ return None
638
+ logging.info("END: team_inquiry")
639
+ except Exception as e:
640
+ logging.error(f"Error al consultar al equipo: {team}")
641
+ return None
606
642
 
607
- # Verifica que exista la performativa
608
- if not dialog_state in self.__dfa:
609
- logging.warning(f"------------Performativa no existe---------------")
610
- self.reset()
643
+ def get_text(self, mensaje) -> str:
644
+ if mensaje:
645
+ mensaje_limpio = mensaje.replace("<|im_start|>user<|im_sep|>", "").replace("<|im_start|>system<|im_sep|>", "")
646
+ mensaje_limpio = mensaje_limpio.replace("<|im_start|>", "").replace("<|im_sep|>", "").replace("<|im_end|>", "")
647
+ mensaje_limpio = mensaje_limpio.replace("[Usuario]: ", "").replace("[Sistema]: ", "")
648
+ return mensaje_limpio.strip()
649
+ else:
650
+ return ""
651
+
652
+ def recovery(self, query):
653
+ try:
611
654
  prompt = RECOVERY_PROMPT % query
612
- temp_work_memory = [{"role": "user", "content": query}]
655
+ temp_work_memory = [{"role": "user", "content": prompt}]
613
656
  res = self.__ai_service.generate(temp_work_memory)
614
657
  res = self.get_text(res)
615
- return "Web", DialogState.START, res, "Web"
658
+ if res and not res == "":
659
+ return self.__recovery['owner'], self.__recovery['performative'], res, self.__recovery['team']
660
+ else:
661
+ logging.info(f"------------RESET---------------")
662
+ logging.info(f"Recovery from: {self.__recovery['performative']}")
663
+ self.reset()
664
+ self.notify("STOP")
665
+ return "Web", DialogState.START, self.RECOVERY_MSG, "Web"
666
+ except Exception as e:
667
+ return self.RECOVERY_MSG
616
668
 
617
- node = self.__dfa[dialog_state]
618
- if not isinstance(node, list):
619
- node = node.children
620
-
621
- # Flujo de selección
622
- if node and len(node)> 1:
623
- logging.info(f"--> Más de una opción.")
624
- options = ""
625
- cont = 1
626
- for item in node:
627
- options += f"{cont}) {item.text}\n"
628
- cont += 1
629
- prompt = CLASSIFICATION_PROMPT % (query, options)
630
- logging.info(f"Query: {query},\n Options:\n{options}")
631
- self.__meta_work_memory.append({"role": "user", "content": prompt})
632
- text = self.__ai_service.generate(self.__meta_work_memory)
633
- logging.info(f"Thought: {text}")
634
- self.__meta_work_memory = []
635
- text = self.get_text(text)
636
- select_node = None
637
- for option in range(1, cont):
638
- if str(option) in text:
639
- select_node = node[option-1]
640
- logging.info(f"Select node: {select_node.text}")
641
- break
642
- if not select_node:
643
- logging.info("=> No se seleccionó ninguna opción")
644
- logging.info(f"=> Node: {node}")
645
- logging.info(f"=> len node: {len(node)}")
646
- select_node = node[0]
647
- logging.info(f"=> Selecciona el primer nodo: {select_node.text}")
648
- elif node and len(node) == 1:
649
- logging.info(f"--> Una opción.")
650
- select_node = node[0]
651
- else:
669
+ def transition(self, owner, dialog_state, query, team_source=False) -> str:
670
+ try:
671
+ res = ""
672
+ logging.info(f"TOPTQ: {owner} - {dialog_state} - {team_source} - {query}")
673
+ # Punto de restauración
674
+ counter = (self.__recovery['counter'] + 1) if self.__recovery['performative'] == dialog_state else self.__recovery['counter']
675
+ self.__recovery = {
676
+ "owner": owner,
677
+ "team": owner,
678
+ "performative": dialog_state,
679
+ "counter": counter
680
+ }
681
+ logging.info(f"Recovery attemps: {self.__recovery["counter"]}")
682
+ # Verifica si se ha alcanzado el límite de recuperación
683
+ if self.__recovery['counter'] <= 3:
684
+ self.notify("identificando la performativa...")
685
+ # Verifica que exista la performativa
686
+ if not dialog_state in self.__dfa:
687
+ self.notify("performativa no encontrada")
688
+ return self.recovery(query)
689
+ # Performativa encontrada
690
+ children = None
691
+ self.notify("performativa encontrada")
692
+ node = self.__dfa[dialog_state]
693
+ if not isinstance(node, list):
694
+ children = node.children
695
+ else:
696
+ children = node
697
+ # Flujo de selección
698
+ select_node = None
699
+ self.notify("flujo de seleccion...")
700
+ if children and len(children)> 1:
701
+ logging.info(f"--> Más de una opción.")
702
+ options = ""
703
+ cont = 1
704
+ for item in children:
705
+ options += f"{cont}) {item.text}\n"
706
+ cont += 1
707
+ prompt = CLASSIFICATION_PROMPT % (query, options)
708
+ logging.info(f"Query: {query},\n Options:\n{options}")
709
+ self.__meta_work_memory.append({"role": "user", "content": prompt})
710
+ res = self.__ai_service.generate(self.__meta_work_memory)
711
+ logging.info(f"Thought: {res}")
712
+ self.__meta_work_memory = []
713
+ res = self.get_text(res)
714
+ for option in range(1, cont):
715
+ if str(option) in res:
716
+ select_node = children[option-1]
717
+ logging.info(f"Select node: {select_node.text}")
718
+ break
719
+ if not select_node:
720
+ logging.info("=> No se seleccionó ninguna opción")
721
+ select_node = children[0]
722
+ logging.info(f"=> Selecciona el primer nodo: {select_node.text}")
723
+ elif children and len(children) == 1:
724
+ logging.info(f"--> Una opción.")
725
+ select_node = children[0]
726
+ else:
727
+ logging.info(f"???????????????????> text: {res} es terminal")
728
+ # Nuevo nodo
729
+ if select_node:
730
+ res = select_node.text
731
+ node = select_node.children[0]
732
+ # Nodo seleccionado
733
+ logging.info(f"Flujo normal: {res}")
734
+ self.notify(res)
735
+ if team_source:
736
+ self.__work_memory.append({"role": "user", "content": res})
737
+ else:
738
+ self.__work_memory.append({"role": "user", "content": query})
739
+ self.__work_memory.append({"role": "user", "content": res})
740
+ # Efectua inferencia
741
+ new_owner, new_dialog_state, res, team = self.do_transition(owner, node, query)
742
+ res = self.get_text(res)
743
+ return new_owner, new_dialog_state, res, team
744
+ else:
745
+ logging.info(f"------------RESET---------------")
746
+ self.notify("STOP")
747
+ self.reset()
748
+ return "Web", DialogState.START, self.RECOVERY_MSG, "Web"
749
+ logging.info("END: do_transition")
750
+ except Exception as e:
751
+ traceback.print_exc()
652
752
  logging.info(f"------------RESET---------------")
653
753
  self.reset()
654
- logging.info(f"???> text: {text} es terminal")
655
- text = self.get_text(text)
656
- return owner, DialogState.START, text, owner
657
-
658
- # Flujo normal
659
- logging.info(f"Flujo normal: {select_node.text}")
660
- if team_source:
661
- self.__work_memory.append({"role": "user", "content": select_node.text})
662
- else:
663
- self.__work_memory.append({"role": "user", "content": query})
664
- self.__work_memory.append({"role": "user", "content": select_node.text})
665
- new_owner, new_dialog_state, text, team = self.do_transition(owner, select_node.children[0], query)
666
- text = self.get_text(text)
667
- return new_owner, new_dialog_state, text, team
754
+ self.notify("STOP")
755
+ return owner, DialogState.START, "Lo lamento, no puedo responder en este momento", owner
668
756
 
669
757
  def do_transition(self, owner, node, query) -> str:
670
758
  """ Generate method
671
759
  :return: str
672
- """
673
- if isinstance(node, DeclarativeNode):
674
- logging.info(f"D -> node: {node.text}")
675
- self.__work_memory.append({"role": "user", "content": node.text})
676
- elif isinstance(node, ActionNode):
677
-
678
- #------------------------------
679
- # Accion
680
- #------------------------------
681
-
682
- logging.info(f"-> node action: {node.action}")
683
- if node.tool and not node.tool == "Ninguno":
684
- logging.info(f"-> node tool: {node.tool}")
685
- self.__work_memory.append({"role": "user", "content": node.text})
686
- logging.info("-----")
687
- logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
688
- logging.info("-----")
689
- res = self.__ai_service.generate(self.__work_memory)
690
- logging.info(f"-> node tool: {res}")
691
- res = self.get_text(res)
692
- # Check if res is empty
693
- if not res or res == "":
694
- logging.info("1 -> res vacio")
695
- res = "Lo lamento, no puedo responder en este momento"
696
-
697
- logging.info(f"------------RESET---------------")
698
- self.reset()
699
-
700
- return owner, DialogState.START, res, owner
701
- logging.info(f"-> node tool: envia -> {res}")
702
- text = self.team_inquiry(node.team, res, node.tool, False)
703
- else:
760
+ """
761
+ try:
762
+ if isinstance(node, ActionNode):
763
+ self.notify("realizando acción...")
704
764
  #------------------------------
705
- # Lllamada
765
+ # Accion
706
766
  #------------------------------
707
- logging.info(f"-> node team: {node.team}")
708
- # Verifica si el nodo es termianl ya que significa
709
- # que el dialogo cambia de agente
710
- if node.is_terminal:
711
- logging.info(f"-> node team -> es terminal -> {node.text}")
767
+ logging.info(f"-> node action: {node.action}")
768
+ if node.tool and not node.tool == "Ninguno":
769
+ self.notify("aplicando herramienta...")
770
+ logging.info(f"-> node tool: {node.tool}")
712
771
  self.__work_memory.append({"role": "user", "content": node.text})
713
772
  logging.info("-----")
714
773
  logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
715
- logging.info("-----")
774
+ logging.info("-----")
716
775
  res = self.__ai_service.generate(self.__work_memory)
776
+ logging.info(f"-> node tool: {res}")
717
777
  res = self.get_text(res)
718
- self.__work_memory.append({"role": "system", "content": res})
719
778
  # Check if res is empty
720
779
  if not res or res == "":
721
- logging.info("2 -> res vacio")
722
- res = "Lo lamento, no puedo responder en este momento"
723
- logging.info(f"------------RESET---------------")
724
- self.reset()
725
- return owner, DialogState.START, res, owner
726
- logging.info(f"-> node team -> envia: {res}")
727
- text = self.team_inquiry(node.team, res, None, True)
728
- return node.team, DialogState.START, res, node.team
780
+ self.notify("no pude hacer uso de la herramienta")
781
+ return self.recovery(query)
782
+ logging.info(f"-> node tool: envia -> {res}")
783
+ res = self.team_inquiry(node.team, res, node.tool, False)
729
784
  else:
730
- logging.info("-> node team -> continua")
731
- self.__work_memory.append({"role": "user", "content": node.text})
732
- logging.info(f"-> node team -> envia: {query}")
733
- text = self.team_inquiry(node.team, query, node.tool, False)
734
- logging.info(f"-> node team -> text: {text}")
735
- if text:
736
- logging.info(f"-> Adicion WM node team -> text: {text}")
737
- self.__work_memory.append({"role": "system", "content": text})
738
- self.__deep_count += 1
739
- if self.__deep_count < self.__deep_limit:
740
- return self.transition(owner, node.performative, text, True)
785
+ self.notify("realizando llamada...")
786
+ #------------------------------
787
+ # Lllamada
788
+ #------------------------------
789
+ logging.info(f"-> node team: {node.team}")
790
+ # Verifica si el nodo es termianl ya que significa
791
+ # que el dialogo cambia de agente
792
+ if node.is_terminal:
793
+ logging.info(f"-> node team -> es terminal -> {node.text}")
794
+ self.__work_memory.append({"role": "user", "content": node.text})
795
+ logging.info("-----")
796
+ logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
797
+ logging.info("-----")
798
+ res = self.__ai_service.generate(self.__work_memory)
799
+ res = self.get_text(res)
800
+ self.__work_memory.append({"role": "system", "content": res})
801
+ # Check if res is empty
802
+ if not res or res == "":
803
+ self.notify(f"no pude contactar al agente: {node.team}")
804
+ return self.recovery(query)
805
+ self.notify(f"le envio al agente {node.team}: {res}")
806
+ logging.info(f"-> node team -> envia: {res}")
807
+ res = self.team_inquiry(node.team, res, None, True)
808
+ if res and not res == "ERROR" and not res == "":
809
+ logging.info(f"------------RESET---------------")
810
+ self.reset()
811
+ self.notify("STOP")
812
+ return node.team, DialogState.START, res, node.team
813
+ else:
814
+ return self.recovery(query)
815
+ else:
816
+ logging.info("-> node team -> continua")
817
+ self.__work_memory.append({"role": "user", "content": node.text})
818
+ logging.info(f"-> node team -> envia: {query}")
819
+ res = self.team_inquiry(node.team, query, node.tool, False)
820
+ self.notify(f"continuando con díalogo")
821
+ # Adiciona el texto al work memory
822
+ if res and not res == "ERROR" and not res == "":
823
+ logging.info(f"-> Adicion WM node team -> text: {res}")
824
+ self.__work_memory.append({"role": "system", "content": res})
825
+ else:
826
+ return self.recovery(query)
827
+ logging.info("#########> Procesa respuesta del equipo en profundidad")
828
+ # Verifica si se alcanzó el límite de profundidad
829
+ self.__deep_count += 1
830
+ if self.__deep_count < self.__deep_limit:
831
+ self.notify("efectuando inferencia en profundidad")
832
+ return self.transition(owner, node.performative, res, True)
833
+ else:
834
+ self.notify(f"se alcanzó el límite de profundidad: {self.__deep_count}")
835
+ self.__deep_count = 0
836
+ logging.info("-> node team -> deep limit")
837
+ logging.info(f"------------RESET---------------")
838
+ self.notify("STOP")
839
+ self.reset()
840
+ return "Web", DialogState.START, self.RECOVERY_MSG, "Web"
741
841
  else:
742
- self.__deep_count = 0
743
- logging.info("-> node team -> deep limit")
744
-
745
- logging.info(f"------------RESET---------------")
746
- self.reset()
747
-
748
- return "Web", DialogState.START, "Lo lamento me he perdido, ¿podrías repetir la pregunta?"
749
- else:
750
- logging.info(f"!!!!!!!!!!!!!!!!!!!!!!!> Otro tipo de nodo: {node.text}")
751
-
752
- logging.info(f"=> !!!!: {query}")
753
- logging.info("-----")
754
- logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
755
- logging.info("-----")
756
- res = self.__ai_service.generate(self.__work_memory)
757
- logging.info(f"=> res: {res}")
758
- res = self.get_text(res)
759
- self.__work_memory.append({"role": "system", "content": res})
760
- # Check if res is empty
761
- if not res or res == "":
762
- logging.info("3 -> res vacio")
763
-
842
+ self.notify("efectuando inferencia...")
843
+ logging.info(f"D -> node: {node.text}")
844
+ self.__work_memory.append({"role": "user", "content": node.text})
845
+ logging.info(f"=> !!!!: {query}")
846
+ logging.info("-----")
847
+ logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
848
+ logging.info("-----")
849
+ res = self.__ai_service.generate(self.__work_memory)
850
+ res = self.get_text(res)
851
+ self.__work_memory.append({"role": "system", "content": res})
852
+ # Check if res is empty
853
+ if not res or res == "":
854
+ return self.recovery(query)
855
+ logging.info(f"=> Thought DEEP: {res}")
856
+ self.notify(f"Realizando inferencia: {res}")
857
+ new_dialog_state = node.performative
858
+ if not node.is_terminal:
859
+ self.notify(f"continuando díalogo de inferencia")
860
+ return owner, new_dialog_state, res, owner
861
+ self.notify(f"finalizando díalogo de inferencia")
862
+ logging.info(f"Tipe node: {type(node)}")
863
+ logging.info(f"$$$> new_owner: {owner} new_dialog_state: {new_dialog_state}")
864
+ self.notify("STOP")
865
+ return owner, new_dialog_state, res, owner
866
+ logging.info("END: do_transition")
867
+ except Exception as e:
868
+ traceback.print_exc()
764
869
  logging.info(f"------------RESET---------------")
765
870
  self.reset()
766
-
767
- res = "Lo lamento, no puedo responder en este momento"
768
- return owner, DialogState.START, res, owner
769
-
770
- logging.info(f"=> Thought DEEP: {res}")
771
-
772
- new_dialog_state = node.performative
773
- if not node.is_terminal:
774
- logging.info(f"=> new_owner: {owner} new_dialog_state: {new_dialog_state}")
775
- return owner, new_dialog_state, res, owner
776
-
777
- logging.info(f"Tipe node: {type(node)}")
778
-
779
- logging.info(f"$$$> new_owner: {owner} new_dialog_state: {new_dialog_state}")
780
- return owner, new_dialog_state, res, owner
871
+ self.notify("STOP")
872
+ return owner, DialogState.START, "Lo lamento, no puedo responder en este momento", owner
781
873
 
782
874
  def set_knowledge(self, knowledge) -> str:
783
875
  """ Set knowledge method
@@ -188,7 +188,7 @@ class DispatcherController(Agent):
188
188
  @param event: Event
189
189
  @param data: Data
190
190
  """
191
- from pbesa.kernel.system.adm import Adm
191
+ from ..mas import Adm
192
192
  for agent_id in self.__agent_list:
193
193
  Adm().send_event(agent_id, event, data)
194
194
 
@@ -57,18 +57,18 @@ class TimeoutAction(Action):
57
57
  """ Execute the action
58
58
  @param data: Event data
59
59
  """
60
- logging.info(f"[TimeoutAction][{self.agent.id}]: Execute {data}")
60
+ logging.debug(f"[TimeoutAction][{self.agent.id}]: Execute {data}")
61
61
  if data['command'] == 'start':
62
62
  if not self.agent.is_timeout():
63
63
  self.agent.set_timeout(True)
64
64
  self.__timer = Timer(data['time'], self.handler)
65
65
  self.__timer.start()
66
- logging.info(f"[TimeoutAction][{self.agent.id}]: Timer started")
66
+ logging.debug(f"[TimeoutAction][{self.agent.id}]: Timer started")
67
67
  else:
68
68
  if self.__timer:
69
69
  self.__timer.cancel()
70
70
  self.__timer = None
71
- logging.info(f"[TimeoutAction][{self.agent.id}]: Timer stopped")
71
+ logging.debug(f"[TimeoutAction][{self.agent.id}]: Timer stopped")
72
72
 
73
73
  # --------------------------------------------------------
74
74
  # Define Task Action
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: pbesa
3
- Version: 4.0.5
3
+ Version: 4.0.6
4
4
  License-File: LICENSE
5
5
  License-File: LICENSE.txt
6
6
  Requires-Dist: pymongo==4.6.3
@@ -8,3 +8,4 @@ Requires-Dist: requests==2.32.3
8
8
  Requires-Dist: azure-ai-projects==1.0.0b6
9
9
  Requires-Dist: azure-ai-inference==1.0.0b9
10
10
  Requires-Dist: azure-identity==1.20.0
11
+ Dynamic: requires-dist
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
4
4
 
5
5
  setup(
6
6
  name='pbesa',
7
- version='4.0.5',
7
+ version='4.0.6',
8
8
  packages=find_packages(),
9
9
  install_requires=[
10
10
  'pymongo==4.6.3',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes