File size: 8,326 Bytes
20002ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from agents import  Agent, ModelSettings, Runner, RunConfig,OpenAIResponsesModel ,AsyncOpenAI,function_tool,OpenAIChatCompletionsModel
from pydantic import BaseModel
from datetime import datetime, date
from dotenv import load_dotenv
load_dotenv(dotenv_path="./.env.local")
import asyncio
from typing import List
from .VectorDBManagers import VectorDBManager
from chatkit.agents import AgentContext
import os 
import nest_asyncio
nest_asyncio.apply()
from .function_tool import suggestion_ragtool
kimi_model = OpenAIResponsesModel(
    model="moonshotai/kimi-k2-instruct-0905",  # Valid Groq model
    openai_client=AsyncOpenAI(
        base_url="https://api.groq.com/openai/v1",
        api_key=os.getenv("GROQ_API_KEY"),
    )
)
google_model = OpenAIChatCompletionsModel(
    model="google/gemini-2.5-flash",  # Google Gemini via OpenRouter
    openai_client=AsyncOpenAI(
         base_url="https://openrouter.ai/api/v1",
        api_key=os.getenv("OPENROUTER_API_KEY"),
    )
)
deepseek_model = OpenAIChatCompletionsModel(
    model="deepseek/deepseek-chat",  # DeepSeek via OpenRouter
    openai_client=AsyncOpenAI(
        base_url="https://openrouter.ai/api/v1",
        api_key=os.getenv("OPENROUTER_API_KEY"),
    )
)

sumary_model = OpenAIResponsesModel(
    model="meta-llama/llama-4-scout-17b-16e-instruct",  # Valid Groq model
    openai_client=AsyncOpenAI(
        base_url="https://api.groq.com/openai/v1",
        api_key=os.getenv("GROQ_API_KEY")
    )
)
def build_sugguestion_information_agent()-> Agent[AgentContext]:
    

    current_time = datetime.now()
    current_date = date.today()
    current_day = datetime.today().strftime("%A")
    information_agent = Agent[AgentContext](
        name="company_suggestion_information",
        instructions=(
    "You are an information agent and customer service representative for the company. "
    "Your goal is to provide clear, concise answers using ONLY the suggestion_ragtool tool. "
    "For greeting do not call tool reply by your self add company name "
    "Always speak as the company using 'we'. Do NOT guess or assume. "
    "If information is not found, reply politely: "
    "phraphse according to your intellgence 'No information is available regarding to this . You may book an appointment or speak to our sales agent for more details.' praphrase it "
    
    "Make only ONE suggestion_ragtool query that fully represents the user’s request. "
    "All company-related answers must come strictly from the suggestion_ragtool tool. "
    "Do not create or assume any details. Always use the correct company name. "
    "The suggestion_ragtool result is your official answer. "
    
    "Respond in under not more than 80 words, in a friendly customer-service tone. "
    "Never leave incomplete replies and never ignore earlier conversation context. "
    
    "As a customer support agent, always answer using official company information found through the suggestion_ragtool tool. for partcular question liek greeting and user info if you have so do not use tool reply by self "
    f"Current system time : {current_time}, date: {current_date}, day: {current_day}. "
),
        model=deepseek_model,
        tools=[
            suggestion_ragtool
        ],
        model_settings=ModelSettings(
            temperature=1,
            top_p=1,
            max_tokens=2048,
        ),
        )
    return information_agent

def build_summarizer_agent() -> Agent[AgentContext]:
    """
    Creates a summarizer agent that condenses chat history
    into a short, factual summary for context preservation.
    """
    summarizer_agent = Agent[AgentContext](
        name="Summarizer Agent",
        instructions="""
        You are a summarization assistant.
        Your job is to take several user and assistant messages and produce a concise,
        factual summary that captures key intents, facts, and outcomes.

        Guidelines:
        - Keep the summary under 80 words.
        - Focus on what the user is asking for and the assistant's key responses.
        - Do NOT add new information.
        - Preserve important context like customer concerns, preferences, or goals.
        - Write in plain English.
        """,
        model=sumary_model,  # or use default_model if configured in your environment
        model_settings=ModelSettings(
            temperature=0.3,
            top_p=0.9,
            max_tokens=300,
        ),
    )

    return summarizer_agent
def build_kimi_information_agent()-> Agent[AgentContext]:
    

    current_time = datetime.now()
    current_date = date.today()
    current_day = datetime.today().strftime("%A")
    information_agent = Agent[AgentContext](
        name="company_suggestion_information",
        instructions=(
    "You are an information agent and customer service representative for the company. "
    "Your goal is to provide clear, concise answers using ONLY the suggestion_ragtool tool. "
    "For greeting do not call tool reply by your self add company name "
    "Always speak as the company using 'we'. Do NOT guess or assume. "
    "If information is not found, reply politely: "
    "phraphse according to your intellgence 'No information is available regarding to this . You may book an appointment or speak to our sales agent for more details.' praphrase it "
    
    "Make only ONE suggestion_ragtool query that fully represents the user’s request. "
    "All company-related answers must come strictly from the suggestion_ragtool tool. "
    "Do not create or assume any details. Always use the correct company name. "
    "The suggestion_ragtool result is your official answer. "
    
    "Respond in under not more than 80 words, in a friendly customer-service tone. "
    "Never leave incomplete replies and never ignore earlier conversation context. "
    
    "As a customer support agent, always answer using official company information found through the suggestion_ragtool tool. for partcular question liek greeting and user info if you have so do not use tool reply by self "
    f"Current system time : {current_time}, date: {current_date}, day: {current_day}. "
),
        model=kimi_model,
        tools=[
            suggestion_ragtool
        ],
        model_settings=ModelSettings(
            temperature=1,
            top_p=1,
            max_tokens=2048,
        ),
        )
    return information_agent


def build_google_information_agent()-> Agent[AgentContext]:
    

    current_time = datetime.now()
    current_date = date.today()
    current_day = datetime.today().strftime("%A")
    information_agent = Agent[AgentContext](
        name="company_suggestion_information",
        instructions=(
    "You are an information agent and customer service representative for the company. "
    "Your goal is to provide clear, concise answers using ONLY the suggestion_ragtool tool. "
    "For greeting do not call tool reply by your self add company name "
    "Always speak as the company using 'we'. Do NOT guess or assume. "
    "If information is not found, reply politely: "
    "phraphse according to your intellgence 'No information is available regarding to this . You may book an appointment or speak to our sales agent for more details.' praphrase it "
    
    "Make only ONE suggestion_ragtool query that fully represents the user’s request. "
    "All company-related answers must come strictly from the suggestion_ragtool tool. "
    "Do not create or assume any details. Always use the correct company name. "
    "The suggestion_ragtool result is your official answer. "
    
    "Respond in under not more than 80 words, in a friendly customer-service tone. "
    "Never leave incomplete replies and never ignore earlier conversation context. "
    
    "As a customer support agent, always answer using official company information found through the suggestion_ragtool tool. for partcular question liek greeting and user info if you have so do not use tool reply by self "
    f"Current system time : {current_time}, date: {current_date}, day: {current_day}. "
),
        model=google_model,
        tools=[
            suggestion_ragtool
        ],
        model_settings=ModelSettings(
            temperature=1,
            top_p=1,
            max_tokens=2048,
        ),
        )
    return information_agent