File size: 1,120 Bytes
221ba30 |
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 |
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
|