|
| 1 | +# Using `sub-task` feature (`new_task` Tool) |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `new_task` tool (also known as "Boomerang Tasks") allows Roo to break down a main task into smaller, independent sub-tasks. Each sub-task is executed in a fresh context, ensuring: |
| 6 | + |
| 7 | +- Reduced AI hallucinations |
| 8 | +- Eliminated context overflow |
| 9 | +- Prevention of lengthy prompt cut-offs |
| 10 | +- Improved accuracy and adherence to the main goal |
| 11 | + |
| 12 | +Sub-tasks return their results to the parent task, which then continues execution seamlessly. |
| 13 | + |
| 14 | +## How It Works |
| 15 | + |
| 16 | +There are no buttons or settings required to enable this feature. Roo Code automatically decides when to use `new_task` if a task can be broken down into smaller, standalone sub-tasks. However, you can instruct Roo Code explicitly to use this feature. |
| 17 | + |
| 18 | +## How to Use `new_task` |
| 19 | + |
| 20 | +### 1. Instruct Roo Code to Break Down a Task |
| 21 | + |
| 22 | +You can request Roo Code to decompose a task into sub-tasks and execute each separately. |
| 23 | + |
| 24 | +**📌 Example Prompt:** |
| 25 | + |
| 26 | +```plaintext |
| 27 | +Write a Python script that lists all files in the current folder and writes the result into a text file. Then, create a Windows batch file to run this Python script. Lastly, create a folder named 'test1' and move both the Python script and the batch file into the folder. Break this task into independent sub-tasks and execute each using the `new_task` tool. |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Provide a List of Tasks to Execute |
| 31 | + |
| 32 | +If you prefer to manually define sub-tasks, list them explicitly and ask Roo to execute each using `new_task`. |
| 33 | + |
| 34 | +**📌 Example Prompt:** |
| 35 | + |
| 36 | +```plaintext |
| 37 | +Execute each of the following tasks using the `new_task` tool: |
| 38 | +
|
| 39 | +1. Write a Python script (`list_files.py`) that lists all files in the current folder and writes them into `files.txt`. |
| 40 | +2. Run the script (`list_files.py`). |
| 41 | +3. Edit `files.txt` to ensure each line contains only a file name. |
| 42 | +4. Count the number of files in the current folder and append the count to `files.txt`. |
| 43 | +``` |
| 44 | + |
| 45 | +### 3. Using Task Files for Execution |
| 46 | + |
| 47 | +Instead of listing tasks in the prompt, you can: |
| 48 | + |
| 49 | +1. Write each task in a separate text file (e.g., `task1.txt`, `task2.txt`). |
| 50 | +2. Store them in a folder (e.g., `tasks`).. |
| 51 | +3. Instruct Roo Code to loop through the folder and execute each task using `new_task`. |
| 52 | + |
| 53 | +**📌 Example Prompt:** |
| 54 | + |
| 55 | +```plaintext |
| 56 | +Loop through all task files in the folder `tasks` and execute each task using the `new_task` tool. |
| 57 | +``` |
| 58 | + |
| 59 | +<br> |
| 60 | + |
| 61 | +## Persistent Execution with Review and Approval |
| 62 | + |
| 63 | +You can enable approval before moving to the next sub-task using the **Auto-Approve Panel** (found at the bottom of Roo's Code panel, above the chat text area). This allows you to review each sub-task before it is declared as Done and control is returned to the main parent task to continue execution rest of the sub-tasks. |
| 64 | + |
| 65 | +At this point you can review the task, make sure it went as planned, write further instructions to Roo Code so it can fix or change whatever you wish to fix in the Sub-Task, and when done - press the Approve button. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +<br> |
| 71 | + |
| 72 | +Beside controlling the end sub-task (and return control to parent / calling task) from the 'Auto-Approve' panel, you can setup this checkbox from withing the Roo Code Settings panel, use the gear icon from the top right corner of the extension panel and scroll down to the 'Auto Approve' section. |
| 73 | + |
| 74 | +<br> |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +## Sub-Task execution plan |
| 79 | + |
| 80 | +The parent task can create a sub-tasks to execute smaller workload segments, and a sub-task can also spawn additional sub-tasks to break the work further into even smaller parts. |
| 81 | + |
| 82 | +This can be achieved using the following prompt: |
| 83 | + |
| 84 | +**📌 Example Prompt:** |
| 85 | + |
| 86 | +```plaintext |
| 87 | +### **Execution Flow:** |
| 88 | +each sub-task should be created using `new_task` tool, |
| 89 | +1. **Main Task:** Extract function signatures from the `apiService.ts` file. |
| 90 | +2. **For each function:** |
| 91 | + - Call **Sub-task 1** (Add comments). |
| 92 | + - Call **Sub-task 2** (Write Jest test). |
| 93 | + - **Nested Sub-task 2.1** (Run Jest test and return results). |
| 94 | +``` |
| 95 | + |
| 96 | +<br> |
| 97 | + |
| 98 | +```mermaid |
| 99 | +graph TD |
| 100 | + A[Main Task: Extract Function Signatures] -->|For each function| B[Sub-task 1: Add Comments] |
| 101 | + A -->|For each function| C[Sub-task 2: Write Jest Test] |
| 102 | + C --> D[Sub-task 2.1: Run Jest Test] |
| 103 | + D -->|✅ All Tests Passed| E[Return Success] |
| 104 | + D -->|❌ Test Failed| F[Return Error Message] |
| 105 | +``` |
| 106 | + |
| 107 | +--- |
| 108 | +<br> |
| 109 | +<br> |
| 110 | +<br> |
| 111 | + |
| 112 | +## 📝 Side note: |
| 113 | + |
| 114 | +### **Understanding Lengthy Prompt Cut-offs** |
| 115 | + |
| 116 | +### What is a Lengthy Prompt Cut-off? |
| 117 | + |
| 118 | +When an AI receives a very long prompt, it may be truncated due to token limits, leading to incomplete instructions or missing details. This can cause the AI to forget key parts of the task, resulting in errors or misinterpretation. |
| 119 | + |
| 120 | +### Why Does This Happen? |
| 121 | + |
| 122 | +- Most AI models have a **token limit**, meaning they can only process a certain amount of text at once. |
| 123 | +- If a prompt exceeds this limit, the model may **cut off** important instructions at the end. |
| 124 | +- This leads to **forgetfulness** or **misinterpretation** of the original request. |
| 125 | + |
| 126 | +### How `new_task` Helps Prevent This |
| 127 | + |
| 128 | +By breaking a large task into smaller, self-contained sub-tasks: |
| 129 | + |
| 130 | +- Each sub-task fits within the AI’s token limit. |
| 131 | +- The AI does not need to remember the entire context of the main task. |
| 132 | +- Prompts remain concise, improving accuracy and reducing the chance of AI forgetfulness. |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +By leveraging the `new_task` tool, you ensure optimized, structured, efficient, and error-free execution of complex tasks in Roo Code. |
| 137 | + |
0 commit comments