Skip to content

fix(models): keep text sent alongside a function response in ApigeeLlm - #7476

Closed
AkshayShah03 wants to merge 1 commit into
google:mainfrom
AkshayShah03:fix/apigee-text-with-function-response
Closed

AkshayShah03 wants to merge 1 commit into
google:mainfrom
AkshayShah03:fix/apigee-text-with-function-response

Conversation

@AkshayShah03

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
In the Chat Completions path of ApigeeLlm, CompletionsHTTPClient._content_to_messages returned early when a Content held a function_response, emitting only the tool messages (plus any tool-attached media). Text or media parts sent in the same Content were collected into content_parts but never used, so they were silently dropped from the request.

Solution:
A tool-role message carries only the tool result, so the remaining parts now follow the tool messages in a single user message, together with any tool-attached media (media first, then the other parts). A lone text part collapses to a plain string, matching the non-tool branch. This mirrors how LiteLlm already handles the same case (_content_to_message_param sends leftover parts as a follow-up message).

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added to tests/unittests/models/test_apigee_llm.py:

  • test_content_conversion_keeps_text_alongside_function_response: function response + text → tool message, then {"role": "user", "content": "<text>"}.
  • test_content_conversion_keeps_text_alongside_function_response_media: function response with attached image + text → tool message, then one user message with the image and the text.

Both fail on main and pass with this change. The existing media-only and no-media tests are unchanged and still pass.

$ pytest tests/unittests/models/
1523 passed, 33 warnings in 11.95s

pyink and isort report no changes.

Manual End-to-End (E2E) Tests:

Not run against a live Apigee / OpenAI-compatible backend. The reproduction snippet from #7475 prints only the tool message on main and the tool message followed by the user text message with this change.

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.

@google-cla

google-cla Bot commented Oct 9, 2026

Copy link
Copy Markdown

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.

@AkshayShah03

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

In the Chat Completions path, _content_to_messages returned only the tool
messages (plus tool-attached media) when a Content held a function_response,
silently dropping any text or media parts sent with it. Those parts now follow
the tool messages in a single user message, matching LiteLlm.

Fixes google#7475
@AkshayShah03
AkshayShah03 force-pushed the fix/apigee-text-with-function-response branch from 3d76ae5 to ef816e3 Compare October 9, 2026 12:07
copybara-service Bot pushed a commit that referenced this pull request Oct 9, 2026
@adk-bot

adk-bot commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Thank you @AkshayShah03 for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit f5db310.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Oct 9, 2026
@adk-bot adk-bot closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ApigeeLlm (Chat Completions): text sent alongside a function_response is silently dropped

3 participants