diff --git a/README.md b/README.md index c921928..eb4ea79 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Ditto is a user-friendly tool that allows you to generate a multi-file Flask app - **Automated Code Generation**: Generates routes, templates, and static files based on your description. - **Self-Building Agent**: Automatically plans and constructs the application without the need for manual coding. - **Modular Structure**: Organizes code into a clean, modular structure with separate directories for templates, static files, and routes. +- **Swarm Logic**: Utilizes swarm logic to decompose tasks into agents, assign tasks, facilitate agent communication, validate completed tasks, and add validated files to the IDE. ## Getting Started @@ -39,7 +40,7 @@ Ditto is a user-friendly tool that allows you to generate a multi-file Flask app 3. **Install Dependencies** ```bash - pip install litellm + pip install -r requirements.txt ``` ### Setting the `OPENAI_API_KEY` @@ -120,6 +121,33 @@ python main.py python main.py ``` +### Using Swarm Logic + +Ditto now includes a swarm logic feature to enhance task decomposition and validation. Here's how to use it: + +1. **Describe Your Task** + + Provide a detailed description of the task you want to accomplish. + +2. **Task Decomposition** + + The system will decompose the task into smaller tasks and create agents to handle each task. + +3. **Task Assignment** + + Tasks are assigned to agents, and the agents will work on their respective tasks. + +4. **Agent Communication** + + Agents will communicate with each other to ensure tasks are completed efficiently. + +5. **Task Validation** + + Completed tasks are validated, and if validated, the files are added to the IDE. If denied, the task is sent back to the agent for rework. + +6. **Monitor Progress** + + You can monitor the progress of the tasks and validation status in real-time. ## Contribution diff --git a/main.py b/main.py index 4f16b27..1555a7c 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,9 @@ # Correctly import the completion function from LiteLLM from litellm import completion, supports_function_calling +# Import the swarm_logic module +from swarm_logic import SwarmLogic + # Configuration MODEL_NAME = os.environ.get('LITELLM_MODEL', 'gpt-4o') # Default model; can be swapped easily @@ -30,7 +33,8 @@ "iteration": 0, "max_iterations": 50, "output": "", - "completed": False + "completed": False, + "validation_status": "" } # Ensure directories exist and create __init__.py in routes @@ -135,6 +139,7 @@ def home(): progress["iteration"] = 0 progress["output"] = "" progress["completed"] = False + progress["validation_status"] = "" thread = Thread(target=run_main_loop, args=(user_input,)) thread.start() return render_template_string(''' @@ -323,6 +328,9 @@ def run_main_loop(user_input): output = "" + # Initialize SwarmLogic + swarm_logic = SwarmLogic() + while iteration < max_iterations: progress["iteration"] = iteration + 1 # Create a new iteration dictionary for each loop @@ -454,6 +462,13 @@ def run_main_loop(user_input): progress["completed"] = True progress["status"] = "completed" + # Use swarm logic to process user input + validated_tasks = swarm_logic.process_user_input(user_input) + if validated_tasks: + progress["validation_status"] = "Tasks validated and files added to IDE." + else: + progress["validation_status"] = "No tasks validated." + return output if __name__ == '__main__': diff --git a/swarm_logic.py b/swarm_logic.py new file mode 100644 index 0000000..c15370c --- /dev/null +++ b/swarm_logic.py @@ -0,0 +1,51 @@ +import os +import json +from swarms import Swarm, Agent + +class SwarmLogic: + def __init__(self): + self.swarm = Swarm() + + def decompose_task(self, user_input): + # Decompose the user-defined task into smaller tasks + tasks = self.swarm.decompose(user_input) + return tasks + + def create_agents(self, tasks): + # Create agents for each task + agents = [Agent(task) for task in tasks] + return agents + + def assign_tasks(self, agents): + # Assign tasks to agents + for agent in agents: + self.swarm.assign(agent) + + def facilitate_communication(self, agents): + # Facilitate communication between agents + for agent in agents: + self.swarm.communicate(agent) + + def validate_tasks(self, agents): + # Validate completed tasks + validated_tasks = [] + for agent in agents: + if self.swarm.validate(agent): + validated_tasks.append(agent.task) + return validated_tasks + + def add_validated_files_to_ide(self, validated_tasks): + # Add validated files to the IDE + for task in validated_tasks: + file_path = os.path.join('ide', task['file_name']) + with open(file_path, 'w') as f: + f.write(task['content']) + + def process_user_input(self, user_input): + tasks = self.decompose_task(user_input) + agents = self.create_agents(tasks) + self.assign_tasks(agents) + self.facilitate_communication(agents) + validated_tasks = self.validate_tasks(agents) + self.add_validated_files_to_ide(validated_tasks) + return validated_tasks