Skip to content

Python: Allow tool_choice: required in OpenAI Clients when using allowed_tools#7024

Merged
giles17 merged 1 commit into
microsoft:mainfrom
cecheta:allowed-tools
Jul 9, 2026
Merged

Python: Allow tool_choice: required in OpenAI Clients when using allowed_tools#7024
giles17 merged 1 commit into
microsoft:mainfrom
cecheta:allowed-tools

Conversation

@cecheta

@cecheta cecheta commented Jul 9, 2026

Copy link
Copy Markdown
Member

Motivation & Context

Description & Review Guide

Allow both auto and required for tool_choice in OpenAI clients, when using allowed_tools.
Tested using FoundryChatClient.

Related Issue

Fixes #7023

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings July 9, 2026 15:49
@giles17 giles17 added the python Usage: [Issues, PRs], Target: Python label Jul 9, 2026
@github-actions github-actions Bot changed the title feat: Allow tool_choice: required in OpenAI Clients when using allowed_tools Python: feat: Allow tool_choice: required in OpenAI Clients when using allowed_tools Jul 9, 2026
@cecheta cecheta changed the title Python: feat: Allow tool_choice: required in OpenAI Clients when using allowed_tools Python: Allow tool_choice: required in OpenAI Clients when using allowed_tools Jul 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_options to preserve/translate allowed_tools for both tool_choice.mode = "auto" and "required".
  • Add unit tests covering allowed_tools with "required" mode (single and multiple tools) and confirming "required" without allowed_tools remains 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

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/openai/agent_framework_openai
   _chat_client.py127712790%307, 320, 670–674, 682–685, 691–695, 745–752, 754–756, 763–765, 823, 831, 854, 972, 1071, 1130, 1132, 1134, 1136, 1202, 1216, 1296, 1306, 1311, 1354, 1465–1466, 1481, 1705, 1710, 1714–1716, 1720–1721, 1804, 1814, 1841, 1847, 1857, 1863, 1868, 1874, 1879–1880, 1960, 2004, 2007–2010, 2024, 2026, 2034–2035, 2047, 2089, 2154, 2171, 2174, 2201–2203, 2242, 2259, 2262, 2324, 2331, 2355–2356, 2391, 2429–2430, 2448–2449, 2492, 2619–2620, 2638, 2721–2729, 2759, 2904, 2919, 2968–2971, 2981–2983, 3010–3012, 3022–3023, 3029, 3044, 3166–3167
TOTAL44093527488% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8828 33 💤 0 ❌ 0 🔥 2m 35s ⏱️

@giles17 giles17 added this pull request to the merge queue Jul 9, 2026
Merged via the queue into microsoft:main with commit 7440b1c Jul 9, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Function calling allowed_tools does not work with mode: required for OpenAI clients

4 participants