feat: add max steps for supervisor and sub-agents
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 |