forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAgentDefinitionExtensions.cs
61 lines (53 loc) · 2.19 KB
/
AgentDefinitionExtensions.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
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace Microsoft.SemanticKernel.Agents;
/// <summary>
/// Provides extension methods for <see cref="AgentDefinition"/>.
/// </summary>
[Experimental("SKEXP0110")]
public static class AgentDefinitionExtensions
{
/// <summary>
/// Creates default <see cref="KernelArguments"/> from the <see cref="AgentDefinition"/>.
/// </summary>
/// <param name="agentDefinition">Agen definition to retrieve default arguments from.</param>
public static KernelArguments GetDefaultKernelArguments(this AgentDefinition agentDefinition)
{
Verify.NotNull(agentDefinition);
var arguments = new KernelArguments(agentDefinition?.Model?.Options);
if (agentDefinition?.Inputs is not null)
{
// Add default arguments for the agent
foreach (var keyValuePair in agentDefinition.Inputs)
{
if (keyValuePair.Value.Default is not null)
{
arguments.Add(keyValuePair.Key, keyValuePair.Value.Default);
}
}
}
return arguments;
}
/// <summary>
/// Get the first tool definition of the specified type.
/// </summary>
/// <param name="agentDefinition">Agent definition to retrieve the first tool from.</param>
/// <param name="toolType">Tool type</param>
public static AgentToolDefinition? GetFirstToolDefinition(this AgentDefinition agentDefinition, string toolType)
{
Verify.NotNull(agentDefinition);
Verify.NotNull(toolType);
return agentDefinition.Tools?.FirstOrDefault(tool => tool.Type == toolType);
}
/// <summary>
/// Determines if the agent definition has a tool of the specified type.
/// </summary>
/// <param name="agentDefinition">Agent definition</param>
/// <param name="toolType">Tool type</param>
public static bool HasToolType(this AgentDefinition agentDefinition, string toolType)
{
Verify.NotNull(agentDefinition);
return agentDefinition.Tools?.Any(tool => tool?.Type?.Equals(toolType, System.StringComparison.Ordinal) ?? false) ?? false;
}
}