Create BasicAgent.py
Browse files- BasicAgent.py +25 -0
BasicAgent.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class BasicAgent:
|
2 |
+
def __init__(self):
|
3 |
+
print("BasicAgent initialized.")
|
4 |
+
# Predefined question-answer pairs (for testing purposes)
|
5 |
+
self.knowledge_base = {
|
6 |
+
"What is your name?": "I am a basic agent.",
|
7 |
+
"What is the capital of France?": "The capital of France is Paris.",
|
8 |
+
"What is the largest mammal?": "The largest mammal is the blue whale.",
|
9 |
+
# Add more predefined Q&A pairs here
|
10 |
+
}
|
11 |
+
|
12 |
+
def __call__(self, question: str) -> str:
|
13 |
+
print(f"Agent received question: {question[:50]}...")
|
14 |
+
|
15 |
+
# Attempt to get the answer from the predefined knowledge base
|
16 |
+
answer = self.knowledge_base.get(question.strip(), None)
|
17 |
+
|
18 |
+
if answer:
|
19 |
+
print(f"Agent returning predefined answer: {answer}")
|
20 |
+
return answer
|
21 |
+
else:
|
22 |
+
# Fallback: Generate a generic response if the question is not in the knowledge base
|
23 |
+
fallback_answer = "Sorry, I don't know the answer to that question."
|
24 |
+
print(f"Agent returning fallback answer: {fallback_answer}")
|
25 |
+
return fallback_answer
|