mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* add support for background responses * Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunResponseUpdate.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix broken link * fix xml comments and background responses properties override funcitonity * change ai model provider * use Run{Streaming}Async overloads that don't require messages * stop using m: prefix in cref attribute of <see/> element. * reject input messages provided with continuation token + don't extract messages from message store and context provide if continuation token is provided * use agent thread for background-responses sample * require agent thread for background responses * Update dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> * Update dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> * remove CA1200 * Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunOptions.cs Co-authored-by: westey <164392973+westey-m@users.noreply.github.com> * Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunResponse.cs Co-authored-by: westey <164392973+westey-m@users.noreply.github.com> * Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunResponse.cs Co-authored-by: westey <164392973+westey-m@users.noreply.github.com> * address pr review comments * Update dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs Co-authored-by: westey <164392973+westey-m@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
78 lines
4.1 KiB
C#
78 lines
4.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using Microsoft.Shared.Diagnostics;
|
|
|
|
namespace Microsoft.Agents.AI;
|
|
|
|
/// <summary>
|
|
/// Provides optional parameters and configuration settings for controlling agent run behavior.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Implementations of <see cref="AIAgent"/> may provide subclasses of <see cref="AgentRunOptions"/> with additional options specific to that agent type.
|
|
/// </para>
|
|
/// </remarks>
|
|
public class AgentRunOptions
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AgentRunOptions"/> class.
|
|
/// </summary>
|
|
public AgentRunOptions()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AgentRunOptions"/> class by copying values from the specified options.
|
|
/// </summary>
|
|
/// <param name="options">The options instance from which to copy values.</param>
|
|
/// <exception cref="ArgumentNullException"><paramref name="options"/> is <see langword="null"/>.</exception>
|
|
public AgentRunOptions(AgentRunOptions options)
|
|
{
|
|
_ = Throw.IfNull(options);
|
|
this.ContinuationToken = options.ContinuationToken;
|
|
this.AllowBackgroundResponses = options.AllowBackgroundResponses;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the continuation token for resuming and getting the result of the agent response identified by this token.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This property is used for background responses that can be activated via the <see cref="AllowBackgroundResponses"/>
|
|
/// property if the <see cref="AIAgent"/> implementation supports them.
|
|
/// Streamed background responses, such as those returned by default by <see cref="AIAgent.RunStreamingAsync(AgentThread?, AgentRunOptions?, System.Threading.CancellationToken)"/>
|
|
/// can be resumed if interrupted. This means that a continuation token obtained from the <see cref="AgentRunResponseUpdate.ContinuationToken"/>
|
|
/// 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 <see cref="AIAgent.RunAsync(AgentThread?, AgentRunOptions?, System.Threading.CancellationToken)"/>,
|
|
/// can be polled for completion by obtaining the token from the <see cref="AgentRunResponse.ContinuationToken"/> property
|
|
/// and passing it via this property on subsequent calls to <see cref="AIAgent.RunAsync(AgentThread?, AgentRunOptions?, System.Threading.CancellationToken)"/>.
|
|
/// </remarks>
|
|
public object? ContinuationToken { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether the background responses are allowed.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
public bool? AllowBackgroundResponses { get; set; }
|
|
}
|