Skip to content

feat: Add tool_choice config to LlmAgent for controlling tool invocation#5984

Open
Oxygen56 wants to merge 3 commits into
google:mainfrom
Oxygen56:feat/tool-choice
Open

feat: Add tool_choice config to LlmAgent for controlling tool invocation#5984
Oxygen56 wants to merge 3 commits into
google:mainfrom
Oxygen56:feat/tool-choice

Conversation

@Oxygen56
Copy link
Copy Markdown

@Oxygen56 Oxygen56 commented Jun 5, 2026

Summary

Adds a tool_choice field to LlmAgent that maps provider-agnostic values (auto, required, none) to Google GenAI's ToolConfig / FunctionCallingConfig.

Changes

  • llm_agent.py: tool_choice field with Literal type and docstring
  • base_llm_flow.py: Maps tool_choicetypes.ToolConfig(function_calling_config=...)
  • tests/unittests/agents/test_tool_choice.py: 8 unit tests

Testing Plan

pytest tests/unittests/agents/test_tool_choice.py -v

Tests cover:

  • Field declaration existence and default value
  • tool_choice="required"FunctionCallingConfigMode.ANY
  • tool_choice="none"FunctionCallingConfigMode.NONE
  • tool_choice="auto" / unset → no config forced
  • Full ToolConfig structure verification

🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Jun 5, 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.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Jun 5, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Jun 5, 2026

Response from ADK Triaging Agent

Hello @Oxygen56, thank you for creating this PR to add tool_choice configuration!

This is a great feature, but to help us review and merge your contribution, could you please address the following items according to our contribution guidelines:

  1. Contributor License Agreement (CLA): It looks like the Google CLA check has failed. Please visit https://cla.developers.google.com/ to sign or verify your agreement.
  2. Testing Plan & Unit Tests: Please include a testing plan section in your PR description describing how you tested this change. Additionally, please add or update unit tests (under tests/unittests/) for your new feature.
  3. Logs/Screenshots: Since this is a new feature, please provide logs or a screenshot of the fix working in action (for example, demonstrating that the tool choice constraint behaves as expected).

These details will help our reviewers process your PR much faster. Thank you!

@rohityan rohityan self-assigned this Jun 5, 2026
@rohityan
Copy link
Copy Markdown
Collaborator

rohityan commented Jun 5, 2026

Hi @Oxygen56 , Thank you for your contribution! It appears you haven't yet signed the Contributor License Agreement (CLA). Please visit https://cla.developers.google.com/ to complete the signing process. Once the CLA is signed, we'll be able to proceed with the review of your PR. Thank you!

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Jun 5, 2026
Oxygen56 added 3 commits June 6, 2026 10:04
Adds a provider-agnostic 'tool_choice' field to LlmAgent that maps to
provider-specific tool configuration:

- 'auto' (default): Model decides whether to call tools
- 'required': Model MUST call at least one tool before responding —
  prevents hallucinated responses when tools are available
- 'none': Model MUST NOT call any tools

The mapping to Google GenAI's ToolConfig/FunctionCallingConfig happens
in base_llm_flow.py's _call_llm_async method, which already handles
request configuration. LiteLLM and other providers can add their own
mappings in their respective LLM implementations.

Fixes google#773
@Oxygen56 Oxygen56 force-pushed the feat/tool-choice branch from 053d9cc to 75bb20b Compare June 6, 2026 02:04
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Jun 6, 2026

🔍 ADK Pull Request Analysis: PR #5984

Title: feat: Add tool_choice config to LlmAgent for controlling tool invocation
Author: @Oxygen56
Status: open


🛑 Compliance Refusal: Contributor License Agreement (CLA) Not Signed

Under Google's open-source compliance guidelines and the ADK project development workflow, we are strictly prohibited from performing code analysis, triage, diff evaluation, or any workspace operations on pull requests where the contributor has not signed the Google Contributor License Agreement (CLA).

Based on our verification, the Google CLA check for this PR is currently failing:

  • The Google CLA Bot has flagged that the contributor has not yet signed the agreement.
  • Maintainers have requested CLA signature, and no signature has been completed.

Next Steps for the Contributor

To proceed with the review and potential merge of this Pull Request, please:

  1. Visit the Google Developers CLA Portal.
  2. Sign or verify your Contributor License Agreement.
  3. Once the CLA check on GitHub turns green, we will be more than happy to perform a

@Oxygen56
Copy link
Copy Markdown
Author

Oxygen56 commented Jun 6, 2026

@adk-bot CLA has been signed. Ready for re-review.

@Oxygen56
Copy link
Copy Markdown
Author

Oxygen56 commented Jun 6, 2026

@rohityan @adk-bot All checks are now passing (cla/google ✅, header-check ✅, pr-analyze ✅, check-changes ✅). The CLA has been signed and there are no remaining blockers.

Ready for review — thanks for your time!

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

Labels

core [Component] This issue is related to the core interface and implementation request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants