| import os, json |
| from agent.planner import planner |
| from agent.coder import coder |
| from agent.critic import critic |
| from agent.fixer import fixer |
| from agent.state import AgentState |
|
|
| def run_agent(prompt, ws): |
| state = AgentState() |
| max_steps = int(os.getenv("MAX_AGENT_STEPS", 5)) |
|
|
| while state.iteration < max_steps: |
| plan = planner(prompt) |
| coder(plan, ws) |
|
|
| issues = critic(prompt) |
| if not issues: |
| break |
|
|
| fixer(issues, ws) |
| state.iteration += 1 |
|
|
| snapshot = {} |
| for root, _, files in os.walk(ws): |
| for f in files: |
| p = os.path.join(root, f) |
| snapshot[p.replace(ws, "")] = open(p).read() |
|
|
| with open("workspace_snapshot.json", "w") as out: |
| json.dump(snapshot, out) |