Final_Assignment_Template / BasicAgent.py
Muhammad-Izhan's picture
Create BasicAgent.py
221ba30 verified
raw
history blame
1.12 kB
class BasicAgent:
def __init__(self):
print("BasicAgent initialized.")
# Predefined question-answer pairs (for testing purposes)
self.knowledge_base = {
"What is your name?": "I am a basic agent.",
"What is the capital of France?": "The capital of France is Paris.",
"What is the largest mammal?": "The largest mammal is the blue whale.",
# Add more predefined Q&A pairs here
}
def __call__(self, question: str) -> str:
print(f"Agent received question: {question[:50]}...")
# Attempt to get the answer from the predefined knowledge base
answer = self.knowledge_base.get(question.strip(), None)
if answer:
print(f"Agent returning predefined answer: {answer}")
return answer
else:
# Fallback: Generate a generic response if the question is not in the knowledge base
fallback_answer = "Sorry, I don't know the answer to that question."
print(f"Agent returning fallback answer: {fallback_answer}")
return fallback_answer