// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
namespace Microsoft.Agents.AI.Workflows;
///
/// Provides extension methods for treating workflows as
///
public static class WorkflowHostingExtensions
{
///
/// Convert a workflow with the appropriate primary input type to an .
///
///
///
///
///
public static AIAgent AsAgent(this Workflow> workflow, string? id = null, string? name = null)
{
return new WorkflowHostAgent(workflow, id, name);
}
///
/// Convert a workflow with the appropriate primary input type to an .
///
///
///
///
///
public static async ValueTask AsAgentAsync(this Workflow workflow, string? id = null, string? name = null)
{
Workflow>? maybeTyped = await workflow.TryPromoteAsync>()
.ConfigureAwait(false);
if (maybeTyped is null)
{
throw new InvalidOperationException("Cannot host a workflow that does not accept List as an input");
}
return maybeTyped.AsAgent(id: id, name: name);
}
internal static FunctionCallContent ToFunctionCall(this ExternalRequest request)
{
Dictionary parameters = new()
{
{ "data", request.Data}
};
return new FunctionCallContent(request.RequestId, request.PortInfo.PortId, parameters);
}
}