Skip to content

Commit 8b05672

Browse files
MervinPraisonclaude
andcommitted
fix: address review issues - tool factory performance and memory learn method
- Optimize tool factory: cache classes but create fresh instances (prevents import overhead while maintaining multi-agent safety) - Fix memory core learn method: add missing return statement - Address CodeRabbit feedback on unreachable code patterns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6b4e1b3 commit 8b05672

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/praisonai-agents/praisonaiagents/memory/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def learn(self):
305305
self._learn_manager = LearnManager(config=self._learn_config)
306306
except ImportError:
307307
logging.warning("Learn manager not available - install learn dependencies")
308+
return self._learn_manager
308309

309310
# Async variants to prevent event loop blocking
310311
async def store_short_term_async(self, content: str, metadata: Optional[Dict] = None, quality_score: Optional[float] = None,

src/praisonai-agents/praisonaiagents/tools/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,16 @@
200200
'email_tools': ('.email_tools', None),
201201
}
202202

203-
# Tool factory functions - creates new instances instead of shared cache
204-
# This prevents state leakage between concurrent agents
203+
# Tool factory functions - caches classes but creates fresh instances
204+
# This prevents state leakage between concurrent agents while optimizing import performance
205+
_loaded_classes = {} # Cache the Class, NOT the instance
206+
205207
def _create_tool_instance(class_name: str, module_path: str):
206-
"""Create a new tool instance. Each call returns a fresh instance to prevent state sharing."""
207-
module = import_module(module_path, __package__)
208-
class_ = getattr(module, class_name)
209-
return class_()
208+
"""Create a new tool instance. Caches the class but returns fresh instances to prevent state sharing."""
209+
if class_name not in _loaded_classes:
210+
module = import_module(module_path, __package__)
211+
_loaded_classes[class_name] = getattr(module, class_name)
212+
return _loaded_classes[class_name]() # Fresh instance safe for multi-agent
210213

211214
# Profile exports (lazy loaded)
212215
_PROFILE_EXPORTS = frozenset({

0 commit comments

Comments
 (0)