| import os | |
| import json | |
| from datetime import datetime | |
| def save_log(task, plan, code, result): | |
| os.makedirs("logs", exist_ok=True) | |
| log_data = { | |
| "timestamp": str(datetime.now()), | |
| "task": task, | |
| "plan": plan, | |
| "code": code, | |
| "result": result | |
| } | |
| with open(f"logs/{datetime.now().strftime('%Y%m%d_%H%M%S')}.json", "w") as f: | |
| json.dump(log_data, f, indent=2) | |
| def read_memory(): | |
| if not os.path.exists("memory.txt"): | |
| return "" | |
| with open("memory.txt", "r") as f: | |
| return f.read() | |
| def write_memory(entry): | |
| with open("memory.txt", "a") as f: | |
| f.write(entry + "\n") | |
| def plan_task(task): | |
| return f"Break the task into steps and generate executable code to achieve: '{task}'" | |
| def generate_code(task): | |
| return f"# Auto-generated code to {task}\nprint('Completed task: {task}')" | |
| def run_code(code): | |
| local_vars = {} | |
| exec(code, {}, local_vars) | |
| return "Code executed successfully." | |
| def append_feedback(task, result, feedback_score): | |
| import json, os, time | |
| feedback_entry = { | |
| "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"), | |
| "task": task, | |
| "result": result, | |
| "feedback": feedback_score | |
| } | |
| os.makedirs("feedback", exist_ok=True) | |
| with open(f"feedback/{int(time.time())}.json", "w") as f: | |
| json.dump(feedback_entry, f, indent=2) | |