-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[bugfix] Fix bug with exploding agent runs due to broken conversion of content Parts to LiteLLM messages format #4303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…-tool-response-content-for-litellm-models Make _part_has_payload respect function response
|
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. |
Summary of ChangesHello @alexkuzmik, 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 resolves a critical bug affecting agents utilizing LiteLLM models in Highlights
🧠 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 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. 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
|
There was a problem hiding this 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 addresses a critical bug that could cause agent runs to enter expensive, token-burning loops. The fix correctly identifies function_response as a valid payload within a content part, preventing an erroneous fallback message from being added after tool calls. The change in src/google/adk/models/lite_llm.py is correct and effectively resolves the issue.
While a unit test was added, it was placed in a test suite that doesn't validate the actual bug fix. I've provided a detailed comment with a suggestion for a new test function that will properly ensure this regression doesn't occur in the future. Once the test is corrected, this PR should be good to merge.
|
/gemini review |
There was a problem hiding this 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 addresses a critical bug that could cause agent runs to enter expensive, infinite loops when using LiteLLM models. The pull request description clearly explains the problem with illustrative examples, which is very helpful for understanding the impact of the bug. The root cause was that a function_response was not being correctly identified as a payload, which triggered the addition of a fallback message that confused the agent.
The fix is simple and effective: _part_has_payload is updated to correctly recognize function_response as a valid payload. The accompanying unit test is well-written and thoroughly validates that the fallback message is no longer added in this scenario.
Overall, this is an excellent contribution that resolves a significant issue. The code changes are clean, targeted, and well-tested.
|
Hi @alexkuzmik , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
Problem:
Hi! Opik engineer is here :)
Our integration tests caught a serious regression in
google-adkafter your latest release (1.23.0).If you're using agents with LiteLLM models, your application might degrade significantly starting from 1.23.0.
Reason: when converting content parts to the litellm format, there is a piece of logic that checks if a content part from the user contains payload. If it doesn't, a user message "Handle the requests as specified in the System Instruction." is added to the end of the message list. The function
google.adk.models.lite_llm._part_has_payloadreturns False if the content is just a function response!So, this fallback user message is added to the end of the chat payload after every tool call and it can affect the agent drastically.
The issue is not consistent; sometimes models ignore this instruction, sometimes they go into a long and expensive loop where they focus on this "Handle the requests as specified in the System Instruction." Here are the traces screenshots for the simplest weather-time agent, whichis supposed to have "llm -> tool -> llm" structure but instead explodes into 30 seconds run that just burns tokens.
"Lite" regression. A few unnecessary tool calls.

Hard case, pay attention to the token consumption and time - 24k and 25 seconds (I saw the cases with 60-70k tokens so this is one is actually quite far from the worst scenario).

Solution:
Updated
_part_has_payloadto respect the function response and treat it as a payload too.Testing Plan
Tested manually with openai models, also looked into Litellm spans directly to make sure this extra instruction no longer passed to
litellm.completion/acompletion.Unit Tests:
Too much warnings in the end, but all the 4027 unit tests passed :)
Manual End-to-End (E2E) Tests:
I used this script, but I suppose that any other might reproduce it as well with higher or lower chance, depending on the model/system instruction/tool/input message. Openai gpt-4o-mini fails most of the time, gpt-5-nano seems smarter and more resilient to this "last message attack". Not sure about any other providers but I don't think it matters.
(script contains opik logic, feel free to remove it if you're using another observability tool)
Checklist