pbesa 2.1__py3-none-any.whl → 4.0.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.
Files changed (75) hide show
  1. pbesa/__init__.py +4 -3
  2. pbesa/cognitive.py +475 -0
  3. pbesa/kernel/__init__.py +4 -6
  4. pbesa/kernel/adapter.py +165 -0
  5. pbesa/kernel/agent.py +558 -0
  6. pbesa/kernel/io/__init__.py +2 -2
  7. pbesa/kernel/io/system_file.py +38 -0
  8. pbesa/kernel/io/tcp_server.py +23 -0
  9. pbesa/kernel/util.py +217 -0
  10. pbesa/kernel/world.py +43 -0
  11. pbesa/mas.py +565 -0
  12. pbesa/remote/__init__.py +5 -0
  13. pbesa/remote/adm_listener.py +44 -0
  14. pbesa/{middleware/remote/AdmListenerHandler.py → remote/adm_listener_handler.py} +74 -57
  15. pbesa/remote/exceptions.py +18 -0
  16. pbesa/remote/remote_adm.py +42 -0
  17. pbesa/{middleware/remote/RemoteAdmHandler.py → remote/remote_adm_handler.py} +109 -83
  18. pbesa/social/__init__.py +4 -0
  19. pbesa/social/collaborative_team.py +299 -0
  20. pbesa/social/delegator.py +81 -0
  21. pbesa/social/delegator_team.py +334 -0
  22. pbesa/social/dialog.py +153 -0
  23. pbesa/social/dispatcher_team.py +319 -0
  24. pbesa/social/templates.py +18 -0
  25. pbesa/social/worker.py +188 -0
  26. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE +21 -21
  27. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE.txt +21 -21
  28. pbesa-4.0.0.dist-info/METADATA +8 -0
  29. pbesa-4.0.0.dist-info/RECORD +32 -0
  30. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/WHEEL +5 -5
  31. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/top_level.txt +0 -0
  32. pbesa/engine/__init__.py +0 -2
  33. pbesa/engine/bdi/BDIAg.py +0 -42
  34. pbesa/engine/bdi/BDILevel.py +0 -10
  35. pbesa/engine/bdi/BDIMachine.py +0 -116
  36. pbesa/engine/bdi/Goal.py +0 -28
  37. pbesa/engine/bdi/GoalExe.py +0 -36
  38. pbesa/engine/bdi/__init__.py +0 -5
  39. pbesa/engine/rational/ActionExe.py +0 -35
  40. pbesa/engine/rational/Brain.py +0 -10
  41. pbesa/engine/rational/RationalAg.py +0 -43
  42. pbesa/engine/rational/__init__.py +0 -3
  43. pbesa/kernel/adapter/Adapter.py +0 -26
  44. pbesa/kernel/adapter/FileAdapter.py +0 -23
  45. pbesa/kernel/adapter/__init__.py +0 -2
  46. pbesa/kernel/agent/Action.py +0 -19
  47. pbesa/kernel/agent/Agent.py +0 -91
  48. pbesa/kernel/agent/BehaviorExe.py +0 -33
  49. pbesa/kernel/agent/Channel.py +0 -10
  50. pbesa/kernel/agent/World.py +0 -15
  51. pbesa/kernel/agent/__init__.py +0 -5
  52. pbesa/kernel/io/SystemFile.py +0 -13
  53. pbesa/kernel/io/TCPServer.py +0 -4
  54. pbesa/kernel/system/Adm.py +0 -189
  55. pbesa/kernel/system/Directory.py +0 -36
  56. pbesa/kernel/system/__init__.py +0 -2
  57. pbesa/kernel/util/HashTable.py +0 -62
  58. pbesa/kernel/util/Queue.py +0 -231
  59. pbesa/kernel/util/__init__.py +0 -2
  60. pbesa/middleware/__init__.py +0 -3
  61. pbesa/middleware/adapter/GameAdapter.py +0 -64
  62. pbesa/middleware/adapter/MongoAdapter.py +0 -47
  63. pbesa/middleware/adapter/RESTAdapter.py +0 -52
  64. pbesa/middleware/adapter/SubProcessAdapter.py +0 -30
  65. pbesa/middleware/adapter/WSSAdapter.py +0 -89
  66. pbesa/middleware/adapter/WSSNJAdapter.py +0 -51
  67. pbesa/middleware/adapter/WSSNJHandler.py +0 -23
  68. pbesa/middleware/adapter/__init__.py +0 -7
  69. pbesa/middleware/remote/AdmListener.py +0 -17
  70. pbesa/middleware/remote/RemoteAdm.py +0 -17
  71. pbesa/middleware/remote/__init__.py +0 -4
  72. pbesa/middleware/web/WebAgTK.py +0 -15
  73. pbesa/middleware/web/__init__.py +0 -0
  74. pbesa-2.1.dist-info/METADATA +0 -25
  75. pbesa-2.1.dist-info/RECORD +0 -54
