agent_backend / app /MultiAgent.py
GoutamSachdev's picture
Update app/MultiAgent.py
20002ec verified
Raw
History Blame Contribute Delete
8.33 kB
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