-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[.NET] Add configurable MaximumAutoInvokeAttempts for ToolCallBehavior #13219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
2
commits into
main
Choose a base branch
from
copilot/fix-0f3fe104-d504-4e10-b85d-6d0d1d3fdaf3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+313
−4
Conversation
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
Co-authored-by: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com>
Copilot finished work on behalf of
markwallace-microsoft
October 6, 2025 14:08
These errors need to be fixed
|
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.
Overview
This PR adds support for configurable
MaximumAutoInvokeAttempts
in the .NET SDK's ToolCallBehavior, bringing feature parity with the Python SDK. This enables developers to control the maximum number of auto-invoke attempts for function/tool calling, providing fine-grained control over execution time, API costs, and preventing runaway loops in agentic scenarios.Motivation
When building agents that perform research tasks or other multi-step operations, developers need control over the maximum number of auto-invoke attempts to:
Changes
New Public APIs
Added factory methods and overloads across all three connectors to accept custom
maximumAutoInvokeAttempts
:OpenAI Connector:
MistralAI Connector:
Google/Gemini Connector:
Usage Example
Implementation Details
maximumAutoInvokeAttempts
parameter to all ToolCallBehavior classesKernelFunctions
,EnabledFunctions
,RequiredFunction
,AnyFunction
) to support custom valuesMaximumAutoInvokeAttempts
remains internal (not exposed as public API)CreateAutoInvokeKernelFunctions
to avoid naming conflict with existing propertyTesting
MistralAIToolCallBehaviorTests.cs
Default Values
The default values remain unchanged when using existing APIs:
Backward Compatibility
✅ Fully backward compatible - All existing code continues to work without modification. Existing static properties and methods maintain their current behavior.
Files Changed
dotnet/src/Connectors/Connectors.OpenAI/ToolCallBehavior.cs
dotnet/src/Connectors/Connectors.MistralAI/MistralAIToolCallBehavior.cs
dotnet/src/Connectors/Connectors.Google/GeminiToolCallBehavior.cs
dotnet/src/Connectors/Connectors.OpenAI.UnitTests/ToolCallBehaviorTests.cs
dotnet/src/Connectors/Connectors.MistralAI.UnitTests/MistralAIToolCallBehaviorTests.cs
(new file)dotnet/src/Connectors/Connectors.Google.UnitTests/GeminiToolCallBehaviorTests.cs
Total: 313 lines added, 4 lines modified
Fixes #[issue-number]
Original prompt
This section details on the original issue you should resolve
<issue_title>.Net New Feature: Expose configurable MaximumAutoInvokeAttempts for ToolCallBehavior</issue_title>
<issue_description>
[.NET] Expose configurable MaximumAutoInvokeAttempts for ToolCallBehavior
The .NET SDK does not expose a way to configure
MaximumAutoInvokeAttempts
for function/tool calling, while the Python SDK provides this capability through the publicmaximum_auto_invoke_attempts
property. This limits users' ability to control execution time and costs for agentic scenarios.Motivation
When building agents that perform research tasks or other multi-step operations, developers need fine-grained control over the maximum number of auto-invoke attempts to:
Real-World Use Case
I'm building an agent that performs research tasks. Sometimes I want to limit it to 5 auto-invoke attempts for quick responses, while other times I might allow more for deeper research. Currently, I'm forced to use the hardcoded defaults (128 for OpenAI) with no ability to customize per scenario.
Current State
Python SDK ✅ (Has this feature)
The Python SDK exposes
maximum_auto_invoke_attempts
as a public, configurable property:Location:
python/semantic_kernel/connectors/ai/function_choice_behavior.py
Usage Examples:
.NET SDK ❌ (Missing this feature)
The .NET SDK has
MaximumAutoInvokeAttempts
as an internal, read-only property with no public configuration API:Locations:
dotnet/src/Connectors/Connectors.OpenAI/ToolCallBehavior.cs
dotnet/src/Connectors/Connectors.Google/GeminiToolCallBehavior.cs
dotnet/src/Connectors/Connectors.MistralAI/MistralAIToolCallBehavior.cs
dotnet/src/Agents/OpenAI/Internal/ResponseThreadActions.cs
Current Implementation:
Current Defaults (Hardcoded):
Proposed Solution
Make
MaximumAutoInvokeAttempts
configurable in the .NET SDK to match Python SDK capabilities.Constructor Parameter
Usage:
Benefits
Additional Context
From
docs/decisions/0061-function-call-behavior.md
, the design principle states that function call behavior should be:Making
MaximumAutoInvokeAttempts
configurable aligns with this principle by giving users consistent control across all connectors.</issue_description>
<agent_instructions>Follow the suggested approach that is described in the issue</agent_instructions>
Comments on the Issue (you are @copilot in this section)
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.