akborana4 commited on
Commit
5eea89f
·
verified ·
1 Parent(s): da36569

Create agent/graph.py

Browse files
Files changed (1) hide show
  1. agent/graph.py +30 -0
agent/graph.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, json
2
+ from agent.planner import planner
3
+ from agent.coder import coder
4
+ from agent.critic import critic
5
+ from agent.fixer import fixer
6
+ from agent.state import AgentState
7
+
8
+ def run_agent(prompt, ws):
9
+ state = AgentState()
10
+ max_steps = int(os.getenv("MAX_AGENT_STEPS", 5))
11
+
12
+ while state.iteration < max_steps:
13
+ plan = planner(prompt)
14
+ coder(plan, ws)
15
+
16
+ issues = critic(prompt)
17
+ if not issues:
18
+ break
19
+
20
+ fixer(issues, ws)
21
+ state.iteration += 1
22
+
23
+ snapshot = {}
24
+ for root, _, files in os.walk(ws):
25
+ for f in files:
26
+ p = os.path.join(root, f)
27
+ snapshot[p.replace(ws, "")] = open(p).read()
28
+
29
+ with open("workspace_snapshot.json", "w") as out:
30
+ json.dump(snapshot, out)