Heuristic:Microsoft Agent framework Function Invocation Defaults
| Knowledge Sources | |
|---|---|
| Domains | AI_Agents, Optimization |
| Last Updated | 2026-02-11 16:45 GMT |
Overview
The framework defaults to a maximum of 40 function invocation iterations and 3 consecutive errors per request, providing automatic termination guards for tool invocation loops.
Description
When an Agent processes a request, the LLM may invoke tools in a loop (call tool, get result, call another tool, etc.). The framework enforces two safety limits: `DEFAULT_MAX_ITERATIONS` (40) prevents infinite tool loops, and `DEFAULT_MAX_CONSECUTIVE_ERRORS_PER_REQUEST` (3) stops processing if tools keep failing. These defaults are defined as `Final` constants and can be overridden via `FunctionInvocationConfiguration`.
Usage
Be aware of these defaults when building agents that use many tools or complex tool chains. If your use case requires more than 40 tool calls per request (e.g., deep research agents), increase the limit. If your tools are flaky, consider increasing the error threshold. Conversely, for simple agents, you may want to lower these values for faster failure detection.
The Insight (Rule of Thumb)
- Action: Be aware of `DEFAULT_MAX_ITERATIONS=40` and `DEFAULT_MAX_CONSECUTIVE_ERRORS_PER_REQUEST=3`.
- Value: Override via `FunctionInvocationConfiguration` if your use case requires different limits.
- Trade-off: Higher limits allow more complex tool chains but increase cost and latency. Lower limits fail faster but may cut off legitimate multi-step operations.
Reasoning
From `python/packages/core/agent_framework/_tools.py:87-88`:
DEFAULT_MAX_ITERATIONS: Final[int] = 40
DEFAULT_MAX_CONSECUTIVE_ERRORS_PER_REQUEST: Final[int] = 3
Additionally, tool constraints enforce minimum values from `_tools.py:299-302`:
if max_invocations is not None and max_invocations < 1:
raise ValueError("max_invocations must be at least 1 or None.")
if max_invocation_exceptions is not None and max_invocation_exceptions < 1:
raise ValueError("max_invocation_exceptions must be at least 1 or None.")
Setting `max_invocations=None` allows unlimited invocations. Setting it to 0 raises a `ValueError`.