Skip to content

fix(models): force the single allowed function in ApigeeLlm tool_choice - #8101

Open
prassu017 wants to merge 1 commit into
google:mainfrom
prassu017:fix-8100-apigee-allowed-function
Open

prassu017 wants to merge 1 commit into
google:mainfrom
prassu017:fix-8100-apigee-allowed-function

Conversation

@prassu017

Copy link
Copy Markdown

Link to Issue or Description of Change

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

Problem:
CompletionsHTTPClient._map_tools maps only FunctionCallingConfig.mode. With mode=ANY and allowed_function_names=["lookup_order"], the Chat Completions request carries "tool_choice": "required", so the model may call any declared tool.

Solution:
When mode=ANY has exactly one allowed name, send the named choice {"type": "function", "function": {"name": ...}}, the same rule AnthropicLlm._build_tool_choice uses. Other cases are unchanged ("required" for zero or several names). This PR does not cover VALIDATED or a multi-name subset (allowed_tools / filtering tools), which the issue also mentions; that needs a design choice from maintainers.

Testing Plan

Unit Tests:

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

New test_construct_payload_any_mode_with_allowed_function_names (one name, two names, none). On main (59b0dd6) the one-name case fails with assert 'required' == {'function': {'name': 'lookup_order'}, 'type': 'function'}; with the fix:

pytest tests/unittests/models/test_apigee_llm.py
81 passed

Only that file ran (Python 3.13); the full suite and tox were not run. pyink --check and isort --check-only pass on both files.

Manual End-to-End (E2E) Tests:

Not run (no Apigee proxy). The unit test asserts the payload sent to /chat/completions.

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

AI-assisted; tests run locally.

With mode ANY and one allowed_function_names entry, Chat Completions
requests now send a named function tool_choice instead of "required",
matching AnthropicLlm.

Fixes google#8100
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.

ApigeeLlm (Chat Completions) ignores FunctionCallingConfig.allowed_function_names and the VALIDATED mode

2 participants