| |
| from utils.knowledge_base import KnowledgeBase |
| |
| from crewai.tools import BaseTool |
|
|
|
|
|
|
| class SearchKnowledgeTool(BaseTool): |
| name: str = "search_knowledge" |
| description: str = "Search self-help or spiritual wisdom." |
| |
| def __init__(self, config=None): |
| super().__init__() |
| self.kb = KnowledgeBase(config) |
| def __call__(self, query: str, k: int = 5): |
| return self.kb.search(query, k=k) if self.kb.is_initialized() else \ |
| [{"text": "General wisdom", "score": 1.0}] |
|
|
| class ExtractWisdomTool(BaseTool): |
| name: str = "extract_wisdom" |
| description: str = "Extract most relevant wisdom for a given query." |
| def __init__(self, config=None): |
| super().__init__() |
| def __call__(self, search_results: list, user_context: dict): |
| return search_results[:3] |
|
|
| class SuggestPracticesTool(BaseTool): |
| name: str = "suggest_practices" |
| description: str = "Recommend meditations or self-care practices." |
| def __init__(self, config=None): |
| super().__init__() |
| def __call__(self, emotional_state: str, cultural_context: str = None): |
| return {"name": "Mindful Breathing", "description": "Focus on your breath to calm the mind."} |
|
|
| class KnowledgeTools: |
| def __init__(self, config=None): |
| self.search_knowledge = SearchKnowledgeTool(config) |
| self.extract_wisdom = ExtractWisdomTool(config) |
| self.suggest_practices = SuggestPracticesTool(config) |