Skip to content

fix(models): let LiteLlm pin the tool-result role - #7042

Open
claxman wants to merge 2 commits into
google:mainfrom
claxman:fix/6482-litellm-tool-result-role
Open

fix(models): let LiteLlm pin the tool-result role#7042
claxman wants to merge 2 commits into
google:mainfrom
claxman:fix/6482-litellm-tool-result-role

Conversation

@claxman

@claxman claxman commented Sep 7, 2026

Copy link
Copy Markdown

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:
_content_to_message_param sets role tool_responses whenever the model name matches Gemma-4. On this tree, google/gemma-4-e4b yields tool_responses and openai/gpt-4o yields tool. grep tool_result_role src/google/adk/models/lite_llm.py was empty. #6482 reports that this breaks servers that validate OpenAI roles.

Solution:
LiteLlm(tool_result_role="tool") is a declared field that pins the role. Unset keeps Gemma-4 auto-detect. It is popped from _additional_args so LiteLLM does not see it. _resolve_tool_result_role is used by _content_to_message_param, _ensure_tool_results, and _get_completion_inputs.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
PYTHONPATH=src .venv/bin/python -m pytest -q tests/unittests/models/test_lite_llm_gemma_tool_role.py

14 passed.

Reverted lite_llm.py to b018062 and reran the file: 6 failed, 8 passed. Restored: 14 passed.

Manual End-to-End (E2E) Tests:

Not run here. No LM Studio on this machine. The LM Studio gemma-4-e4b repro from the issue with LiteLlm(model=..., tool_result_role="tool") would cover it if the reporter can run it.

Additional context

Claim: #6482 (comment)

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.

Gemma-4 names always sent role=tool_responses. Servers that validate
OpenAI roles reject that value. An explicit tool_result_role keeps the
auto-detect as the default.

Fixes google#6482
A PrivateAttr drop silently lost the override on model_dump and
model_copy. Other BaseLlm knobs are declared fields.

Fixes google#6482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LiteLLM] role='tool_responses' for Gemma-4 models breaks tool calling on LM Studio (strict OpenAI role validation)

2 participants