from agents.planner import plan_task from agents.executor import execute_step from agents.critic import review_result from memory import add_to_memory, search_memory import uuid from datetime import datetime def run_agents(goal, memory, session_id=None): session_id = session_id or str(uuid.uuid4())[:8] timestamp = datetime.now().isoformat(timespec="seconds") log = f"[{timestamp}] Session {session_id}: Goal: {goal}\n" history = search_memory(goal, memory) context = "\n".join(history[:3]) if history else "No relevant memory found." plan = plan_task(goal, memory) add_to_memory(f"[{session_id}] 🧠 Context: {context}", memory) add_to_memory(f"[{session_id}] šŸ—‚ Plan: {plan}", memory) outputs = [] for step in plan: result = execute_step(step) add_to_memory(f"[{session_id}] šŸ”§ Executor ran: {step} -> {result}", memory) review = review_result(step, result) add_to_memory(f"[{session_id}] šŸ” Critic: {review}", memory) step_log = f"šŸ”¹ Step: {step}\nšŸ›  Result: {result}\n🧠 Review: {review}\n" log += step_log + "\n" outputs.append(step_log) with open("log.txt", "a") as f: f.write(log + "\n") return "\n".join(outputs)