// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Immutable;
using System.Text.Json.Serialization;
using Microsoft.Extensions.AI;
namespace Microsoft.Agents.AI.DurableTask.State;
///
/// Durable agent state content representing a function call.
///
internal sealed class DurableAgentStateFunctionCallContent : DurableAgentStateContent
{
///
/// The function call arguments.
///
/// TODO: Consider ensuring that empty dictionaries are omitted from serialization.
[JsonPropertyName("arguments")]
public required IReadOnlyDictionary Arguments { get; init; } =
ImmutableDictionary.Empty;
///
/// Gets the function call identifier.
///
///
/// This is used to correlate this function call with its resulting
/// .
///
[JsonPropertyName("callId")]
public required string CallId { get; init; }
///
/// Gets the function name.
///
[JsonPropertyName("name")]
public required string Name { get; init; }
///
/// Creates a from a .
///
/// The to convert.
///
/// A representing the original content.
///
public static DurableAgentStateFunctionCallContent FromFunctionCallContent(FunctionCallContent content)
{
return new DurableAgentStateFunctionCallContent()
{
Arguments = content.Arguments?.ToImmutableDictionary() ?? ImmutableDictionary.Empty,
CallId = content.CallId,
Name = content.Name
};
}
///
public override AIContent ToAIContent()
{
return new FunctionCallContent(
this.CallId,
this.Name,
new Dictionary(this.Arguments));
}
}