-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: add max steps for supervisor and sub-agents #4062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add max steps for supervisor and sub-agents #4062
Conversation
dfdd6df to
25a17a2
Compare
772b621 to
eb855e1
Compare
0e1166f to
eb6ad55
Compare
| @@ -0,0 +1,16 @@ | |||
| CRITICAL - MAXIMUM STEPS REACHED | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used for both the system prompt concat and also the new conditional assistant message
| system.push(...(await SystemPrompt.environment())) | ||
| system.push(...(await SystemPrompt.custom())) | ||
|
|
||
| if (input.isLastStep) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional addition of the system prompt
| return false | ||
| }), | ||
| ), | ||
| ...(isLastStep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional addition of a new `assistant message. See PR description for more logic about why I went this route.
|
|
||
| // normal processing | ||
| const agent = await Agent.get(lastUser.agent) | ||
| const maxSteps = agent.maxSteps ?? Infinity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If maxSteps is undefined, this value will not cap agentic actions
e8dbab4 to
c60a030
Compare
917250b to
f4593c6
Compare
c30ae17 to
c60a030
Compare
f1dc981 to
3e15a39
Compare
df8bdf9 to
0dd5039
Compare
649991d to
ae2c890
Compare
f8ee907 to
6a9856d
Compare
e0eb99f to
7731405
Compare
7731405 to
d19e28f
Compare
|
/review |
We want a way to limit the number of steps allow agents in the app can take. This is primarily useful for sub-agents, but it applies to the supervisor as well. The user can define a maxSteps value for each agent. Documentation has also been updated for this new feature.
d19e28f to
76fcbf0
Compare
|
/oc use docs agent to update the example for max_steps it should only show an example for a subagent, dont show the setting being applied to general, plan or build |
|
Done! The docs agent has updated the |
Co-authored-by: rekram1-node <[email protected]>
|
/oc use docs agent to update the max steps example to show a custom agent w/ max steps set, does have the example use any default agent we provide, this custom agent can be completely stupid it doesnt have to be real and the prompt for it can be super super simple too |
|
Perfect! The example has been successfully updated. The max steps section now shows: ✅ A custom agent named The explanation text about what max steps does remains unchanged, and this is now the only example shown for this feature. |
Co-authored-by: rekram1-node <[email protected]>
* fix: ensure checkUpgrade sets `init:` (anomalyco#5040) * chore: format code * ci: use blacksmith runners in review workflow too (anomalyco#5042) * zen: make session provider sticky * ci: only maintainer can trigger * ci: cleaner * ignore: update download stats 2025-12-04 * fix(tui): cursor color * Preserve prompt input when creating new session (anomalyco#4993) * fix: model not being passed correctly to tool * tweak: bash tool messages regarding timeouts and truncation more clear for agent (anomalyco#5066) * tui: fix /new slash command being persisted in prompt input * add optional prompt Input to Github Action (anomalyco#4828) Co-authored-by: Github Action <[email protected]> Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> * bump: builtin plugin versions * feat: Add SAP AI Core provider support (anomalyco#5023) Signed-off-by: Jérôme Benoit <[email protected]> * core: ensure model npm package falls back to dev models config when not explicitly defined * docs: add CodeCompanion.nvim integration instructions (anomalyco#5079) * tweak: bash tool description re commit stuff * core: add test for custom model npm package inheritance * feat(desktop): terminal pane (anomalyco#5081) Co-authored-by: Github Action <[email protected]> Co-authored-by: Dax Raad <[email protected]> * Revert "feat(desktop): terminal pane (anomalyco#5081)" This reverts commit d763c11. * release: v1.0.133 * Update Nix flake.lock and hashes * Reapply "feat(desktop): terminal pane (anomalyco#5081)" This reverts commit f9dcd97. * chore: format code * Update Nix flake.lock and hashes * zen: fix byok * ignore: fix provider credentials query for BYOK Provider credentials field was being selected from ProviderTable even when the table wasn't joined (when byokProvider was undefined). Now the join is conditional - when byokProvider exists, we join and get the credentials; when it doesn't, the join condition is always false so provider remains null. * docs: llama.cpp docs: `limit` moved under model (anomalyco#5089) Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: GitHub Action <[email protected]> * fix: add getModel to SAP AI Core provider for correct SDK initialization (anomalyco#5086) Signed-off-by: Jérôme Benoit <[email protected]> * fix pty builds * fix * increase default scroll speed * ci: review * fix: ensure that vcs is still set to git even if no commits in repo * ignore: rm slop commnand (only for opencode repo this isnt shipping) * chore: format code * ignore: cmd tweak * tui: wrap dialog option descriptions (anomalyco#5083) * ci: keybinds * fix: ensure projects that go from having no commits to having commits have sessions migrated (anomalyco#5105) Co-authored-by: GitHub Action <[email protected]> * ignore: tweak * ignore: update download stats 2025-12-05 * Zen: add codex max * do not use required pty for local dev * fix: anomalyco#5064 ProviderInitError github-copilot-enterprise (anomalyco#5123) * feat(theme): Vercel (anomalyco#5119) Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <[email protected]> * fix(desktop): new session not selecting tab * fix(desktop): clone pty session on reconnect * add experimental.open_telemetry config option to enable OTEL spans (anomalyco#4978) Co-authored-by: noamzbr <[email protected]> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <[email protected]> * ignore: regen sdk * fix(desktop): prompting * fix(desktop): terminal cursor position * feat: add max steps for supervisor and sub-agents (anomalyco#4062) Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <[email protected]> * tweak: bash tool improve output metadata for agent consumption, fix small timeout issue (anomalyco#5131) * OpenCode Desktop app (anomalyco#5044) Co-authored-by: Adam <[email protected]> * Update Nix flake.lock and hashes * release: v1.0.134 * sync: record last synced tag v1.0.134 * chore: format code --------- Signed-off-by: Jérôme Benoit <[email protected]> Co-authored-by: YeonGyu-Kim <[email protected]> Co-authored-by: GitHub Action <[email protected]> Co-authored-by: wsx99outlook <[email protected]> Co-authored-by: Frank <[email protected]> Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: Adam <[email protected]> Co-authored-by: Daniel Gray <[email protected]> Co-authored-by: Shantur Rathore <[email protected]> Co-authored-by: Daniel Polito <[email protected]> Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jérôme Benoit <[email protected]> Co-authored-by: Dax Raad <[email protected]> Co-authored-by: Cason Adams <[email protected]> Co-authored-by: opencode <[email protected]> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: ry2009 <[email protected]> Co-authored-by: Julian Visser <[email protected]> Co-authored-by: Anthony Shew <[email protected]> Co-authored-by: rekram1-node <[email protected]> Co-authored-by: Noam Bressler <[email protected]> Co-authored-by: noamzbr <[email protected]> Co-authored-by: Nathan Thomas <[email protected]> Co-authored-by: Brendan Allan <[email protected]>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <[email protected]>


Problem
See #3631 for more details about this feature. From the issue:
"We want to add a
maxStepsconstraint to prevent costly large iteration loops for the supervisor and sub-agents.On the
maxSteps - 1loop 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
activeToolsandtoolsvalues, 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
maxStepslimit 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
Screen.Recording.2025-11-17.at.6.39.07.PM.mov
Screen.Recording.2025-11-17.at.6.49.45.PM.mov
Screencast.from.2025-11-17.19-08-05.webm
Screen.Recording.2025-11-17.at.6.40.15.PM.mov
Screen.Recording.2025-11-17.at.6.51.02.PM.mov
Screencast.from.2025-11-17.19-11-20.webm