feat(core): resilient subagent tool rejection with contextual feedback#22951
Conversation
Summary of ChangesHello, 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 significantly enhances the robustness and user experience of subagents by introducing a sophisticated tool rejection handling mechanism. Instead of immediately terminating when a user denies a tool execution, subagents now receive specific feedback and are prompted to rethink their strategy, allowing for more adaptive and continuous task completion. This change differentiates between user-initiated rejections and system-level aborts, ensuring that subagents can gracefully recover from user interventions while maintaining the ability for hard termination when necessary. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
|
Size Change: +3.24 kB (+0.01%) Total Size: 26.2 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
The pull request introduces a robust mechanism for handling soft tool rejections by subagents, allowing them to adapt their strategy rather than immediately terminating. This is achieved through contextual feedback to the model and appropriate UI state management. The changes include updating system instructions for subagents, modifying activity stream handling, and adding comprehensive test cases to validate the new behavior. The implementation appears solid, effectively differentiating between soft rejections and hard aborts, and ensuring the agent can recover gracefully.
| case 'ERROR': { | ||
| const error = String(activity.data['error']); | ||
| const isCancellation = error === 'Request cancelled.'; | ||
| const isRejection = error.startsWith( |
There was a problem hiding this comment.
don't love this string matching on errors. Can we do this a bit more robustly or at least make these string constants. Same issue applies for existing "Request cancelled."
| call.outcome === ToolConfirmationOutcome.Cancel; | ||
|
|
||
| if (isSoftRejection) { | ||
| const error = `User rejected this operation. Please acknowledge this, rethink your strategy, and try a different approach. If you cannot proceed without the rejected operation, summarize the issue and use \`${TASK_COMPLETE_TOOL_NAME}\` to report your findings and the blocker.`; |
There was a problem hiding this comment.
would be great to have some behavioral tests to verify the agent actually behaves reasonably given these soft rejections rather than always looping attempting the request again.
There was a problem hiding this comment.
Agreed. Going to file this as an issue to follow up with since the immediate concern is that we don't want to lose this context immediately. We may need some more tuning the exact tool response and SI
jacob314
left a comment
There was a problem hiding this comment.
Approved from a core perspective.
Distinguishes between UI-based tool rejection (soft rejection) and process-level cancellation (hard abort) for subagents. Soft rejections now allow the subagent to rethink its strategy via a direct context injection, while Ctrl+C remains terminal.
bbc7b1d to
9167cc2
Compare
Summary
This PR introduces a more resilient tool rejection mechanism for subagents, allowing them to rethink their strategy when a user denies a specific tool execution instead of immediately terminating the entire task.
Details
LocalSubagentInvocationto correctly reflect individual tool rejections ascancelledin the progress bar without ending the subagent's overall execution state.AbortErrorto the parent.Related Issues
N/A
How to Validate
@codebase_investigator).run_shell_command), click Reject in the picker.npm test -w @google/gemini-cli-core -- src/agents/local-executor.test.ts src/agents/local-invocation.test.tsPre-Merge Checklist