-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathWorkflowFactory.cs
More file actions
50 lines (41 loc) · 1.84 KB
/
WorkflowFactory.cs
File metadata and controls
50 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft. All rights reserved.
using Azure.Identity;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Declarative;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
internal sealed class WorkflowFactory(string workflowFile, Uri foundryEndpoint)
{
public IList<AIFunction> Functions { get; init; } = [];
public IConfiguration? Configuration { get; init; }
// Assign to continue an existing conversation
public string? ConversationId { get; init; }
// Assign to enable logging
public ILoggerFactory LoggerFactory { get; init; } = NullLoggerFactory.Instance;
/// <summary>
/// Create the workflow from the declarative YAML. Includes definition of the
/// <see cref="DeclarativeWorkflowOptions" /> and the associated <see cref="WorkflowAgentProvider"/>.
/// </summary>
public Workflow CreateWorkflow()
{
// Create the agent provider that will service agent requests within the workflow.
AzureAgentProvider agentProvider = new(foundryEndpoint, new AzureCliCredential())
{
// Functions included here will be auto-executed by the framework.
Functions = this.Functions
};
// Define the workflow options.
DeclarativeWorkflowOptions options =
new(agentProvider)
{
Configuration = this.Configuration,
ConversationId = this.ConversationId,
LoggerFactory = this.LoggerFactory,
};
string workflowPath = Path.Combine(AppContext.BaseDirectory, workflowFile);
// Use DeclarativeWorkflowBuilder to build a workflow based on a YAML file.
return DeclarativeWorkflowBuilder.Build<string>(workflowPath, options);
}
}