Skip to content

Python: Strip tools from FoundryAgent request when agent_reference is present#5101

Merged
moonbox3 merged 2 commits intomicrosoft:mainfrom
mvanhorn:fix/foundry-tools-400-5087
Apr 8, 2026
Merged

Python: Strip tools from FoundryAgent request when agent_reference is present#5101
moonbox3 merged 2 commits intomicrosoft:mainfrom
mvanhorn:fix/foundry-tools-400-5087

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 5, 2026

Summary

FoundryAgent returns HTTP 400 when both agent_reference and tools are present in the serialized request body. The parent class RawOpenAIChatClient._prepare_options() adds tools to run_options at _chat_client.py:1193, but _prepare_options() in the Foundry subclass never strips it before returning. The Foundry API rejects requests containing both fields.

Changes

  • In RawFoundryAgentChatClient._prepare_options(), add .pop() calls to remove tools, tool_choice, and parallel_tool_calls from run_options after injecting agent_reference. FunctionTools are still invoked client-side by the function invocation layer.
  • Add test_raw_foundry_agent_chat_client_prepare_options_strips_tools verifying that tools are absent from the returned options while agent_reference is preserved.

Testing

  • New test mocks parent _prepare_options to return dict with tools/tool_choice/parallel_tool_calls, asserts all three are stripped and agent_reference remains in extra_body
  • Existing test test_raw_foundry_agent_chat_client_prepare_options_accepts_function_tools still passes

Fixes #5087

This contribution was developed with AI assistance (Claude Code).

… present

_prepare_options() now removes tools, tool_choice, and parallel_tool_calls
from run_options after injecting agent_reference. The Foundry API rejects
requests containing both fields. FunctionTools are still invoked client-side
by the function invocation layer.

Fixes microsoft#5087

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 7, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry/agent_framework_foundry
   _agent.py1413475%181–182, 186–188, 193–196, 291, 320–321, 333–335, 337–338, 340–346, 348–349, 351, 353, 357–358, 545–546, 549, 591
TOTAL27034318588% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5389 20 💤 0 ❌ 0 🔥 1m 26s ⏱️

@chetantoshniwal chetantoshniwal added this pull request to the merge queue Apr 7, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 7, 2026
@moonbox3 moonbox3 enabled auto-merge April 8, 2026 04:30
@moonbox3 moonbox3 added this pull request to the merge queue Apr 8, 2026
Merged via the queue into microsoft:main with commit 18d1ba3 Apr 8, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: FoundryAgent returns 400 if both agent_reference and tools are present in request body

5 participants