@@ -0,0 +1,299 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ -------------------------- PBESA -------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN
8
+ @version 4.0.0
9
+ @date 09/08/24
10
+
11
+ The Collaborative Team consists of a controller and a
12
+ group of agents who work together to complete tasks
13
+ synchronously with the client. When a client submits a
14
+ request, the controller breaks down the task into smaller
15
+ parts, assigning each part to a specific agent. The
16
+ agents perform their portion of the work and then send
17
+ their results back to the controller. The controller
18
+ then consolidates all the partial responses into a single
19
+ comprehensive response, which is delivered to the client.
20
+ This structure allows the team to efficiently tackle
21
+ complex tasks by leveraging the agents' ability to work
22
+ in parallel. By maintaining a synchronous interaction
23
+ with the client, the Collaborative Team ensures
24
+ that requests are managed in an organized and structured
25
+ manner, providing a unified and cohesive response.
26
+ This approach is ideal for situations where precision
27
+ and consistency are essential, as it allows for close
28
+ coordination among all team members and the delivery of
29
+ clear and unified results.
30
+ """
31
+
32
+ # --------------------------------------------------------
33
+ # Define resources
34
+ # --------------------------------------------------------
35
+
36
+ from threading import Timer
37
+ from abc import abstractmethod
38
+ from ..kernel.agent import Agent
39
+ from ..kernel.agent import Action
40
+
41
+ # ----------------------------------------------------------
42
+ # Defines system component exceptions
43
+ # ----------------------------------------------------------
44
+
45
+ class CollaborativeException(Exception):
46
+ """ Base class for exceptions of agent """
47
+ pass
48
+
49
+ # ----------------------------------------------------------
50
+ # Define the TimeoutAction component
51
+ # ----------------------------------------------------------
52
+
53
+ class TimeoutAction(Action):
54
+ """ Represents the action that manages the timeout """
55
+
56
+ def __init__(self) -> None:
57
+ """ Constructor """
58
+ self.__timer = None
59
+ super().__init__()
60
+
61
+ def handler(self) -> None:
62
+ """ Timeout handler """
63
+ if self.agent.is_timeout():
64
+ self.agent.set_timeout(False)
65
+ self.adm.send_event(self.agent.id, 'response', 'timeout')
66
+
67
+ def execute(self, data:any) -> None:
68
+ """ Execute the action
69
+ @param data: Event data
70
+ """
71
+ if data['command'] == 'start':
72
+ if not self.agent.is_timeout():
73
+ self.agent.set_timeout(True)
74
+ self.__timer = Timer(data['time'], self.handler)
75
+ self.__timer.start()
76
+ else:
77
+ if self.__timer:
78
+ self.__timer.cancel()
79
+ self.__timer = None
80
+
81
+ # --------------------------------------------------------
82
+ # Define DelegateAction component
83
+ # --------------------------------------------------------
84
+
85
+ class DelegateAction(Action):
86
+ """ An action is a response to the occurrence of an event """
87
+
88
+ def execute(self, data:any) -> None:
89
+ """
90
+ Response.
91
+ @param data Event data
92
+ """
93
+ self.agent.set_gateway(data['gateway'])
94
+ self.agent.reset()
95
+ self.delegate(data['dto'])
96
+
97
+ def activeTimeout(self, time:int) -> None:
98
+ """ Active timeout
99
+ @param time: Time
100
+ """
101
+ self.adm.send_event(self.agent.id, 'timeout', {'time': time, 'command': 'start'})
102
+
103
+ def toAssign(self, data:any) -> None:
104
+ """ Assign data to an agent
105
+ @param data: Data
106
+ """
107
+ if len(self.agent.get_free_list()) > 0:
108
+ ag = self.agent.get_free_list().pop(0)
109
+ self.adm.send_event(ag, 'task', data)
110
+ else:
111
+ raise CollaborativeException('[Warn, toAssign]: The number of data packets exceeds the number of agents')
112
+
113
+ @abstractmethod
114
+ def delegate(self, data:any) -> None:
115
+ """ Delegate method
116
+ @param data: Data
117
+ """
118
+ pass
119
+
120
+ # --------------------------------------------------------
121
+ # Define ResponseAction component
122
+ # --------------------------------------------------------
123
+
124
+ class ResponseAction(Action):
125
+ """ An action is a response to the occurrence of an event """
126
+
127
+ def execute(self, data:any) -> None:
128
+ """ Execute the action
129
+ @param data: Event data
130
+ """
131
+ if 'timeout' == data:
132
+ results = {}
133
+ for key, res in self.agent.get_check_dict().items():
134
+ results[key] = res
135
+ self.end_of_process(results, True)
136
+ else:
137
+ result = 'None'
138
+ agentID = data['source']
139
+ if data['result']:
140
+ result = data['result']
141
+ self.agent.get_check_dict()[agentID] = result
142
+ if self.check():
143
+ results = {}
144
+ for key, res in self.agent.get_check_dict().items():
145
+ results[key] = res
146
+ self.end_of_process(results, False)
147
+
148
+ def check(self):
149
+ for res in self.agent.get_check_dict().values():
150
+ if not res:
151
+ return False
152
+ return True
153
+
154
+ def send_response(self, response:any) -> None:
155
+ """ Send response
156
+ @param response: Response
157
+ """
158
+ self.agent.set_timeout(False)
159
+ self.adm.send_event(self.agent.id, 'timeout', {'command': 'cancel'})
160
+ self.agent.get_gateway().put(response)
161
+
162
+ @abstractmethod
163
+ def end_of_process(self, results:dict, timeout:int) -> None:
164
+ """ End of process
165
+ @param results: Results
166
+ @param timeout: Timeout
167
+ """
168
+ pass
169
+
170
+ # --------------------------------------------------------
171
+ # Define component
172
+ # --------------------------------------------------------
173
+
174
+ class CollaborativeController(Agent):
175
+ """ Represents the agent that delegates the execution of actions to other agents """
176
+
177
+ def __init__(self, agent_id:str) -> None:
178
+ """ Constructor
179
+ @param agent_id: Agent ID
180
+ """
181
+ self.__agent_list = []
182
+ self.__check_dict = {}
183
+ self.__gateway = None
184
+ self.__free_list = None
185
+ self.__timeout = False
186
+ self.__poolSize = None
187
+ self.__request_dict = {}
188
+ super().__init__(agent_id)
189
+
190
+ def setup(self) -> None:
191
+ """ Set up method """
192
+ self._social = True
193
+ self.add_behavior('Timeout')
194
+ self.bind_action('Timeout', 'timeout', TimeoutAction())
195
+ self.add_behavior('Delegate')
196
+ self.add_behavior('Response')
197
+ self.build()
198
+
199
+ def bind_delegate_action(self, action:DelegateAction) -> None:
200
+ """ Binds the delegate action to the agent
201
+ @param action: Delegate action
202
+ """
203
+ self.bind_action('Delegate', 'delegate', action)
204
+
205
+ def bind_response_action(self, action:ResponseAction) -> None:
206
+ """ Binds the response action to the agent
207
+ @param action: Response action
208
+ """
209
+ self.bind_action('Response', 'response', action)
210
+
211
+ def suscribe_agent(self, agent:Agent) -> None:
212
+ """ Suscribes an agent to the controller
213
+ @param agent: Agent
214
+ """
215
+ if not isinstance(agent, Agent):
216
+ raise CollaborativeException('[Warn, suscribeAgent]: The object to subscribe is not an agent')
217
+ agent.set_controller(self.id)
218
+ agent.set_controller_type('LINEAL')
219
+ self.__check_dict[agent.id] = None
220
+ self.__agent_list.append(agent.id)
221
+ actions = agent.get_actions()
222
+ for action in actions:
223
+ action.set_is_pool(False)
224
+ action.set_enable_response(True)
225
+
226
+ def suscribe_remote_agent(self, agent_id:str) -> None:
227
+ """ Suscribes an agent to the controller
228
+ @param agent_id: Agent ID
229
+ """
230
+ if not isinstance(agent_id, str):
231
+ raise CollaborativeException('[Warn, suscribeRemoteAgent]: The object to subscribe is not an agent ID')
232
+ self.__check_dict[agent_id] = None
233
+ self.__agent_list.append(agent_id)
234
+
235
+ def reset(self) -> None:
236
+ """ Reset method """
237
+ self.__free_list = []
238
+ for ag in self.__agent_list:
239
+ self.__check_dict[ag] = None
240
+ self.__free_list.append(ag)
241
+
242
+ @abstractmethod
243
+ def build(self) -> None:
244
+ """ Build method """
245
+ pass
246
+
247
+ def start(self) -> None:
248
+ """ Start method """
249
+ if len(self.__agent_list) <= 0:
250
+ raise CollaborativeException('[Warn, toAssign]: Controller agent list is empty. Agents must be subscribed to the controller')
251
+ super().start()
252
+
253
+ def get_free_list(self) -> list:
254
+ """ Get free list
255
+ @return: Free list
256
+ """
257
+ return self.__free_list
258
+
259
+ def get_request_dict(self) -> dict:
260
+ """ Get request dictionary
261
+ @return: Request dictionary
262
+ """
263
+ return self.__request_dict
264
+
265
+ def get_gateway(self) -> str:
266
+ """ Get gateway
267
+ @return: Gateway
268
+ """
269
+ return self.__gateway
270
+
271
+ def set_gateway(self, gateway:str) -> None:
272
+ """ Set gateway
273
+ @param gateway: Gateway
274
+ """
275
+ self.__gateway = gateway
276
+
277
+ def get_check_dict(self) -> dict:
278
+ """ Get check dictionary
279
+ @return: Check dictionary
280
+ """
281
+ return self.__check_dict
282
+
283
+ def is_timeout(self) -> bool:
284
+ """ Check if the controller has a timeout
285
+ @return: True if the controller has a timeout, False otherwise
286
+ """
287
+ return self.__timeout
288
+
289
+ def set_timeout(self, timeout:bool) -> None:
290
+ """ Set timeout
291
+ @param timeout: Timeout
292
+ """
293
+ self.__timeout = timeout
294
+
295
+ def is_block(self) -> bool:
296
+ """ Check if the controller is blocked
297
+ @return: True if the controller is blocked, False otherwise
298
+ """
299
+ return True
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ -------------------------- PBESA -------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN
8
+ @version 4.0.0
9
+ @date 09/08/24
10
+ """
11
+
12
+ # --------------------------------------------------------
13
+ # Define resources
14
+ # --------------------------------------------------------
15
+
16
+ from abc import abstractmethod
17
+ from ..kernel.agent import Agent
18
+ from ..kernel.agent import Action
19
+
20
+ # ----------------------------------------------------------
21
+ # Defines system component exceptions
22
+ # ----------------------------------------------------------
23
+
24
+ class DelegatorException(Exception):
25
+ """ Base class for exceptions of agent """
26
+ pass
27
+
28
+ # --------------------------------------------------------
29
+ # Define Delegator component
30
+ # --------------------------------------------------------
31
+
32
+ class Delegator(Agent):
33
+ """ Represents the agent that delegates the execution of actions to other agents """
34
+
35
+ def __init__(self, agent_id:str) -> None:
36
+ """ Constructor
37
+ @param agent_id: Agent ID
38
+ """
39
+ self.__agentList = []
40
+ super().__init__(agent_id)
41
+
42
+ def setup(self) -> None:
43
+ """ Set up method """
44
+ self._social = True
45
+ # Defines the agent state
46
+ self.state = {}
47
+ # Defines the delegate behavior
48
+ self.add_behavior('Delegate')
49
+ # Defines the space for build
50
+ self.build()
51
+
52
+ def bindDelegateAction(self, action:Action) -> None:
53
+ """ Binds the delegate action to the agent
54
+ @param action: Delegate action
55
+ """
56
+ self.bind_action('Delegate', 'delegate', action)
57
+
58
+ def suscribeAgent(self, agent: Agent) -> None:
59
+ """ Suscribes an agent to the delegate agent
60
+ @param agent: Agent
61
+ """
62
+ if not isinstance(agent, Agent):
63
+ raise DelegatorException('[Warn, suscribeAgent]: The object to subscribe is not an agent')
64
+ self.__agentList.append(agent.id)
65
+
66
+ @abstractmethod
67
+ def build(self) -> None:
68
+ """ Build method """
69
+ pass
70
+
71
+ def start(self) -> None:
72
+ """ Start method """
73
+ if len(self.__agentList) <= 0:
74
+ raise DelegatorException('[Warn, start]: Delegate agent list is empty. Agents must be subscribed to the Delegate Agent')
75
+ super().start()
76
+
77
+ def getAgentList(self) -> list:
78
+ """ Get the agent
79
+ @return: Agent list
80
+ """
81
+ return self.__agentList