Commit 570a4d5
Python: Support OpenAI and Gemini
* Support OpenAI allowed_tools in ToolMode (#5309)
Add allowed_tools field to ToolMode TypedDict, enabling users to restrict
which tools the model may call via the OpenAI allowed_tools tool_choice
type. This preserves prompt caching by keeping all tools in the tools list
while limiting which ones the model can invoke.
- Add allowed_tools: list[str] to ToolMode TypedDict
- Add validation in validate_tool_mode() (only valid when mode == "auto")
- Convert to OpenAI API format in _prepare_options()
- Add tests for validation and API payload generation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Python: Support OpenAI `allowed_tools` tool choice in Python SDK
Fixes #5309
* Fix #5309: Validate allowed_tools shape and add Chat Completions client support
- validate_tool_mode now checks allowed_tools is a non-string sequence of
strings and normalizes to list[str], raising ContentError for invalid types
- Add missing allowed_tools branch in _chat_completion_client._prepare_options
so allowed_tools is emitted as the OpenAI allowed_tools wire format instead
of being silently dropped
- Add tests for invalid allowed_tools types (string, int, mixed), empty list,
tuple normalization, and Chat Completions client payload generation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: support allowed_tools with mode 'required' in addition to 'auto'
OpenAI's allowed_tools tool_choice type supports both mode 'auto' and
'required'. Update validation, client conversion, and tests to allow
both modes instead of restricting to 'auto' only.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: use Gemini VALIDATED mode for allowed_tools, warn in unsupported providers
- Use FunctionCallingConfigMode.VALIDATED instead of ANY when allowed_tools
is set with auto mode in Gemini, preserving optional tool-call semantics.
- Handle allowed_tools in required mode with required_function_name precedence.
- Fix allowed_names guard to use identity check (is not None) so empty lists
are preserved.
- Bump google-genai minimum to >=1.32.0 (VALIDATED added in that version).
- Add warnings in Anthropic and Bedrock when allowed_tools is set but not
supported.
- Add Gemini unit tests for allowed_tools with auto, required, empty list,
and required_function_name precedence scenarios.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: Chat Completions API does not support allowed_tools, add integration tests
- Chat Completions API (_chat_completion_client.py) now warns and falls
back to plain mode when allowed_tools is set, since the /chat/completions
endpoint does not support the allowed_tools type.
- Add allowed_tools integration test param to both OpenAIChatClient
(Responses API) and OpenAIChatCompletionClient parametrized option tests.
- Update Chat Completions unit tests to reflect the warn-and-fallback
behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: remove unused walrus operator variable in chat completion client
Remove assigned-but-never-used variable 'allowed' flagged by ruff F841.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>allowed_tools tool choice (#5322)1 parent f5419b9 commit 570a4d5
11 files changed
Lines changed: 912 additions & 605 deletions
File tree
- python
- packages
- anthropic/agent_framework_anthropic
- bedrock/agent_framework_bedrock
- core
- agent_framework
- tests/core
- gemini
- agent_framework_gemini
- tests
- openai
- agent_framework_openai
- tests/openai
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
| 875 | + | |
| 876 | + | |
875 | 877 | | |
876 | 878 | | |
877 | 879 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
408 | 410 | | |
409 | 411 | | |
410 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3246 | 3246 | | |
3247 | 3247 | | |
3248 | 3248 | | |
| 3249 | + | |
3249 | 3250 | | |
3250 | 3251 | | |
3251 | 3252 | | |
3252 | 3253 | | |
| 3254 | + | |
3253 | 3255 | | |
3254 | 3256 | | |
3255 | 3257 | | |
| |||
3482 | 3484 | | |
3483 | 3485 | | |
3484 | 3486 | | |
3485 | | - | |
| 3487 | + | |
3486 | 3488 | | |
3487 | 3489 | | |
3488 | 3490 | | |
| |||
3499 | 3501 | | |
3500 | 3502 | | |
3501 | 3503 | | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
3502 | 3515 | | |
3503 | 3516 | | |
3504 | 3517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1087 | 1087 | | |
1088 | 1088 | | |
1089 | 1089 | | |
| 1090 | + | |
1090 | 1091 | | |
1091 | 1092 | | |
1092 | 1093 | | |
1093 | 1094 | | |
| 1095 | + | |
1094 | 1096 | | |
1095 | 1097 | | |
1096 | 1098 | | |
1097 | 1099 | | |
1098 | 1100 | | |
1099 | 1101 | | |
| 1102 | + | |
| 1103 | + | |
1100 | 1104 | | |
1101 | 1105 | | |
1102 | 1106 | | |
| |||
1154 | 1158 | | |
1155 | 1159 | | |
1156 | 1160 | | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
1157 | 1200 | | |
1158 | 1201 | | |
1159 | 1202 | | |
| |||
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
826 | | - | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
827 | 831 | | |
828 | 832 | | |
829 | 833 | | |
830 | 834 | | |
831 | 835 | | |
832 | | - | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
833 | 842 | | |
834 | 843 | | |
835 | 844 | | |
836 | 845 | | |
837 | 846 | | |
838 | | - | |
| 847 | + | |
839 | 848 | | |
840 | 849 | | |
841 | 850 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1157 | 1157 | | |
1158 | 1158 | | |
1159 | 1159 | | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1160 | 1240 | | |
1161 | 1241 | | |
1162 | 1242 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
1299 | 1305 | | |
1300 | 1306 | | |
1301 | 1307 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
662 | 662 | | |
663 | 663 | | |
664 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
665 | 671 | | |
666 | 672 | | |
667 | 673 | | |
| |||
Lines changed: 90 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4259 | 4259 | | |
4260 | 4260 | | |
4261 | 4261 | | |
| 4262 | + | |
| 4263 | + | |
| 4264 | + | |
| 4265 | + | |
| 4266 | + | |
| 4267 | + | |
4262 | 4268 | | |
4263 | 4269 | | |
4264 | 4270 | | |
| |||
4813 | 4819 | | |
4814 | 4820 | | |
4815 | 4821 | | |
| 4822 | + | |
| 4823 | + | |
| 4824 | + | |
| 4825 | + | |
| 4826 | + | |
| 4827 | + | |
| 4828 | + | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
| 4832 | + | |
| 4833 | + | |
| 4834 | + | |
| 4835 | + | |
| 4836 | + | |
| 4837 | + | |
| 4838 | + | |
| 4839 | + | |
| 4840 | + | |
| 4841 | + | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
| 4846 | + | |
| 4847 | + | |
| 4848 | + | |
| 4849 | + | |
| 4850 | + | |
| 4851 | + | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
| 4855 | + | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
| 4860 | + | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
| 4872 | + | |
| 4873 | + | |
| 4874 | + | |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
4816 | 4906 | | |
4817 | 4907 | | |
4818 | 4908 | | |
| |||
0 commit comments