from typing import TypedDict, List
from langgraph.graph import StateGraph, START, END
class UniversityState(TypedDict):
query: str
intent: str
department: str
response: str
history: List[str]
DEPARTMENTS = {
"cse": "Computer Science Engineering",
"computer": "Computer Science Engineering",
"cs": "Computer Science Engineering",
"ece": "Electronics and Communication Engineering",
"electronics": "Electronics and Communication Engineering",
"eee": "Electrical Engineering",
"electrical": "Electrical Engineering",
"me": "Mechanical Engineering",
"mech": "Mechanical Engineering",
"mechanical": "Mechanical Engineering",
"civil": "Civil Engineering",
}
def classifier(state: UniversityState):
text = state["query"].lower()
if any(word in text for word in [
"admission",
"admit",
"apply",
"eligibility",
"cutoff"
]):
intent = "admission"
elif any(word in text for word in [
"fee",
"fees",
"payment",
"tuition"
]):
intent = "fees"
elif any(word in text for word in [
"exam",
"semester",
"result",
"admit card",
"routine"
]):
intent = "exam"
elif any(word in text for word in [
"scholarship",
"e-kalyan",
"financial"
]):
intent = "scholarship"
elif any(word in text for word in [
"hostel",
"mess",
"room"
]):
intent = "hostel"
elif any(word in text for word in [
"placement",
"package",
"job",
"salary",
"recruiter"
]):
intent = "placement"
else:
intent = "unknown"
return {"intent": intent}
def department_detector(state: UniversityState):
text = state["query"].lower()
department = "General"
for key, value in DEPARTMENTS.items():
if key in text:
department = value
break
return {"department": department}
def admission_agent(state: UniversityState):
dept = state["department"]
response = f"""
🎓 Admission Agent
Department : {dept}
Admission Process
1. Fill Online Application Form
2. Upload Documents
• 10th Marksheet
• 12th Marksheet
• Aadhaar Card
• Passport Size Photo
3. Pay Registration Fee
4. Submit Application
5. Download Acknowledgement
6. Wait for Merit List
7. Document Verification
8. Final Admission Confirmation
"""
return {"response": response}
def fees_agent(state: UniversityState):
dept = state["department"]
response = f"""
💰 Fees Agent
Department : {dept}
Approx Fees
Tuition Fee : ₹73,000
Hostel Fee : ₹20,000
Registration Fee : ₹5,000
Library Fee : ₹2,000
Exam Fee : ₹2,500
"""
return {"response": response}
def exam_agent(state: UniversityState):
response = """
📝 Exam Agent
Semester Exam
Mid Semester :
September
End Semester :
December
Admit Card :
Available before exam
Result :
Usually published within 30 days.
"""
return {"response": response}
def scholarship_agent(state: UniversityState):
response = """
🎓 Scholarship Agent
Available Scholarships
• Merit Scholarship
• SC Scholarship
• ST Scholarship
• OBC Scholarship
• E-Kalyan Scholarship
• NSP Scholarship
"""
return {"response": response}
def hostel_agent(state: UniversityState):
response = """
🏠 Hostel Agent
Separate Boys Hostel
Separate Girls Hostel
Mess Available
24×7 Electricity
WiFi Available
RO Drinking Water
Security Available
"""
return {"response": response}
def placement_agent(state: UniversityState):
dept = state["department"]
response = f"""
💼 Placement Agent
Department :
{dept}
Average Package :
₹4 LPA
Highest Package :
₹12 LPA
Top Recruiters
• TCS
• Infosys
• Wipro
• Cognizant
• Capgemini
"""
return {"response": response}
def unknown_agent(state: UniversityState):
return {
"response":
"""
❌ Sorry
I can answer only about
• Admission
• Fees
• Exam
• Scholarship
• Hostel
• Placement
"""
}
def formatter(state: UniversityState):
history = state.get("history", [])
history.append(f"User : {state['query']}")
history.append(f"Bot : {state['response']}")
return {
"response": state["response"],
"history": history
}
def router(state: UniversityState):
return state["intent"]
workflow = StateGraph(UniversityState)
workflow.add_node("Classifier", classifier)
workflow.add_node("Department", department_detector)
workflow.add_node("Admission", admission_agent)
workflow.add_node("Fees", fees_agent)
workflow.add_node("Exam", exam_agent)
workflow.add_node("Scholarship", scholarship_agent)
workflow.add_node("Hostel", hostel_agent)
workflow.add_node("Placement", placement_agent)
workflow.add_node("Unknown", unknown_agent)
workflow.add_node("Formatter", formatter)
workflow.add_edge(START, "Classifier")
workflow.add_edge("Classifier", "Department")
workflow.add_conditional_edges(
"Department",
router,
{
"admission": "Admission",
"fees": "Fees",
"exam": "Exam",
"scholarship": "Scholarship",
"hostel": "Hostel",
"placement": "Placement",
"unknown": "Unknown"
}
)
workflow.add_edge("Admission", "Formatter")
workflow.add_edge("Fees", "Formatter")
workflow.add_edge("Exam", "Formatter")
workflow.add_edge("Scholarship", "Formatter")
workflow.add_edge("Hostel", "Formatter")
workflow.add_edge("Placement", "Formatter")
workflow.add_edge("Unknown", "Formatter")
workflow.add_edge("Formatter", END)
app = workflow.compile()
def chat():
print("=" * 60)
print("🎓 UNIVERSITY AI MULTI-AGENT SYSTEM")
print("=" * 60)
print("\nAvailable Topics")
print("------------------------------")
print("Admission")
print("Fees")
print("Exam")
print("Scholarship")
print("Hostel")
print("Placement")
print("------------------------------")
print("\nDepartments")
print("------------------------------")
print("CSE")
print("ECE")
print("EEE")
print("Mechanical")
print("Civil")
print("------------------------------")
print("\nType 'bye' to exit.\n")
history = []
while True:
query = input("You : ").strip()
if query.lower() in ["bye", "exit", "quit"]:
print("\nBot : 👋 Thank you. Have a nice day!")
break
state = {
"query": query,
"intent": "",
"department": "",
"response": "",
"history": history
}
result = app.invoke(state)
history = result["history"]
print("\nBot :")
print(result["response"])
print()
if __name__ == "__main__":
chat()