File size: 3,293 Bytes
20d720d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f49168f
 
 
 
 
 
 
 
 
 
 
20d720d
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from agents.tools.voice_tools import VoiceTools
from agents.tools.llm_tools import LLMTools
from agents.tools.knowledge_tools import KnowledgeTools
from agents.tools.validation_tools import ValidationTools
from crewai import Agent
from utils.knowledge_base import KnowledgeBase

class PersonalCoachCrew:
    def __init__(self, config):
        self.config = config 
        # Centralized tool instances
        self.voice_tools = VoiceTools(self.config)
        self.llm_tools = LLMTools(self.config)
        self.knowledge_tools = KnowledgeTools(self.config)
        self.validation_tools = ValidationTools(self.config)

        self.knowledge_base = KnowledgeBase(self.config)
        self._initialize_agents()
        self._create_crew()

    def _initialize_agents(self):
        # ----- AGENT 1 -----
        self.conversation_handler = Agent(
            role="Empathetic Conversation Handler",
            goal="Understand user's emotional state and needs through compassionate dialogue",
            backstory="...",
            verbose=self.config.crew.verbose,
            allow_delegation=False,
            tools=[
                self.voice_tools.transcribe_audio,
                self.voice_tools.detect_emotion,
                self.voice_tools.generate_reflective_questions,
            ]
        )
        # ----- AGENT 2 -----
        self.wisdom_advisor = Agent(
            role="Wisdom Keeper and Spiritual Guide",
            goal="Provide personalized guidance drawing from ancient wisdom and modern psychology",
            backstory="...",
            verbose=self.config.crew.verbose,
            allow_delegation=False,
            tools=[
                self.knowledge_tools.search_knowledge,
                self.knowledge_tools.extract_wisdom,
                self.knowledge_tools.suggest_practices,
                self.llm_tools.mistral_chat,
                self.llm_tools.generate_advice,
            ]
        )
        # ----- AGENT 3 -----
        self.response_validator = Agent(
            role="Response Guardian and Quality Validator",
            goal="Ensure all responses are safe, appropriate, and truly helpful",
            backstory="...",
            verbose=self.config.crew.verbose,
            allow_delegation=False,
            tools=[
                self.validation_tools.validate_user_input,
                self.validation_tools.validate_response,
                self.validation_tools._validate_response,
                self.validation_tools._check_prohibited_content,
                self.validation_tools._check_crisis_indicators,
                self.validation_tools._calculate_confidence,
                self.validation_tools._check_supportive_elements,
                self.validation_tools._check_tone,
                self.validation_tools._is_spam,
               
                
            ]
        )
        # ----- AGENT 4 -----
        self.interaction_manager = Agent(
            role="Conversation Flow Manager",
            goal="Create natural, engaging dialogue that helps users on their journey",
            backstory="...",
            verbose=self.config.crew.verbose,
            allow_delegation=False,
            tools=[
                self.llm_tools.summarize_conversation,
            ]
        )