Skip to content

Python: Fix tool normalization and provider sample consolidation#3953

Merged
eavanvalkenburg merged 5 commits intomicrosoft:mainfrom
eavanvalkenburg:bugbash_fixes
Feb 16, 2026
Merged

Python: Fix tool normalization and provider sample consolidation#3953
eavanvalkenburg merged 5 commits intomicrosoft:mainfrom
eavanvalkenburg:bugbash_fixes

Conversation

@eavanvalkenburg
Copy link
Member

@eavanvalkenburg eavanvalkenburg commented Feb 16, 2026

Summary

This PR addresses tool-normalization regressions and consolidates provider samples.

Core/runtime fixes

  • Restores callable/single-tool normalization so direct callable and single-tool inputs work consistently.
  • Changes tool-choice behavior so unset values remain unset (providers use service defaults), while explicit values are preserved.

Sample consolidation and provider coverage

  • Consolidates duplicate samples/02-agents/chat_client/* built-in samples into built_in_chat_clients.py.
  • Expands built-in client coverage to include OpenAI, Azure OpenAI (including Foundry project endpoint), Anthropic, Ollama, and Bedrock.
  • Keeps custom_chat_client.py and adds a local custom options type in that sample.

Bedrock promotion and provider-sample move

  • Adds Bedrock to agent-framework-core[all].
  • Adds Bedrock lazy import surface under agent_framework.amazon.
  • Moves Bedrock sample content into samples/02-agents/providers/amazon/ and updates related docs.

Context-provider sample updates

  • Updates context provider samples to use AzureOpenAIResponsesClient with Foundry project_endpoint + deployment_name setup where applicable.

Fixes #3577
Fixes #3946
Fixes #3945
Fixes #3936

Copilot AI review requested due to automatic review settings February 16, 2026 13:23
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Feb 16, 2026
@github-actions github-actions bot changed the title Fix tool normalization and provider sample consolidation Python: Fix tool normalization and provider sample consolidation Feb 16, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 16, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/anthropic/agent_framework_anthropic
   _chat_client.py36614959%422, 451, 483, 485, 500, 522–525, 534, 536, 573–577, 579, 581–582, 584, 589–590, 592, 625–626, 635, 637–638, 643, 660–661, 705, 724, 730, 739, 741, 745–746, 789–791, 793, 806–807, 814–816, 820–822, 826–829, 840, 842, 864, 874, 896–902, 909–910, 918–919, 927–930, 937–938, 944–945, 951–952, 958, 966–968, 972, 979–980, 986–987, 993–994, 1000, 1008–1011, 1018–1019, 1038, 1045–1046, 1065, 1087, 1089, 1098–1099, 1105, 1127–1128, 1134–1135, 1144–1154, 1161–1167, 1174–1180, 1187–1196, 1203–1206
packages/azure-ai/agent_framework_azure_ai
   _agent_provider.py122298%245, 253
   _chat_client.py4787584%388–389, 391, 574, 579–580, 582–583, 586, 589, 591, 596, 857–858, 860, 863, 866, 869–874, 877, 879, 887, 899–901, 905, 908–909, 917–920, 930, 938–941, 943–944, 946–947, 954, 962–963, 971–972, 977–978, 982–989, 994, 997, 1005, 1011, 1019–1021, 1024, 1046–1047, 1180, 1208, 1223, 1339, 1461
   _client.py2753786%379, 381, 424, 432–444, 457, 517, 532–537, 580, 615, 617, 650, 858, 861, 864–865, 867–870, 913
   _project_provider.py117496%209, 303, 343, 376
packages/core/agent_framework
   _agents.py3103987%476, 841, 877, 954–957, 1014–1016, 1130, 1143, 1156, 1162, 1198, 1200, 1209–1214, 1219, 1221, 1227–1228, 1235, 1237–1238, 1246–1247, 1250–1252, 1260–1261, 1263, 1268, 1270
   _clients.py71395%295, 488, 490
   _tools.py8199588%165–166, 303, 305, 323–325, 332, 350, 364, 371, 378, 394, 396, 403, 440, 465, 469, 486–488, 535–537, 600, 622, 680–692, 727, 738–749, 771–773, 778, 782, 796–798, 837, 906, 916, 926, 982, 1013, 1032, 1294, 1351, 1371, 1442–1446, 1568, 1572, 1622, 1624, 1640, 1642, 1707, 1734, 1791, 1859, 2042–2043, 2070, 2078, 2091, 2101–2102, 2137, 2193, 2225
   _types.py9989290%49, 58–59, 113, 118, 137, 139, 143, 147, 149, 151, 153, 171, 175, 201, 223, 228, 233, 237, 263, 267, 613–614, 985, 1047, 1064, 1082, 1087, 1105, 1115, 1132–1133, 1135, 1153–1154, 1156, 1163–1164, 1166, 1201, 1212–1213, 1215, 1253, 1480, 1532, 1623–1628, 1650, 1655, 1821, 1833, 2076, 2085, 2106, 2201, 2426, 2633, 2703, 2715, 2722, 2733, 2936–2938, 2941–2943, 2947, 2952, 2956, 3040–3042, 3071, 3125, 3129–3131, 3133, 3144–3145, 3148–3152, 3158
   exceptions.py500100% 
   observability.py6178386%346, 348–350, 353–355, 360–361, 367–368, 374–375, 382, 384–386, 389–391, 396–397, 403–404, 410–411, 418, 687, 690, 698–699, 702–705, 707, 710–712, 715–716, 744, 746, 757–759, 761–763, 767, 775, 876, 878, 1027, 1029, 1033–1038, 1040, 1043–1047, 1049, 1158–1159, 1161, 1218–1219, 1354, 1408–1409, 1525–1527, 1586, 1756, 1910, 1912
packages/core/agent_framework/openai
   _assistant_provider.py107991%163, 289, 355, 470–475
   _assistants_client.py2733487%408, 410, 412, 415, 419–420, 423, 426, 431–432, 434, 437–439, 444, 455, 480, 482, 484, 486, 488, 493, 496, 499, 503, 514, 599, 684, 713, 750–753, 823
   _chat_client.py2692391%202, 232–233, 237, 355, 362, 443–450, 452–455, 465, 550, 585, 601, 641
   _responses_client.py6137987%291–294, 298–299, 302–303, 309–310, 315, 328–334, 355, 363, 386, 549, 552, 607, 611, 613, 615, 617, 693, 703, 708, 751, 829, 846, 859, 915, 1008, 1013, 1017–1019, 1023–1024, 1047, 1116, 1138–1139, 1154–1155, 1173–1174, 1305–1306, 1322, 1324, 1403–1411, 1506, 1561, 1576, 1612–1613, 1615–1617, 1631–1633, 1643–1644, 1650, 1665
TOTAL20563323884% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3955 225 💤 0 ❌ 0 🔥 1m 9s ⏱️

Copy link
Contributor

Copilot AI left a comment

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 restores callable/single-tool normalization and unset tool-choice handling, consolidates chat client samples, migrates Bedrock to the agent_framework.amazon namespace, and updates context provider samples to use AzureOpenAIResponsesClient with Foundry project endpoint setup.

Changes:

  • Restored tool normalization to accept single tools, callables, and sequences via unified normalize_tools() function, fixing issues #3936, #3946, and #3577
  • Changed validate_tool_mode() to return None when tool_choice is unset (instead of {'mode': 'none'}), allowing clients to omit the parameter
  • Migrated Bedrock to lazy-import agent_framework.amazon namespace, promoted in core[all], and relocated sample to providers/amazon/
  • Consolidated chat client samples into single built_in_chat_clients.py with factory pattern supporting OpenAI, Azure, Anthropic, Ollama, and Bedrock
  • Updated all context provider samples (Redis, Mem0, Azure AI Search, simple) to use AzureOpenAIResponsesClient with Foundry project endpoints

Reviewed changes

Copilot reviewed 45 out of 47 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/packages/core/agent_framework/_tools.py Added ToolTypes and normalize_tools() to handle single tools, callables, and sequences uniformly; supports tools passed via kwargs
python/packages/core/agent_framework/_types.py Updated validate_tool_mode() to return None when unset; updated tool type annotations to use ToolTypes
python/packages/core/agent_framework/_agents.py Updated Agent tool parameter types to use ToolTypes; simplified tool normalization logic
python/packages/core/agent_framework/_clients.py Updated as_agent() tool parameter types to use ToolTypes
python/packages/core/agent_framework/openai/_chat_client.py Updated _prepare_tools_for_openai() to use normalize_tools()
python/packages/core/agent_framework/openai/_assistants_client.py Updated to use normalize_tools(); added null check for tool_mode before setting tool_choice
python/packages/core/agent_framework/openai/_assistant_provider.py Updated tool type annotations to use ToolTypes; filter out MCP tools before passing to assistant API
python/packages/core/agent_framework/amazon/__init__.py New lazy-import module for Bedrock package via agent_framework.amazon namespace
python/packages/core/pyproject.toml Added agent-framework-bedrock to all extra
python/uv.lock Promoted Bedrock in dependency resolution
python/packages/bedrock/agent_framework_bedrock/_chat_client.py Updated import path in docstring to agent_framework.amazon
python/packages/bedrock/README.md Updated sample reference to new location under providers/amazon/
python/packages/bedrock/AGENTS.md Updated import path examples to agent_framework.amazon
python/packages/bedrock/samples/bedrock_sample.py Deleted (moved to samples/02-agents/providers/amazon/)
python/samples/02-agents/providers/amazon/bedrock_chat_client.py New consolidated Bedrock sample with tool usage
python/samples/02-agents/providers/amazon/README.md New README documenting Bedrock sample and environment variables
python/samples/02-agents/providers/README.md Added Bedrock provider entry to overview
python/samples/02-agents/chat_client/built_in_chat_clients.py New consolidated sample supporting 11 client types via factory pattern
python/samples/02-agents/chat_client/README.md Updated to document consolidated sample approach
python/samples/02-agents/chat_client/*.py (deleted) Removed individual client samples (openai_, azure_, azure_ai_*) in favor of consolidated approach
python/samples/02-agents/context_providers/simple_context_provider.py Updated to use AzureOpenAIResponsesClient with Foundry endpoints; improved state management
python/samples/02-agents/context_providers/redis/*.py Updated all Redis samples to use AzureOpenAIResponsesClient and added source_id parameter
python/samples/02-agents/context_providers/redis/README.md Updated environment variable documentation for Foundry setup
python/samples/02-agents/context_providers/mem0/*.py Added source_id parameter to all Mem0ContextProvider instances
python/samples/02-agents/context_providers/azure_ai_search/*.py Added source_id parameter to AzureAISearchContextProvider (fixes #3945)
python/samples/02-agents/response_stream.py Fixed ChatResponse construction to use messages list instead of text/role
python/samples/02-agents/typed_options.py Moved model_id to client constructor instead of options dict
python/samples/01-get-started/README.md Updated to use Azure Foundry environment variables
python/samples/01-get-started/01_hello_agent.py Added note about XML tags in samples
python/packages/core/tests/openai/test_openai_chat_client.py Added test for single FunctionTool normalization
python/packages/core/tests/openai/test_openai_assistants_client.py Added tests for tool_choice handling and single tool normalization
python/packages/core/tests/core/test_types.py Updated test for validate_tool_mode(None) to expect None instead of {'mode': 'none'}
python/packages/core/tests/core/test_function_invocation_logic.py Added test for tools passed via kwargs

eavanvalkenburg and others added 5 commits February 16, 2026 17:00
- restore callable/single-tool normalization paths and unset tool-choice behavior\n- consolidate and expand chat/provider samples (OpenAI/Azure/Anthropic/Ollama/Bedrock)\n- migrate Bedrock lazy import surface to agent_framework.amazon and move provider samples

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Feb 16, 2026
Merged via the queue into microsoft:main with commit aab621f Feb 16, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

3 participants