forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAgentDefinitionYaml.cs
53 lines (46 loc) · 1.88 KB
/
AgentDefinitionYaml.cs
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
51
52
53
// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics.CodeAnalysis;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace Microsoft.SemanticKernel.Agents;
/// <summary>
/// Helper methods for creating <see cref="AgentDefinition"/> from YAML.
/// </summary>
[Experimental("SKEXP0110")]
public static class AgentDefinitionYaml
{
/// <summary>
/// Convert the given YAML text to a <see cref="AgentDefinition"/> model.
/// </summary>
/// <param name="text">YAML representation of the <see cref="AgentDefinition"/> to use to create the prompt function.</param>
public static AgentDefinition FromYaml(string text)
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.WithTypeConverter(new PromptExecutionSettingsTypeConverter())
.WithTypeConverter(new ModelConfigurationTypeConverter())
.WithTypeConverter(new AgentToolDefinitionTypeConverter())
.WithTypeConverter(new AgentMetadataTypeConverter())
.Build();
var agentDefinition = deserializer.Deserialize<AgentDefinition>(text);
return agentDefinition.UpdateInputNames();
}
#region private
/// <summary>
/// Update the input names to match dictionary keys in this <see cref="AgentDefinition"/> instance.
/// </summary>
/// <param name="agentDefinition">AgentDefinition instance to update.</param>
private static AgentDefinition UpdateInputNames(this AgentDefinition agentDefinition)
{
Verify.NotNull(agentDefinition);
if (agentDefinition?.Inputs is not null)
{
foreach (var keyValuePair in agentDefinition.Inputs)
{
keyValuePair.Value.Name = keyValuePair.Key;
}
}
return agentDefinition!;
}
#endregion
}