Skip to content

Comments

feat(core): add default execution limits for subagents#18274

Merged
abhipatel12 merged 2 commits intomainfrom
abhi/subagents/max-turns
Feb 4, 2026
Merged

feat(core): add default execution limits for subagents#18274
abhipatel12 merged 2 commits intomainfrom
abhi/subagents/max-turns

Conversation

@abhipatel12
Copy link
Collaborator

Summary

Introduced centralized default execution limits for subagents to prevent infinite loops and hanging processes.

Details

  • Added DEFAULT_MAX_TURNS (15) and DEFAULT_MAX_TIME_MINUTES (5) to packages/core/src/agents/types.ts.
  • Updated agentLoader.ts to apply these defaults when parsing agent definitions (e.g., from Markdown files).
  • Refactored local-executor.ts to use these constants as fallbacks during runtime and updated error reporting to reflect the actual limits hit.
  • Updated agentLoader.test.ts to verify the new default behavior.
  • Updated docs/core/subagents.md to document the new default values.

Related Issues

Related to improving subagent robustness and observability.

How to Validate

Run the updated tests:
npm test -w @google/gemini-cli-core -- src/agents/agentLoader.test.ts src/agents/local-executor.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

@abhipatel12 abhipatel12 requested review from a team as code owners February 4, 2026 05:15
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @abhipatel12, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request centralizes and applies default execution limits for subagents, specifically for maximum turns and maximum execution time. This enhancement aims to improve the robustness of subagents by preventing infinite loops and prolonged execution, thereby ensuring more predictable and stable agent behavior across the system.

Highlights

  • Default Execution Limits: Introduced DEFAULT_MAX_TURNS (15) and DEFAULT_MAX_TIME_MINUTES (5) constants to establish default execution limits for subagents, centralizing these critical values.
  • Agent Definition Loading: Implemented the use of these new default limits in agentLoader.ts to ensure subagents loaded from definitions (e.g., Markdown files) automatically inherit these constraints if not explicitly set.
  • Runtime Execution and Error Reporting: Refactored local-executor.ts to leverage these default constants as fallbacks during runtime and enhanced error messages to accurately report the specific limits (turns or time) that caused agent termination.
  • Testing and Documentation: Updated agentLoader.test.ts to include tests verifying that subagents correctly apply the new default execution limits, and documented the new default values in docs/core/subagents.md for clarity.
Changelog
  • docs/core/subagents.md
    • Updated documentation for max_turns and timeout_mins to reflect their new default values of 15 and 5 minutes, respectively.
  • packages/core/src/agents/agentLoader.test.ts
    • Imported DEFAULT_MAX_TIME_MINUTES and DEFAULT_MAX_TURNS.
    • Modified a test case to use these default constants for runConfig validation, ensuring default limits are correctly applied.
  • packages/core/src/agents/agentLoader.ts
    • Imported DEFAULT_MAX_TURNS and DEFAULT_MAX_TIME_MINUTES.
    • Updated markdownToAgentDefinition to use DEFAULT_MAX_TURNS and DEFAULT_MAX_TIME_MINUTES as fallback values for maxTurns and maxTimeMinutes if not specified in the markdown definition.
  • packages/core/src/agents/local-executor.ts
    • Imported DEFAULT_MAX_TURNS and DEFAULT_MAX_TIME_MINUTES.
    • Modified the maxTimeMinutes calculation to use DEFAULT_MAX_TIME_MINUTES as a fallback if not explicitly set in the agent's run configuration.
    • Updated error messages for AgentTerminateMode.TIMEOUT and AgentTerminateMode.MAX_TURNS to dynamically report the actual limits used (either defined or default) when an agent terminates.
    • Modified the checkTerminationConditions method to use DEFAULT_MAX_TURNS as a fallback when evaluating the maxTurns limit.
  • packages/core/src/agents/types.ts
    • Added DEFAULT_MAX_TURNS (15) and DEFAULT_MAX_TIME_MINUTES (5) constants to define system-wide default execution limits.
    • Updated the RunConfig interface documentation to clarify that maxTimeMinutes and maxTurns will default to these new constants if not specified.
Activity
  • The author has updated relevant documentation to reflect the changes.
  • Tests have been added or updated to cover the new functionality, ensuring correctness.
  • The changes have been validated on MacOS, confirming functionality on a key platform.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces default execution limits for subagents, which is a great step for robustness. The implementation correctly adds default values for max_turns and timeout_mins in the agent loader and documentation. My review focuses on improving the implementation within the local-executor to reduce code duplication and on fixing a type inconsistency in types.ts to make the agent configuration more robust and clear.

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

Size Change: +237 B (0%)

Total Size: 23.7 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 23.7 MB +237 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 4, 2026
@abhipatel12 abhipatel12 added this pull request to the merge queue Feb 4, 2026
Merged via the queue into main with commit b39cefe Feb 4, 2026
26 checks passed
@abhipatel12 abhipatel12 deleted the abhi/subagents/max-turns branch February 4, 2026 06:37
yuvrajangadsingh pushed a commit to yuvrajangadsingh/gemini-cli that referenced this pull request Feb 4, 2026
sidwan02 pushed a commit to sidwan02/gemini-cli-gemma that referenced this pull request Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants