Skip to content

Conversation

@dineshkrishna9999
Copy link

Link to Issue or Description of Change

  1. Link to an existing issue (if applicable):
  1. Or, if no issue exists, describe the change:
    Problem: When using LiteLLM with OpenAI/Azure models, types.Part objects containing only a function_response were incorrectly treated as having no payload in _part_has_payload. This caused _append_fallback_user_content_if_missing to inject an unintended fallback user message, breaking the tool calling flow and potentially triggering content safety filters.

Solution: Updated _part_has_payload in src/google/adk/models/lite_llm.py to correctly identify function_response as a valid payload. This prevents the unnecessary injection of the fallback user message when a function response is present.

Testing Plan

Unit Tests

  • I have added a new unit test for this change: tests/unittests/models/test_litellm_function_response.py
  • All unit tests pass locally.

Summary of pytest results:

uv run pytest tests/unittests/models/test_litellm_function_response.py
# tests/unittests/models/test_litellm_function_response.py .. [100%]
# ============================== 2 passed in 0.12s ===============================

Regression testing on full lite_llm suite:

uv run pytest tests/unittests/models/test_litellm.py
# ============================= 176 passed in 3.61s ==============================

Manual End-to-End (E2E) Tests

  1. Verified that part.function_response is now correctly recognized as a payload.
  2. Verified that the fallback user message is NOT appended when a function response is present.
  3. Ran compliance checks with ./autoformat.sh.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Fixes google#4249. Added support for function_response in _part_has_payload.
@google-cla
Copy link

google-cla bot commented Jan 29, 2026

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dineshkrishna9999, 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 addresses a critical bug in the LiteLLM integration, specifically when handling types.Part objects containing function_response with OpenAI/Azure models. Previously, these parts were not recognized as having a payload, leading to the incorrect injection of a fallback user message. This unintended behavior disrupted the tool calling mechanism and could trigger content safety filters. The changes ensure that function_response is now correctly identified as a valid payload, thereby preventing the erroneous message injection and restoring proper tool calling functionality.

Highlights

  • Function Response Payload Recognition: The _part_has_payload function now correctly identifies function_response as a valid payload within types.Part objects. This resolves an issue where such parts were previously treated as empty.
  • Tool Calling Fix: This change prevents the unintended injection of fallback user messages, which was breaking the tool calling flow when using LiteLLM with OpenAI/Azure models.
  • New Unit Test: A dedicated unit test file, test_litellm_function_response.py, has been added to specifically verify the correct handling of function_response payloads.
  • Code Readability Improvements: Minor formatting adjustments have been applied to several functions within src/google/adk/models/lite_llm.py to enhance code readability.

🧠 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.

@adk-bot adk-bot added the models [Component] Issues related to model support label Jan 29, 2026
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 effectively addresses the issue of function_response not being correctly identified as a payload in _part_has_payload, which was causing unintended fallback user messages and breaking tool calling flows. The addition of the if part.function_response: return True condition directly resolves the problem. The new unit tests in tests/unittests/models/test_litellm_function_response.py provide good coverage for this fix, ensuring the updated logic works as expected. The other changes are primarily stylistic and improve code readability without altering functionality.

@dineshkrishna9999
Copy link
Author

@google-cla check

@ryanaiagent ryanaiagent self-assigned this Jan 29, 2026
@dineshkrishna9999
Copy link
Author

Submitted with the latest changes

Thank you,
Dinesh Karakambaka

@ryanaiagent ryanaiagent added the needs review [Status] The PR/issue is awaiting review from the maintainer label Jan 30, 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 needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unintended user message injection breaks tool calling with LiteLLM + OpenAI/Azure

3 participants