Repository navigation
fix(models): mark failed MCP tool results as errors on the interactions API - #7825
Closed
adityasingh2400 wants to merge 1 commit into
Closed
adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
…ns API _convert_part_to_interaction_content set is_error on a function_result step only when the response had an error key. A failed MCP CallToolResult reports the failure with isError (is_error in MCP SDK 2.x dumps), so Gemini was told the failed call succeeded. Treat a truthy isError or is_error as an error too, as AnthropicLlm already does. Fixes google#7824
Collaborator
|
Thank you @adityasingh2400 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 72205cd. Closing this PR as the changes are now in the main branch. |
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 before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
_convert_part_to_interaction_contentsetis_erroron afunction_resultstep only when the function response had anerrorkey. A failed MCPCallToolResultreports the failure withisError(is_errorin MCP SDK 2.x dumps) and has noerrorkey, so on the Interactions API Gemini was told that a failed MCP tool call succeeded.Solution:
Also treat a truthy
isErrororis_errorin the response dict as an error. This matches whatAnthropicLlmdoes since #7665. Responses with anerrorkey behave as before, and the result payload is still passed through unchanged.Testing Plan
Unit Tests:
Added to
tests/unittests/models/test_interactions_utils.py, each parametrized overisErrorandis_error:test_function_response_failed_mcp_result_is_errortest_function_response_successful_mcp_result_is_not_errorpre-commit runpasses on the changed files.mypyreports one error ininteractions_utils.py(FunctionResultDeltahas no attributecall_id), which is already onmainand outside this change.Manual End-to-End (E2E) Tests:
The test server is a real streamable-HTTP MCP server whose
read_filetool raises, so it returns anisError: trueresult. ARunnerdrives anLlmAgent(model=Gemini("gemini-2.5-flash", use_interactions_api=True), tools=[McpToolset(StreamableHTTPConnectionParams(...))]). Onlyinteractions_utils._create_interactions(the network call) is stubbed: it recordscreate_kwargs["input"], asks forread_fileon the first request, and answers on the second. The output below is thefunction_resultstep from the second request:Checklist
Additional context
None.