aiecs 1.1.0__py3-none-any.whl → 1.2.1__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.

Potentially problematic release.


This version of aiecs might be problematic. Click here for more details.

Files changed (81) hide show
  1. aiecs/__init__.py +1 -1
  2. aiecs/aiecs_client.py +1 -1
  3. aiecs/config/config.py +38 -0
  4. aiecs/domain/__init__.py +95 -0
  5. aiecs/domain/community/__init__.py +159 -0
  6. aiecs/domain/community/agent_adapter.py +516 -0
  7. aiecs/domain/community/analytics.py +465 -0
  8. aiecs/domain/community/collaborative_workflow.py +99 -7
  9. aiecs/domain/community/communication_hub.py +649 -0
  10. aiecs/domain/community/community_builder.py +322 -0
  11. aiecs/domain/community/community_integration.py +365 -12
  12. aiecs/domain/community/community_manager.py +481 -5
  13. aiecs/domain/community/decision_engine.py +459 -13
  14. aiecs/domain/community/exceptions.py +238 -0
  15. aiecs/domain/community/models/__init__.py +36 -0
  16. aiecs/domain/community/resource_manager.py +1 -1
  17. aiecs/domain/community/shared_context_manager.py +621 -0
  18. aiecs/domain/context/context_engine.py +37 -33
  19. aiecs/infrastructure/monitoring/__init__.py +22 -0
  20. aiecs/infrastructure/monitoring/global_metrics_manager.py +207 -0
  21. aiecs/infrastructure/persistence/file_storage.py +41 -28
  22. aiecs/llm/__init__.py +44 -7
  23. aiecs/llm/callbacks/__init__.py +12 -0
  24. aiecs/llm/{custom_callbacks.py → callbacks/custom_callbacks.py} +1 -1
  25. aiecs/llm/client_factory.py +23 -6
  26. aiecs/llm/clients/__init__.py +35 -0
  27. aiecs/llm/{base_client.py → clients/base_client.py} +73 -1
  28. aiecs/llm/{googleai_client.py → clients/googleai_client.py} +19 -15
  29. aiecs/llm/{openai_client.py → clients/openai_client.py} +9 -14
  30. aiecs/llm/{vertex_client.py → clients/vertex_client.py} +15 -15
  31. aiecs/llm/{xai_client.py → clients/xai_client.py} +36 -50
  32. aiecs/llm/config/__init__.py +54 -0
  33. aiecs/llm/config/config_loader.py +275 -0
  34. aiecs/llm/config/config_validator.py +237 -0
  35. aiecs/llm/config/model_config.py +132 -0
  36. aiecs/llm/utils/__init__.py +11 -0
  37. aiecs/llm/utils/validate_config.py +91 -0
  38. aiecs/main.py +32 -2
  39. aiecs/scripts/aid/VERSION_MANAGEMENT.md +97 -0
  40. aiecs/scripts/aid/__init__.py +15 -0
  41. aiecs/scripts/aid/version_manager.py +224 -0
  42. aiecs/scripts/dependance_check/download_nlp_data.py +1 -0
  43. aiecs/tools/__init__.py +23 -23
  44. aiecs/tools/docs/__init__.py +5 -2
  45. aiecs/tools/docs/ai_document_orchestrator.py +39 -26
  46. aiecs/tools/docs/ai_document_writer_orchestrator.py +61 -38
  47. aiecs/tools/docs/content_insertion_tool.py +48 -28
  48. aiecs/tools/docs/document_creator_tool.py +47 -29
  49. aiecs/tools/docs/document_layout_tool.py +35 -20
  50. aiecs/tools/docs/document_parser_tool.py +56 -36
  51. aiecs/tools/docs/document_writer_tool.py +115 -62
  52. aiecs/tools/schema_generator.py +56 -56
  53. aiecs/tools/statistics/__init__.py +82 -0
  54. aiecs/tools/statistics/ai_data_analysis_orchestrator.py +581 -0
  55. aiecs/tools/statistics/ai_insight_generator_tool.py +473 -0
  56. aiecs/tools/statistics/ai_report_orchestrator_tool.py +629 -0
  57. aiecs/tools/statistics/data_loader_tool.py +518 -0
  58. aiecs/tools/statistics/data_profiler_tool.py +599 -0
  59. aiecs/tools/statistics/data_transformer_tool.py +531 -0
  60. aiecs/tools/statistics/data_visualizer_tool.py +460 -0
  61. aiecs/tools/statistics/model_trainer_tool.py +470 -0
  62. aiecs/tools/statistics/statistical_analyzer_tool.py +426 -0
  63. aiecs/tools/task_tools/chart_tool.py +2 -1
  64. aiecs/tools/task_tools/image_tool.py +43 -43
  65. aiecs/tools/task_tools/office_tool.py +39 -36
  66. aiecs/tools/task_tools/pandas_tool.py +37 -33
  67. aiecs/tools/task_tools/report_tool.py +67 -56
  68. aiecs/tools/task_tools/research_tool.py +32 -31
  69. aiecs/tools/task_tools/scraper_tool.py +53 -46
  70. aiecs/tools/task_tools/search_tool.py +1123 -0
  71. aiecs/tools/task_tools/stats_tool.py +20 -15
  72. aiecs/tools/tool_executor/__init__.py +2 -2
  73. aiecs/tools/tool_executor/tool_executor.py +3 -3
  74. {aiecs-1.1.0.dist-info → aiecs-1.2.1.dist-info}/METADATA +5 -1
  75. aiecs-1.2.1.dist-info/RECORD +144 -0
  76. {aiecs-1.1.0.dist-info → aiecs-1.2.1.dist-info}/entry_points.txt +1 -0
  77. aiecs/tools/task_tools/search_api.py +0 -7
  78. aiecs-1.1.0.dist-info/RECORD +0 -114
  79. {aiecs-1.1.0.dist-info → aiecs-1.2.1.dist-info}/WHEEL +0 -0
  80. {aiecs-1.1.0.dist-info → aiecs-1.2.1.dist-info}/licenses/LICENSE +0 -0
  81. {aiecs-1.1.0.dist-info → aiecs-1.2.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,516 @@
1
+ """
2
+ Agent Adapter System
3
+
4
+ Provides an adapter architecture for integrating custom agents and LLM clients
5
+ into the community system. Supports heterogeneous agent types and extensibility.
6
+ """
7
+
8
+ import logging
9
+ from abc import ABC, abstractmethod
10
+ from typing import Dict, List, Any, Optional, Type
11
+ from enum import Enum
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class AgentCapability(str, Enum):
17
+ """Standard agent capabilities."""
18
+ TEXT_GENERATION = "text_generation"
19
+ CODE_GENERATION = "code_generation"
20
+ DATA_ANALYSIS = "data_analysis"
21
+ DECISION_MAKING = "decision_making"
22
+ KNOWLEDGE_RETRIEVAL = "knowledge_retrieval"
23
+ TASK_PLANNING = "task_planning"
24
+ IMAGE_PROCESSING = "image_processing"
25
+ AUDIO_PROCESSING = "audio_processing"
26
+ MULTIMODAL = "multimodal"
27
+
28
+
29
+ class AgentAdapter(ABC):
30
+ """
31
+ Abstract base class for agent adapters.
32
+
33
+ Implement this class to integrate custom agent types or LLM clients
34
+ into the community system.
35
+ """
36
+
37
+ def __init__(self, agent_id: str, config: Optional[Dict[str, Any]] = None):
38
+ """
39
+ Initialize the agent adapter.
40
+
41
+ Args:
42
+ agent_id: Unique identifier for the agent
43
+ config: Optional configuration for the agent
44
+ """
45
+ self.agent_id = agent_id
46
+ self.config = config or {}
47
+ self.capabilities: List[AgentCapability] = []
48
+ self.metadata: Dict[str, Any] = {}
49
+ self._initialized = False
50
+
51
+ @abstractmethod
52
+ async def initialize(self) -> bool:
53
+ """
54
+ Initialize the agent adapter.
55
+
56
+ Returns:
57
+ True if initialization was successful
58
+ """
59
+ pass
60
+
61
+ @abstractmethod
62
+ async def execute(
63
+ self,
64
+ task: str,
65
+ context: Optional[Dict[str, Any]] = None,
66
+ **kwargs
67
+ ) -> Dict[str, Any]:
68
+ """
69
+ Execute a task with the agent.
70
+
71
+ Args:
72
+ task: Task description or instruction
73
+ context: Optional context for the task
74
+ **kwargs: Additional parameters
75
+
76
+ Returns:
77
+ Execution result with status and output
78
+ """
79
+ pass
80
+
81
+ @abstractmethod
82
+ async def communicate(
83
+ self,
84
+ message: str,
85
+ recipient_id: Optional[str] = None,
86
+ message_type: str = "request",
87
+ **kwargs
88
+ ) -> Dict[str, Any]:
89
+ """
90
+ Send a message to another agent or broadcast.
91
+
92
+ Args:
93
+ message: Message content
94
+ recipient_id: Optional recipient agent ID (None = broadcast)
95
+ message_type: Type of message (request, response, notification, share)
96
+ **kwargs: Additional message parameters
97
+
98
+ Returns:
99
+ Message delivery status and response
100
+ """
101
+ pass
102
+
103
+ @abstractmethod
104
+ async def get_capabilities(self) -> List[AgentCapability]:
105
+ """
106
+ Get the capabilities of this agent.
107
+
108
+ Returns:
109
+ List of agent capabilities
110
+ """
111
+ pass
112
+
113
+ @abstractmethod
114
+ async def health_check(self) -> Dict[str, Any]:
115
+ """
116
+ Check the health status of the agent.
117
+
118
+ Returns:
119
+ Health status information
120
+ """
121
+ pass
122
+
123
+ async def shutdown(self) -> bool:
124
+ """
125
+ Shutdown the agent adapter gracefully.
126
+
127
+ Returns:
128
+ True if shutdown was successful
129
+ """
130
+ self._initialized = False
131
+ logger.info(f"Agent adapter {self.agent_id} shutdown")
132
+ return True
133
+
134
+
135
+ class StandardLLMAdapter(AgentAdapter):
136
+ """
137
+ Adapter for standard LLM clients (OpenAI, Anthropic, etc.).
138
+ """
139
+
140
+ def __init__(
141
+ self,
142
+ agent_id: str,
143
+ llm_client: Any,
144
+ model_name: str,
145
+ config: Optional[Dict[str, Any]] = None
146
+ ):
147
+ """
148
+ Initialize standard LLM adapter.
149
+
150
+ Args:
151
+ agent_id: Unique identifier for the agent
152
+ llm_client: The LLM client instance
153
+ model_name: Name of the model
154
+ config: Optional configuration
155
+ """
156
+ super().__init__(agent_id, config)
157
+ self.llm_client = llm_client
158
+ self.model_name = model_name
159
+ self.capabilities = [
160
+ AgentCapability.TEXT_GENERATION,
161
+ AgentCapability.DECISION_MAKING,
162
+ AgentCapability.KNOWLEDGE_RETRIEVAL
163
+ ]
164
+
165
+ async def initialize(self) -> bool:
166
+ """Initialize the LLM adapter."""
167
+ try:
168
+ # Test connection with simple prompt
169
+ if hasattr(self.llm_client, 'health_check'):
170
+ await self.llm_client.health_check()
171
+ self._initialized = True
172
+ logger.info(f"Initialized LLM adapter for {self.model_name}")
173
+ return True
174
+ except Exception as e:
175
+ logger.error(f"Failed to initialize LLM adapter: {e}")
176
+ return False
177
+
178
+ async def execute(
179
+ self,
180
+ task: str,
181
+ context: Optional[Dict[str, Any]] = None,
182
+ **kwargs
183
+ ) -> Dict[str, Any]:
184
+ """Execute a task with the LLM."""
185
+ if not self._initialized:
186
+ return {
187
+ "status": "error",
188
+ "error": "Adapter not initialized"
189
+ }
190
+
191
+ try:
192
+ # Build prompt from task and context
193
+ prompt = self._build_prompt(task, context)
194
+
195
+ # Call LLM client
196
+ if hasattr(self.llm_client, 'generate'):
197
+ response = await self.llm_client.generate(
198
+ prompt=prompt,
199
+ model=self.model_name,
200
+ **kwargs
201
+ )
202
+ elif hasattr(self.llm_client, 'complete'):
203
+ response = await self.llm_client.complete(prompt, **kwargs)
204
+ else:
205
+ response = str(self.llm_client) # Fallback
206
+
207
+ return {
208
+ "status": "success",
209
+ "output": response,
210
+ "agent_id": self.agent_id,
211
+ "model": self.model_name
212
+ }
213
+ except Exception as e:
214
+ logger.error(f"Error executing task with LLM: {e}")
215
+ return {
216
+ "status": "error",
217
+ "error": str(e)
218
+ }
219
+
220
+ async def communicate(
221
+ self,
222
+ message: str,
223
+ recipient_id: Optional[str] = None,
224
+ message_type: str = "request",
225
+ **kwargs
226
+ ) -> Dict[str, Any]:
227
+ """Send a message through the LLM."""
228
+ # LLMs typically don't directly communicate, but can format messages
229
+ formatted_message = {
230
+ "from": self.agent_id,
231
+ "to": recipient_id or "broadcast",
232
+ "type": message_type,
233
+ "content": message,
234
+ "model": self.model_name
235
+ }
236
+
237
+ return {
238
+ "status": "formatted",
239
+ "message": formatted_message
240
+ }
241
+
242
+ async def get_capabilities(self) -> List[AgentCapability]:
243
+ """Get LLM capabilities."""
244
+ return self.capabilities
245
+
246
+ async def health_check(self) -> Dict[str, Any]:
247
+ """Check LLM health."""
248
+ return {
249
+ "status": "healthy" if self._initialized else "not_initialized",
250
+ "agent_id": self.agent_id,
251
+ "model": self.model_name,
252
+ "capabilities": [cap.value for cap in self.capabilities]
253
+ }
254
+
255
+ def _build_prompt(self, task: str, context: Optional[Dict[str, Any]]) -> str:
256
+ """Build prompt from task and context."""
257
+ prompt_parts = []
258
+
259
+ if context:
260
+ if "system" in context:
261
+ prompt_parts.append(f"System: {context['system']}")
262
+ if "history" in context:
263
+ prompt_parts.append(f"History: {context['history']}")
264
+
265
+ prompt_parts.append(f"Task: {task}")
266
+
267
+ return "\n\n".join(prompt_parts)
268
+
269
+
270
+ class CustomAgentAdapter(AgentAdapter):
271
+ """
272
+ Adapter for custom agent implementations.
273
+ Allows developers to wrap any agent implementation.
274
+ """
275
+
276
+ def __init__(
277
+ self,
278
+ agent_id: str,
279
+ agent_instance: Any,
280
+ execute_method: str = "execute",
281
+ capabilities: Optional[List[AgentCapability]] = None,
282
+ config: Optional[Dict[str, Any]] = None
283
+ ):
284
+ """
285
+ Initialize custom agent adapter.
286
+
287
+ Args:
288
+ agent_id: Unique identifier for the agent
289
+ agent_instance: The custom agent instance
290
+ execute_method: Name of the execute method on the agent
291
+ capabilities: List of agent capabilities
292
+ config: Optional configuration
293
+ """
294
+ super().__init__(agent_id, config)
295
+ self.agent_instance = agent_instance
296
+ self.execute_method = execute_method
297
+ self.capabilities = capabilities or [AgentCapability.TEXT_GENERATION]
298
+
299
+ async def initialize(self) -> bool:
300
+ """Initialize the custom agent."""
301
+ try:
302
+ if hasattr(self.agent_instance, 'initialize'):
303
+ if asyncio.iscoroutinefunction(self.agent_instance.initialize):
304
+ await self.agent_instance.initialize()
305
+ else:
306
+ self.agent_instance.initialize()
307
+ self._initialized = True
308
+ logger.info(f"Initialized custom agent adapter for {self.agent_id}")
309
+ return True
310
+ except Exception as e:
311
+ logger.error(f"Failed to initialize custom agent: {e}")
312
+ return False
313
+
314
+ async def execute(
315
+ self,
316
+ task: str,
317
+ context: Optional[Dict[str, Any]] = None,
318
+ **kwargs
319
+ ) -> Dict[str, Any]:
320
+ """Execute a task with the custom agent."""
321
+ if not self._initialized:
322
+ return {
323
+ "status": "error",
324
+ "error": "Adapter not initialized"
325
+ }
326
+
327
+ try:
328
+ execute_func = getattr(self.agent_instance, self.execute_method, None)
329
+ if not execute_func:
330
+ return {
331
+ "status": "error",
332
+ "error": f"Method {self.execute_method} not found on agent"
333
+ }
334
+
335
+ # Try to call the execute method
336
+ if asyncio.iscoroutinefunction(execute_func):
337
+ result = await execute_func(task, context=context, **kwargs)
338
+ else:
339
+ result = execute_func(task, context=context, **kwargs)
340
+
341
+ return {
342
+ "status": "success",
343
+ "output": result,
344
+ "agent_id": self.agent_id
345
+ }
346
+ except Exception as e:
347
+ logger.error(f"Error executing task with custom agent: {e}")
348
+ return {
349
+ "status": "error",
350
+ "error": str(e)
351
+ }
352
+
353
+ async def communicate(
354
+ self,
355
+ message: str,
356
+ recipient_id: Optional[str] = None,
357
+ message_type: str = "request",
358
+ **kwargs
359
+ ) -> Dict[str, Any]:
360
+ """Send a message through the custom agent."""
361
+ if hasattr(self.agent_instance, 'send_message'):
362
+ send_func = self.agent_instance.send_message
363
+ if asyncio.iscoroutinefunction(send_func):
364
+ return await send_func(message, recipient_id, message_type, **kwargs)
365
+ else:
366
+ return send_func(message, recipient_id, message_type, **kwargs)
367
+
368
+ # Default message formatting
369
+ return {
370
+ "status": "formatted",
371
+ "message": {
372
+ "from": self.agent_id,
373
+ "to": recipient_id or "broadcast",
374
+ "type": message_type,
375
+ "content": message
376
+ }
377
+ }
378
+
379
+ async def get_capabilities(self) -> List[AgentCapability]:
380
+ """Get custom agent capabilities."""
381
+ return self.capabilities
382
+
383
+ async def health_check(self) -> Dict[str, Any]:
384
+ """Check custom agent health."""
385
+ if hasattr(self.agent_instance, 'health_check'):
386
+ health_func = self.agent_instance.health_check
387
+ if asyncio.iscoroutinefunction(health_func):
388
+ return await health_func()
389
+ else:
390
+ return health_func()
391
+
392
+ return {
393
+ "status": "healthy" if self._initialized else "not_initialized",
394
+ "agent_id": self.agent_id,
395
+ "capabilities": [cap.value for cap in self.capabilities]
396
+ }
397
+
398
+
399
+ class AgentAdapterRegistry:
400
+ """
401
+ Registry for managing agent adapters.
402
+ Allows registration, lookup, and management of agent adapters.
403
+ """
404
+
405
+ def __init__(self):
406
+ """Initialize the adapter registry."""
407
+ self.adapters: Dict[str, AgentAdapter] = {}
408
+ self.adapter_types: Dict[str, Type[AgentAdapter]] = {
409
+ "standard_llm": StandardLLMAdapter,
410
+ "custom": CustomAgentAdapter
411
+ }
412
+ logger.info("Agent adapter registry initialized")
413
+
414
+ def register_adapter_type(
415
+ self,
416
+ type_name: str,
417
+ adapter_class: Type[AgentAdapter]
418
+ ) -> None:
419
+ """
420
+ Register a new adapter type.
421
+
422
+ Args:
423
+ type_name: Name for the adapter type
424
+ adapter_class: Adapter class
425
+ """
426
+ self.adapter_types[type_name] = adapter_class
427
+ logger.info(f"Registered adapter type: {type_name}")
428
+
429
+ async def register_adapter(
430
+ self,
431
+ adapter: AgentAdapter,
432
+ auto_initialize: bool = True
433
+ ) -> bool:
434
+ """
435
+ Register an agent adapter.
436
+
437
+ Args:
438
+ adapter: Agent adapter to register
439
+ auto_initialize: Whether to initialize the adapter automatically
440
+
441
+ Returns:
442
+ True if registration was successful
443
+ """
444
+ if adapter.agent_id in self.adapters:
445
+ logger.warning(f"Adapter {adapter.agent_id} already registered, replacing")
446
+
447
+ if auto_initialize and not adapter._initialized:
448
+ success = await adapter.initialize()
449
+ if not success:
450
+ logger.error(f"Failed to initialize adapter {adapter.agent_id}")
451
+ return False
452
+
453
+ self.adapters[adapter.agent_id] = adapter
454
+ logger.info(f"Registered adapter: {adapter.agent_id}")
455
+ return True
456
+
457
+ def get_adapter(self, agent_id: str) -> Optional[AgentAdapter]:
458
+ """
459
+ Get an adapter by agent ID.
460
+
461
+ Args:
462
+ agent_id: ID of the agent
463
+
464
+ Returns:
465
+ Agent adapter or None if not found
466
+ """
467
+ return self.adapters.get(agent_id)
468
+
469
+ def unregister_adapter(self, agent_id: str) -> bool:
470
+ """
471
+ Unregister an adapter.
472
+
473
+ Args:
474
+ agent_id: ID of the agent to unregister
475
+
476
+ Returns:
477
+ True if adapter was unregistered
478
+ """
479
+ if agent_id in self.adapters:
480
+ del self.adapters[agent_id]
481
+ logger.info(f"Unregistered adapter: {agent_id}")
482
+ return True
483
+ return False
484
+
485
+ def list_adapters(self) -> List[str]:
486
+ """
487
+ List all registered adapter IDs.
488
+
489
+ Returns:
490
+ List of adapter IDs
491
+ """
492
+ return list(self.adapters.keys())
493
+
494
+ async def health_check_all(self) -> Dict[str, Dict[str, Any]]:
495
+ """
496
+ Perform health check on all adapters.
497
+
498
+ Returns:
499
+ Dictionary mapping agent IDs to health status
500
+ """
501
+ health_statuses = {}
502
+ for agent_id, adapter in self.adapters.items():
503
+ try:
504
+ status = await adapter.health_check()
505
+ health_statuses[agent_id] = status
506
+ except Exception as e:
507
+ health_statuses[agent_id] = {
508
+ "status": "error",
509
+ "error": str(e)
510
+ }
511
+ return health_statuses
512
+
513
+
514
+ # Import asyncio for async checks
515
+ import asyncio
516
+