mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
17b4dfab14
* Propagate orchestration ID (if any). * Add integration test for orchestration ID in entity state. * Update schema. * Fixup formatting issues. * Fix more formatting issues.
58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace Microsoft.Agents.AI.DurableTask.State;
|
|
|
|
/// <summary>
|
|
/// Represents a user or system request entry in the durable agent state.
|
|
/// </summary>
|
|
internal sealed class DurableAgentStateRequest : DurableAgentStateEntry
|
|
{
|
|
/// <summary>
|
|
/// Gets the ID of the orchestration that initiated this request (if any).
|
|
/// </summary>
|
|
[JsonPropertyName("orchestrationId")]
|
|
public string? OrchestrationId { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the expected response type for this request (e.g. "json" or "text").
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If omitted, the expectation is that the agent will respond in plain text.
|
|
/// </remarks>
|
|
[JsonPropertyName("responseType")]
|
|
public string? ResponseType { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the expected response JSON schema for this request, if applicable.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This is only applicable when <see cref="ResponseType"/> is "json".
|
|
/// If omitted, no specific schema is expected.
|
|
/// </remarks>
|
|
[JsonPropertyName("responseSchema")]
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public JsonElement? ResponseSchema { get; init; }
|
|
|
|
/// <summary>
|
|
/// Creates a <see cref="DurableAgentStateRequest"/> from a <see cref="RunRequest"/>.
|
|
/// </summary>
|
|
/// <param name="request">The <see cref="RunRequest"/> to convert.</param>
|
|
/// <returns>A <see cref="DurableAgentStateRequest"/> representing the original request.</returns>
|
|
public static DurableAgentStateRequest FromRunRequest(RunRequest request)
|
|
{
|
|
return new DurableAgentStateRequest()
|
|
{
|
|
CorrelationId = request.CorrelationId,
|
|
OrchestrationId = request.OrchestrationId,
|
|
Messages = request.Messages.Select(DurableAgentStateMessage.FromChatMessage).ToList(),
|
|
CreatedAt = request.Messages.Min(m => m.CreatedAt) ?? DateTimeOffset.UtcNow,
|
|
ResponseType = request.ResponseFormat is ChatResponseFormatJson ? "json" : "text",
|
|
ResponseSchema = (request.ResponseFormat as ChatResponseFormatJson)?.Schema
|
|
};
|
|
}
|
|
}
|