HandoffWorkflowBuilderCore<TBuilder>.WithAutonomousMode Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Enables autonomous mode for the handoff workflow.
public TBuilder WithAutonomousMode(int? turnLimit = default, string? continuationPrompt = default, System.Collections.Generic.IEnumerable<Microsoft.Agents.AI.AIAgent>? agents = default, System.Collections.Generic.IReadOnlyDictionary<Microsoft.Agents.AI.AIAgent,int>? agentTurnLimits = default, System.Collections.Generic.IReadOnlyDictionary<Microsoft.Agents.AI.AIAgent,string>? agentContinuationPrompts = default);
member this.WithAutonomousMode : Nullable<int> * string * seq<Microsoft.Agents.AI.AIAgent> * System.Collections.Generic.IReadOnlyDictionary<Microsoft.Agents.AI.AIAgent, int> * System.Collections.Generic.IReadOnlyDictionary<Microsoft.Agents.AI.AIAgent, string> -> 'Builder
Public Function WithAutonomousMode (Optional turnLimit As Nullable(Of Integer) = Nothing, Optional continuationPrompt As String = Nothing, Optional agents As IEnumerable(Of AIAgent) = Nothing, Optional agentTurnLimits As IReadOnlyDictionary(Of AIAgent, Integer) = Nothing, Optional agentContinuationPrompts As IReadOnlyDictionary(Of AIAgent, String) = Nothing) As TBuilder
Parameters
The default maximum number of autonomous continuation iterations per agent per workflow
turn. Applies to agents not listed in agentTurnLimits. If
null, defaults to
Microsoft.Agents.AI.Workflows.Specialized.HandoffWorkflowBuilderDefaults.DefaultAutonomousTurnLimit (50).
- continuationPrompt
- String
The default user-role prompt fed to an agent on each autonomous continuation. Applies to
agents not listed in agentContinuationPrompts. If null,
defaults to Microsoft.Agents.AI.Workflows.Specialized.HandoffWorkflowBuilderDefaults.DefaultAutonomousContinuationPrompt.
- agents
- IEnumerable<AIAgent>
Optional allow-list restricting autonomous mode to a specific subset of agents. If
null or empty, autonomous mode is enabled for every participant.
Agents not in the allow-list always yield control back to the caller after a single
invocation (when they do not request a handoff).
- agentTurnLimits
- IReadOnlyDictionary<AIAgent,Int32>
Optional per-agent turn-limit overrides. Each entry's key is the agent and its value the
turn limit that overrides turnLimit for that agent. Agents not present
fall back to the default.
- agentContinuationPrompts
- IReadOnlyDictionary<AIAgent,String>
Optional per-agent continuation-prompt overrides. Each entry's key is the agent and its value the continuation prompt used for that agent. Agents not present fall back to the default.
Returns
The updated builder instance.
Remarks
In autonomous mode, an agent whose response does not include a handoff is invoked again with a continuation prompt, up to a configured turn limit. The autonomous loop for a given agent ends when the agent invokes a handoff tool, the configured termination condition fires, or the per-agent turn limit is reached — at which point the workflow yields control back to the caller.
Per-agent turn counting. Autonomous-turn counters are tracked independently per agent in the shared handoff state. A counter is incremented each time the End executor loops control back to its source agent, and reset to zero in three cases: (1) when that agent requests a handoff, (2) when its autonomous loop terminates (limit reached, termination fires, or autonomous mode disabled for that agent), and (3) at the start of every fresh user turn. As a consequence, if agent A loops twice and then hands off to B, A's counter resets to zero; should control later return to A within the same user turn, A starts a new autonomous run from zero.