Skip to content

fix: add function_response check to _part_has_payload#4356

Closed
filipecaixeta wants to merge 1 commit intogoogle:mainfrom
filipecaixeta:fix-part-has-payload-function-response
Closed

fix: add function_response check to _part_has_payload#4356
filipecaixeta wants to merge 1 commit intogoogle:mainfrom
filipecaixeta:fix-part-has-payload-function-response

Conversation

@filipecaixeta
Copy link

Summary

  • Add function_response check to _part_has_payload function in lite_llm.py
  • Fixes issue where _append_fallback_user_content_if_missing was adding the fallback message "Handle the requests as specified in the System Instruction." even when a valid function response was present in user content
  • Added comprehensive unit tests for both _part_has_payload and _append_fallback_user_content_if_missing with function_response scenarios

Problem

The _part_has_payload function checks whether a Part contains usable payload for the model, but it was missing a check for function_response. This caused the fallback user content to be injected unnecessarily when a user message contained only a function response, leading to:

  • Extra tokens being added to requests
  • Potential confusion in model responses
  • Incorrect behavior in function call/response flows

Changes

src/google/adk/models/lite_llm.py:

if part.function_response and part.function_response.response:
    return True

tests/unittests/models/test_litellm.py:

  • Added TestPartHasPayload class with 6 unit tests
  • Added TestAppendFallbackUserContentIfMissing class with 5 unit tests

Test plan

  • All new unit tests pass (11 tests)
  • Existing related tests pass (test_generate_content_async_adds_fallback_user_message, test_maybe_append_user_content)
  • Tests cover edge cases: empty response, valid response, text content, empty parts

The _part_has_payload function was not checking for function_response
content, causing _append_fallback_user_content_if_missing to add the
fallback message "Handle the requests as specified in the System
Instruction." even when a valid function response was present.

This fix adds a check for part.function_response.response to properly
detect when a Part contains function response payload.

Added unit tests for:
- _part_has_payload function with various payload types
- _append_fallback_user_content_if_missing with function_response
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @filipecaixeta, 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 refines the logic for handling function_response objects within LLM requests. By updating the _part_has_payload utility, it ensures that valid function responses are properly recognized, thereby preventing the erroneous injection of a fallback user message. This change optimizes token usage and enhances the accuracy of model interactions, particularly in function calling workflows.

Highlights

  • Function Response Handling: The _part_has_payload function now correctly identifies valid function_response payloads, preventing unnecessary fallback messages from being added to LLM requests.
  • Fallback Message Correction: Resolved an issue where _append_fallback_user_content_if_missing would erroneously inject a default user message even when a valid function response was present, leading to token waste and potential model confusion.
  • Comprehensive Testing: New unit tests have been added for both _part_has_payload and _append_fallback_user_content_if_missing to cover various scenarios, including function responses, empty responses, and other edge cases.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 correctly addresses an issue where a fallback user message was being added unnecessarily for messages containing a function_response. The fix in _part_has_payload is simple and effective. The newly added unit tests are comprehensive, covering both the changed function and the dependent logic in _append_fallback_user_content_if_missing, which ensures the fix is robust and prevents regressions. The code quality is excellent. Great work!

@filipecaixeta
Copy link
Author

I'm closing this PR since someone was faster and solved it already

@ryanaiagent ryanaiagent self-assigned this Feb 2, 2026
@ryanaiagent ryanaiagent added the models [Component] Issues related to model support label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants