Skip to content

Commit ef0a124

Browse files
refactor: Use dynamic approach for praisonaiagents imports
- Replace manual symbol list with dynamic import using - Use for automatic maintenance - Remove manual tracking of imported symbols - Reduce code from 49 to 17 lines - Future-proof: automatically inherits new exports from praisonaiagents Co-authored-by: Mervin Praison <[email protected]>
1 parent e3dcbf3 commit ef0a124

File tree

1 file changed

+13
-52
lines changed

1 file changed

+13
-52
lines changed

src/praisonai/praisonai/__init__.py

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,26 @@
66
from .version import __version__
77

88
# Re-export all classes from praisonaiagents to enable:
9-
# from PraisonAI import Agent, Task, PraisonAIAgents
10-
# List of symbols that should be available from praisonaiagents
11-
_praisonaiagents_exports = [
12-
'Agent',
13-
'ImageAgent',
14-
'PraisonAIAgents',
15-
'Agents',
16-
'Task',
17-
'Tools',
18-
'TaskOutput',
19-
'ReflectionOutput',
20-
'AutoAgents',
21-
'Session',
22-
'Memory',
23-
'Knowledge',
24-
'Chunking',
25-
'MCP',
26-
'GuardrailResult',
27-
'LLMGuardrail',
28-
'Handoff',
29-
'handoff',
30-
'handoff_filters',
31-
'RECOMMENDED_PROMPT_PREFIX',
32-
'prompt_with_handoff_instructions',
33-
'get_telemetry',
34-
'enable_telemetry',
35-
'disable_telemetry',
36-
'MinimalTelemetry',
37-
'TelemetryCollector',
38-
'display_interaction',
39-
'display_self_reflection',
40-
'display_instruction',
41-
'display_tool_call',
42-
'display_error',
43-
'display_generating',
44-
'clean_triple_backticks',
45-
'error_logs',
46-
'register_display_callback',
47-
'sync_display_callbacks',
48-
'async_display_callbacks',
49-
]
50-
51-
# Track which symbols were successfully imported
52-
_imported_symbols = []
53-
9+
# from praisonai import Agent, Task, PraisonAIAgents
5410
try:
5511
import praisonaiagents
56-
# Import all symbols from praisonaiagents
57-
for symbol in _praisonaiagents_exports:
58-
if hasattr(praisonaiagents, symbol):
59-
globals()[symbol] = getattr(praisonaiagents, symbol)
60-
_imported_symbols.append(symbol)
12+
# Import all symbols from praisonaiagents using * import
13+
from praisonaiagents import *
6114
except ImportError:
6215
# If praisonaiagents is not available, these imports will fail gracefully
6316
pass
6417

65-
# Define __all__ to include both PraisonAI core classes and successfully imported praisonaiagents classes
18+
# Define __all__ to include both PraisonAI core classes and praisonaiagents exports
6619
__all__ = [
6720
# Core PraisonAI classes
6821
'PraisonAI',
6922
'__version__',
70-
] + _imported_symbols
23+
]
24+
25+
# Dynamically extend __all__ with praisonaiagents exports
26+
try:
27+
import praisonaiagents
28+
__all__.extend(praisonaiagents.__all__)
29+
except (ImportError, AttributeError):
30+
# If praisonaiagents is not available or doesn't have __all__, fail gracefully
31+
pass

0 commit comments

Comments
 (0)