fix: resolve infinite loop when combining outputSchema and tools also added unit tests#412
Open
b2rpt wants to merge 1 commit into
Open
fix: resolve infinite loop when combining outputSchema and tools also added unit tests#412b2rpt wants to merge 1 commit into
b2rpt wants to merge 1 commit into
Conversation
… added unit tests
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the [contribution guide](https://google.github.io/adk-
docs/contributing-guide/) before creating a pull request.
responseSchemaon the model configuration.2. In the Gemini API, combining strict JSON mode and Function Calling (tools) in the same
call is architecturally unsupported:
- Stable models immediately return a
400 Bad RequestAPI error.- Preview models (such as
gemini-3.1-flash-lite) get confused, calling toolsrecursively and getting trapped in an infinite loop.
"application/json"
andresponseSchemaat the Gemini API level (BasicLlmRequestProcessor), allowing standard function calling without API conflicts. 2. **Dynamic Tool Registration**: InLlmAgent.ts, we dynamically inject a specialset_model_responsetool into the agent's toolset whenoutputSchemaand tools are both present. 3. **Filter Bypass**: Ensured that theset_model_responsetool is never filtered out by plugin-drivenallowedToolsrestrictions. 4. **System Instruction Injection**: Appended a system instruction instructing the model that it must submit its final structured output by calling theset_model_responsetool. 5. **Turn Interception**: Intercepted theset_model_responsecall in the agent's post- processing lifecycle to parse the arguments and format the final text JSON response, settingskipSummarization = trueto break the agent execution loop and exit the turn immediately. Added safe-checks for TS compiler compatibility (toolContext` null-checks).outputSchemais not set at API level when tools are present).-
instructions_llm_request_processor_test.ts: Passed (5 tests, including newverification that instructions to call
set_model_responseare successfully appended).- Total test suite: 1,787 test cases successfully executed and passed.
tools. The agent will successfully execute the custom tools and then return a single
structured JSON response by calling
set_model_responseat the end of the turn withouttriggering a
400 Bad Requestor entering recursive tool call loops.js/blob/main/CONTRIBUTING.md) document.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] New and existing unit tests pass locally with my changes.
- [x] I have manually tested my changes end-to-end.
- [ ] Any dependent changes have been merged and published in downstream modules.