Spaces:
Runtime error
Runtime error
Create agent_loop.py
Browse files- core/agent_loop.py +21 -0
core/agent_loop.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from agents.planner import generate_plan
|
2 |
+
from agents.executor import execute_step
|
3 |
+
from agents.critic import reflect_and_improve
|
4 |
+
from agents.memory import MemoryAgent
|
5 |
+
|
6 |
+
memory = MemoryAgent()
|
7 |
+
|
8 |
+
def run_autonomous_loop(user_goal):
|
9 |
+
memory.save("Goal", user_goal)
|
10 |
+
|
11 |
+
plan = generate_plan(user_goal, memory)
|
12 |
+
memory.save("Plan", plan)
|
13 |
+
|
14 |
+
final_output = ""
|
15 |
+
for step in plan:
|
16 |
+
result = execute_step(step, memory)
|
17 |
+
memory.save(f"Result of {step}", result)
|
18 |
+
improved_step = reflect_and_improve(step, result, memory)
|
19 |
+
final_output += f"Step: {step}\nResult: {result}\nImproved Step: {improved_step}\n\n"
|
20 |
+
|
21 |
+
return final_output
|