// Copyright (c) Microsoft. All rights reserved. using System; using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.AI; using Microsoft.Shared.DiagnosticIds; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI; /// /// Provides optional parameters and configuration settings for controlling agent run behavior. /// /// /// /// Implementations of may provide subclasses of with additional options specific to that agent type. /// /// public class AgentRunOptions { /// /// Initializes a new instance of the class. /// public AgentRunOptions() { } /// /// Initializes a new instance of the class by copying values from the specified options. /// /// The options instance from which to copy values. /// is . protected AgentRunOptions(AgentRunOptions options) { _ = Throw.IfNull(options); this.ContinuationToken = options.ContinuationToken; this.AllowBackgroundResponses = options.AllowBackgroundResponses; this.AdditionalProperties = options.AdditionalProperties?.Clone(); this.ResponseFormat = options.ResponseFormat; } /// /// Gets or sets the continuation token for resuming and getting the result of the agent response identified by this token. /// /// /// This property is used for background responses that can be activated via the /// property if the implementation supports them. /// Streamed background responses, such as those returned by default by /// can be resumed if interrupted. This means that a continuation token obtained from the /// of an update just before the interruption occurred can be passed to this property to resume the stream from the point of interruption. /// Non-streamed background responses, such as those returned by , /// can be polled for completion by obtaining the token from the property /// and passing it via this property on subsequent calls to . /// [Experimental(DiagnosticIds.Experiments.AIResponseContinuations)] public ResponseContinuationToken? ContinuationToken { get; set; } /// /// Gets or sets a value indicating whether the background responses are allowed. /// /// /// /// Background responses allow running long-running operations or tasks asynchronously in the background that can be resumed by streaming APIs /// and polled for completion by non-streaming APIs. /// /// /// When this property is set to true, non-streaming APIs may start a background operation and return an initial /// response with a continuation token. Subsequent calls to the same API should be made in a polling manner with /// the continuation token to get the final result of the operation. /// /// /// When this property is set to true, streaming APIs may also start a background operation and begin streaming /// response updates until the operation is completed. If the streaming connection is interrupted, the /// continuation token obtained from the last update that has one should be supplied to a subsequent call to the same streaming API /// to resume the stream from the point of interruption and continue receiving updates until the operation is completed. /// /// /// This property only takes effect if the implementation it's used with supports background responses. /// If the implementation does not support background responses, this property will be ignored. /// /// public bool? AllowBackgroundResponses { get; set; } /// /// Gets or sets additional properties associated with these options. /// /// /// An containing custom properties, /// or if no additional properties are present. /// /// /// Additional properties provide a way to include custom metadata or provider-specific /// information that doesn't fit into the standard options schema. This is useful for /// preserving implementation-specific details or extending the options with custom data. /// public AdditionalPropertiesDictionary? AdditionalProperties { get; set; } /// /// Gets or sets the response format. /// /// /// If , no response format is specified and the agent will use its default. /// This property can be set to to specify that the response should be unstructured text, /// to to specify that the response should be structured JSON data, or /// an instance of constructed with a specific JSON schema to request that the /// response be structured JSON data according to that schema. It is up to the agent implementation if or how /// to honor the request. If the agent implementation doesn't recognize the specific kind of , /// it can be ignored. /// public ChatResponseFormat? ResponseFormat { get; set; } /// /// Produces a clone of the current instance. /// /// /// A clone of the current instance. /// /// /// /// The clone will have the same values for all properties as the original instance. Any collections, like , /// are shallow-cloned, meaning a new collection instance is created, but any references contained by the collections are shared with the original. /// /// /// Derived types should override to return an instance of the derived type. /// /// public virtual AgentRunOptions Clone() => new(this); }