Spaces:
Runtime error
Runtime error
Upload reasoning_agent.py
Browse files- reasoning_agent.py +21 -0
reasoning_agent.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from datetime import datetime
|
3 |
+
|
4 |
+
class ReasoningAgent:
|
5 |
+
def __init__(self):
|
6 |
+
self.logs = []
|
7 |
+
|
8 |
+
def think(self, context: str, goal: str) -> str:
|
9 |
+
thought = f"[{datetime.now()}] Reasoning: Based on context '{context}', the goal is '{goal}'."
|
10 |
+
plan = f"To achieve this, the AI should break down the task and search memory/tools for support."
|
11 |
+
self.logs.append(thought + "\n" + plan)
|
12 |
+
return plan
|
13 |
+
|
14 |
+
def reflect(self, result: str) -> str:
|
15 |
+
reflection = f"[{datetime.now()}] Reflection: After execution, result was: '{result}'"
|
16 |
+
feedback = "Was the outcome successful? What can be improved next time?"
|
17 |
+
self.logs.append(reflection + "\n" + feedback)
|
18 |
+
return feedback
|
19 |
+
|
20 |
+
def get_log(self):
|
21 |
+
return self.logs[-5:]
|