feat(core): implement tool repair and length continuation auto-recovery#24978
feat(core): implement tool repair and length continuation auto-recovery#24978achernez wants to merge 2 commits intogoogle-gemini:mainfrom
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 introduces two key robustness features to the agent core: automatic tool name repair for handling minor model hallucinations and seamless response continuation when output is truncated due to token limits. These changes improve the overall reliability of agent interactions and include comprehensive unit and integration testing. Additionally, a build script modification ensures better compatibility across different Linux environments. 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
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces length continuation for agent sessions when a response is truncated due to MAX_TOKENS, adds tool name repair capabilities (normalization and fuzzy matching) to the scheduler, and updates the build script to dynamically detect workspaces. I have provided feedback regarding the naming consistency of the new usage property and suggested refactoring the duplicated tool repair logic into a helper method.
packages/core/src/agent/types.ts
Outdated
| outputTokens?: number; | ||
| cachedTokens?: number; | ||
| /** Whether this usage report is for a continued response. */ | ||
| is_continuation?: boolean; |
There was a problem hiding this comment.
The property is_continuation uses snake_case, which is inconsistent with the camelCase naming convention used for other properties in the Usage interface (e.g., inputTokens, outputTokens, cachedTokens). It also conflicts with the isContinuation property added to AgentEventCommon on line 83 of this same file. Please rename it to isContinuation to maintain consistency and adhere to TypeScript naming standards.
| is_continuation?: boolean; | |
| isContinuation?: boolean; |
| if (!tool) { | ||
| // Attempt normalization: kebab-case to snake_case | ||
| const normalizedName = normalizeToolName(request.name); | ||
| if (normalizedName !== request.name) { | ||
| tool = toolRegistry.getTool(normalizedName); | ||
| if (tool) { | ||
| debugLogger.log( | ||
| `Repaired tool name: ${request.name} -> ${normalizedName} (via normalization)`, | ||
| ); | ||
| enrichedRequest.name = normalizedName; | ||
| enrichedRequest.originalRequestName = | ||
| enrichedRequest.originalRequestName || request.name; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!tool) { | ||
| // Attempt fuzzy matching: Levenshtein distance <= 2 | ||
| const fuzzyResult = getClosestMatch( | ||
| request.name, | ||
| toolRegistry.getAllToolNames(), | ||
| 2, | ||
| ); | ||
| if (fuzzyResult.repairedName && !fuzzyResult.isAmbiguous) { | ||
| tool = toolRegistry.getTool(fuzzyResult.repairedName); | ||
| if (tool) { | ||
| debugLogger.log( | ||
| `Repaired tool name: ${request.name} -> ${fuzzyResult.repairedName} (via fuzzy matching, distance: ${fuzzyResult.distance})`, | ||
| ); | ||
| enrichedRequest.name = fuzzyResult.repairedName; | ||
| enrichedRequest.originalRequestName = | ||
| enrichedRequest.originalRequestName || request.name; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The tool name repair logic (normalization and fuzzy matching) is duplicated here and in the _execute method (lines 811-841). This duplication increases the risk of inconsistent behavior if the repair logic needs to be updated in the future. Please refactor this logic into a private helper method (e.g., _tryRepairToolName) that can be called from both locations.
…date repair logic
|
@googlebot I signed it! |
Summary
This PR implements two reliability features into
@google/gemini-cli-coreto improve agent robustness:1. Tool Hallucination Auto-Repair (Fuzzy Matching)
read-file) to snake_case (read_file).packages/core/src/utils/fuzzy-matcher.tsand integrated into theScheduler.2. Length Continuation
finishReason: 'MAX_TOKENS').LegacyAgentSessionrun loop.Verification
fuzzy-matcher.ts.scheduler.test.tsfor tool repair logic and ambiguity handling.legacy-agent-session.test.tsfor length continuation and iteration limits.npm run lintandnpm run build.scripts/build.jsthat caused build failures in some Linux environments.Fixes #24977