[PR #4062] feat: add max steps for supervisor and sub-agents #10857

Closed
opened 2026-02-16 18:15:36 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4062

State: closed
Merged: Yes


Problem

See https://github.com/sst/opencode/issues/3631 for more details about this feature. From the issue:

"We want to add a maxSteps constraint to prevent costly large iteration loops for the supervisor and sub-agents.

On the maxSteps - 1 loop iteration, it should kick out of any sub-agent tool calls and return a text response."

Solution

I went nine rounds in the ring with the AI harness for OpenCode and figuring out the most consistent way to enforce this behavior across many models (tried mainly Grok code Fast, Big Pickle, and GPT OSS 20B and Qwen3 30B which I am locally hosting).

I tried removing tools from the calls on the final step(s) and paired it with a system prompt, but I consistently had models ignore the system prompt and even lack of activeTools and tools values, resulting in breaking attempts to call tools that were not defined.

I also tried the Vercel AI SDK toolChoice param (since we're using that package), but I also found that models universally ignored that request.

What did work every time was conditionally placing both a system prompt and an assistant prompt on the last step. With both of these combined, all models I've tested respect the maxSteps limit and instantly return a text-based summary of actions taken and recommended next steps.

I've also taken the liberty of updating the website documentation for this feature.

Testing

Windows MacOS Linux
With maxSteps = 4
Without maxSteps in config
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4062 **State:** closed **Merged:** Yes --- ## Problem See https://github.com/sst/opencode/issues/3631 for more details about this feature. From the issue: "We want to add a `maxSteps` constraint to prevent costly large iteration loops for the supervisor and sub-agents. On the `maxSteps - 1` loop iteration, it should kick out of any sub-agent tool calls and return a text response." ## Solution I went nine rounds in the ring with the AI harness for OpenCode and figuring out the most consistent way to enforce this behavior across many models (tried mainly Grok code Fast, Big Pickle, and GPT OSS 20B and Qwen3 30B which I am locally hosting). I tried removing tools from the calls on the final step(s) and paired it with a system prompt, but I consistently had models ignore the system prompt and even lack of `activeTools` and `tools` values, resulting in breaking attempts to call tools that were not defined. I also tried the Vercel AI SDK [toolChoice](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#tool-choice) param (since we're using that package), but I also found that models universally ignored that request. What _did_ work every time was conditionally placing both a system prompt and an assistant prompt on the last step. With both of these combined, all models I've tested respect the `maxSteps` limit and instantly return a text-based summary of actions taken and recommended next steps. I've also taken the liberty of updating the website documentation for this feature. ## Testing <table> <tr> <th></th> <th>Windows</th> <th>MacOS</th> <th>Linux</th> </tr> <tr> <td>With maxSteps = 4</th> <td><video src="https://github.com/user-attachments/assets/fb52ef73-130b-4b96-ab4f-a941b7883860"></td> <td><video src="https://github.com/user-attachments/assets/89a5096d-7e2c-43a1-8b5f-235b3d04ab3c"></td> <td><video src="https://github.com/user-attachments/assets/6eb0f025-498c-45f3-bef6-ba8f75bcf573"></td> </tr> <tr> <td>Without maxSteps in config</th> <td><video src="https://github.com/user-attachments/assets/8d724448-a0a2-4278-9fa5-eeef941eb2ca"></td> <td><video src="https://github.com/user-attachments/assets/476b345a-88d6-4d64-b9a7-c0f8ee4c5197"></td> <td><video src="https://github.com/user-attachments/assets/ddc86019-582c-4153-a509-c62198631276"></td> </tr> </table>
yindo added the pull-request label 2026-02-16 18:15:36 -05:00
yindo closed this issue 2026-02-16 18:15:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10857