-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
54 lines (46 loc) · 1.87 KB
/
agent.py
File metadata and controls
54 lines (46 loc) · 1.87 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import time
from core.llm_engine import LLMEngine
from core.planner import Planner
from core.executor import Executor
from core.self_improver import SelfImprover
from core.tool_registry import ToolRegistry
from core.memory import Memory # assume your memory.py handles chat/task memory
class WindowsAgent:
def __init__(self):
print("[Agent] Initializing agent...")
self.llm = LLMEngine(model="deepseek-r1:7b")
self.planner = Planner(self.llm)
self.tool_registry = ToolRegistry()
self.self_improver = SelfImprover()
self.executor = Executor(self.tool_registry, self.self_improver)
self.memory = Memory() # store past instructions, plans, results
def handle_instruction(self, instruction: str):
print(f"[Agent] Received instruction: {instruction}")
# Save to memory
self.memory.add_user_instruction(instruction)
# Step 1: Generate JSON plan
plan = self.planner.create_plan(instruction)
print(f"[Agent] Plan generated by LLM: {plan}")
# Step 2: Execute plan
self.executor.execute_plan(plan)
# Step 3: Save execution result
self.memory.add_plan_result(plan)
print("[Agent] Instruction executed.\n")
def run(self):
print("[Agent] Ready to receive instructions. Type 'exit' to quit.")
while True:
instruction = input("Instruction: ")
if instruction.lower() in ("exit", "quit"):
print("[Agent] Exiting...")
break
if not instruction.strip():
continue
try:
self.handle_instruction(instruction)
except Exception as e:
print(f"[Agent] Error: {e}")
# Optional: Try to recover or self-improve
continue
if __name__ == "__main__":
agent = WindowsAgent()
agent.run()