Python: Allow tool_choice: required in OpenAI Clients when using allowed_tools#7024
Merged
Conversation
tool_choice: required in OpenAI Clients when using allowed_toolstool_choice: required in OpenAI Clients when using allowed_tools
tool_choice: required in OpenAI Clients when using allowed_toolstool_choice: required in OpenAI Clients when using allowed_tools
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a behavior gap in the Python OpenAI Responses client by allowing tool_choice.mode: "required" to be used together with allowed_tools, matching the agent_framework core tool-choice contract and addressing issue #7023.
Changes:
- Update
OpenAIChatClient._prepare_optionsto preserve/translateallowed_toolsfor bothtool_choice.mode="auto"and"required". - Add unit tests covering
allowed_toolswith"required"mode (single and multiple tools) and confirming"required"withoutallowed_toolsremains a plain string.
Show a summary per file
| File | Description |
|---|---|
| python/packages/openai/agent_framework_openai/_chat_client.py | Extends tool-choice conversion logic so allowed_tools is honored for "required" mode, not only "auto". |
| python/packages/openai/tests/openai/test_openai_chat_client.py | Adds regression tests ensuring _prepare_options produces the expected OpenAI Responses API tool_choice shape for "required" + allowed_tools. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Low
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
moonbox3
approved these changes
Jul 9, 2026
giles17
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
Description & Review Guide
Allow both
autoandrequiredfortool_choicein OpenAI clients, when usingallowed_tools.Tested using
FoundryChatClient.Related Issue
Fixes #7023
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.