// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json.Serialization;
using Microsoft.Extensions.AI;
namespace Microsoft.Agents.AI.DurableTask;
///
/// Represents a request to run an agent with a specific message and configuration.
///
public record RunRequest
{
///
/// Gets the list of chat messages to send to the agent (for multi-message requests).
///
public IList Messages { get; init; } = [];
///
/// Gets the optional response format for the agent's response.
///
public ChatResponseFormat? ResponseFormat { get; init; }
///
/// Gets whether to enable tool calls for this request.
///
public bool EnableToolCalls { get; init; } = true;
///
/// Gets the collection of tool names to enable. If not specified, all tools are enabled.
///
public IList? EnableToolNames { get; init; }
///
/// Gets or sets the correlation ID for correlating this request with its response.
///
[JsonInclude]
internal string CorrelationId { get; set; } = Guid.NewGuid().ToString("N");
///
/// Gets or sets the ID of the orchestration that initiated this request (if any).
///
[JsonInclude]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
internal string? OrchestrationId { get; set; }
///
/// Initializes a new instance of the class for a single message.
///
/// The message to send to the agent.
/// The role of the message sender (User or System).
/// Optional response format for the agent's response.
/// Whether to enable tool calls for this request.
/// Optional collection of tool names to enable. If not specified, all tools are enabled.
public RunRequest(
string message,
ChatRole? role = null,
ChatResponseFormat? responseFormat = null,
bool enableToolCalls = true,
IList? enableToolNames = null)
: this([new ChatMessage(role ?? ChatRole.User, message) { CreatedAt = DateTimeOffset.UtcNow }], responseFormat, enableToolCalls, enableToolNames)
{
}
///
/// Initializes a new instance of the class for multiple messages.
///
/// The list of chat messages to send to the agent.
/// Optional response format for the agent's response.
/// Whether to enable tool calls for this request.
/// Optional collection of tool names to enable. If not specified, all tools are enabled.
[JsonConstructor]
public RunRequest(
IList messages,
ChatResponseFormat? responseFormat = null,
bool enableToolCalls = true,
IList? enableToolNames = null)
{
this.Messages = messages;
this.ResponseFormat = responseFormat;
this.EnableToolCalls = enableToolCalls;
this.EnableToolNames = enableToolNames;
}
}