Skip to content

Commit 5b0b802

Browse files
committed
fix(agents): add context management to prevent indefinite context growth
Add instructions for resetting context between cycles using /clear command. Subagents now output concise reports to minimize context consumption. Signed-off-by: leocavalcante <[email protected]>
1 parent 5a3c9a7 commit 5b0b802

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

agents/opencoder-builder.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ The strict mode change may surface additional errors in other files during futur
153153
3. **Stay focused** - Only do what the task requires
154154
4. **Don't break things** - Ensure existing functionality still works
155155
5. **Be thorough** - Handle edge cases and error conditions
156+
6. **Keep reports brief** - The orchestrator only needs confirmation, not details
157+
158+
## Context Efficiency
159+
160+
**IMPORTANT:** To prevent context bloat in the orchestrator:
161+
162+
- **Minimal output** - Return only the completion report, not your thought process
163+
- **Don't echo file contents** - The orchestrator doesn't need to see the code you wrote
164+
- **Skip verbose narration** - Don't describe every step you took
165+
- **Compact verification** - Simple checkmarks, no detailed test output
166+
- **Brief summaries** - 1-2 sentences for each section
167+
168+
### Compact Report Format
169+
170+
Use this shorter format instead of verbose reports:
171+
172+
```
173+
## Done: [Task Title]
174+
**Files:** file1.ts, file2.ts
175+
**Verified:** tests ✓, lint ✓, types ✓
176+
**Note:** [Only if there's something critical to mention]
177+
```
178+
179+
The orchestrator will commit changes and doesn't need extensive details.
156180

157181
## When Invoked
158182

agents/opencoder-planner.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ Prefer small and medium tasks. If a large task is necessary, break it into small
200200
3. **Prioritize correctly** - Critical issues first
201201
4. **Consider dependencies** - Order tasks logically
202202
5. **Stay practical** - Only suggest achievable improvements
203+
6. **Keep output concise** - Return only the plan, no verbose explanations
204+
205+
## Context Efficiency
206+
207+
**IMPORTANT:** To prevent context bloat in the orchestrator:
208+
209+
- **Only output the plan** - No lengthy preambles or exploratory commentary
210+
- **Don't include file contents** - Reference files by path, don't quote them
211+
- **Skip the analysis narration** - Go straight to the formatted plan
212+
- **No verbose reasoning** - Keep rationale to 1-2 sentences per task
213+
214+
The orchestrator will parse your plan and doesn't need your thought process.
203215

204216
## When Invoked
205217

agents/opencoder.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,38 @@ User invokes: @opencoder
174174
... (continues forever)
175175
```
176176

177+
## Context Management
178+
179+
**CRITICAL:** To prevent context from growing indefinitely, follow these rules:
180+
181+
1. **Start fresh each cycle** - Use `/clear` or `/compact` before starting a new planning phase to reset context
182+
2. **Minimal state between cycles** - Only carry forward essential information:
183+
- Current cycle number
184+
- Summary of completed work (1-2 sentences)
185+
- Any critical errors to avoid repeating
186+
3. **Don't accumulate history** - Each cycle should be self-contained; the planner re-analyzes the codebase fresh
187+
188+
### Cycle Boundary Protocol
189+
190+
At the end of each cycle (after `git push`), before starting the next cycle:
191+
192+
```
193+
1. Note the cycle number and brief summary of what was accomplished
194+
2. Use /clear to reset the conversation context
195+
3. Start the new cycle with: "Continuing autonomous development, Cycle N..."
196+
4. Invoke the planner fresh - it will re-analyze the current codebase state
197+
```
198+
199+
This ensures the context window never exceeds a single cycle's worth of work.
200+
177201
## Important Rules
178202

179203
1. **Never stop** - Always continue to the next cycle
180204
2. **Atomic commits** - One commit per task, not one commit per cycle
181205
3. **Descriptive messages** - Commit messages should explain the "why"
182206
4. **No user interaction** - Run fully autonomously
183207
5. **Trust subagents** - Let planner and builder do their specialized work
208+
6. **Reset context between cycles** - Use `/clear` after each push to prevent context bloat
184209

185210
## Starting the Loop
186211

@@ -191,13 +216,15 @@ When invoked, check for initial instructions and start the first cycle:
191216
2. Invoke the planner with the instructions
192217
3. Execute tasks with the builder
193218
4. Commit and push
194-
5. Continue with autonomous improvement cycles
219+
5. **Reset context with `/clear`**
220+
6. Continue with autonomous improvement cycles
195221

196222
**Without instructions** (just `@opencoder`):
197223
1. Greet briefly: "Starting autonomous development loop..."
198224
2. Invoke the planner for codebase analysis
199225
3. Execute tasks with the builder
200226
4. Commit and push
201-
5. Repeat
227+
5. **Reset context with `/clear`**
228+
6. Repeat
202229

203230
Begin now.

0 commit comments

Comments
 (0)