Skip to content

Commit 13bc5ea

Browse files
authored
Merge branch 'main' into main
2 parents 5cf337b + f7fdfcd commit 13bc5ea

288 files changed

Lines changed: 7391 additions & 4323 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dotnet/nuget/nuget-package.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<Project>
22
<PropertyGroup>
33
<!-- Central version prefix - applies to all nuget packages. -->
4-
<VersionPrefix>1.63.0</VersionPrefix>
4+
<VersionPrefix>1.64.0</VersionPrefix>
55
<PackageVersion Condition="'$(VersionSuffix)' != ''">$(VersionPrefix)-$(VersionSuffix)</PackageVersion>
66
<PackageVersion Condition="'$(VersionSuffix)' == ''">$(VersionPrefix)</PackageVersion>
77

88
<Configurations>Debug;Release;Publish</Configurations>
99
<IsPackable>true</IsPackable>
1010

1111
<!-- Package validation. Baseline Version should be the latest version available on NuGet. -->
12-
<PackageValidationBaselineVersion>1.62.0</PackageValidationBaselineVersion>
12+
<PackageValidationBaselineVersion>1.63.0</PackageValidationBaselineVersion>
1313
<!-- Validate assembly attributes only for Publish builds -->
1414
<NoWarn Condition="'$(Configuration)' != 'Publish'">$(NoWarn);CP0003</NoWarn>
1515
<!-- Do not validate reference assemblies -->

dotnet/samples/Concepts/PromptTemplates/HandlebarsPrompts.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
using System.Web;
34
using Microsoft.SemanticKernel;
45
using Microsoft.SemanticKernel.PromptTemplates.Handlebars;
56
using Resources;
@@ -43,14 +44,15 @@ Make sure to reference the customer by name response.
4344
""";
4445

4546
// Input data for the prompt rendering and execution
47+
// Performing manual encoding for each property for safe content rendering
4648
var arguments = new KernelArguments()
4749
{
4850
{ "customer", new
4951
{
50-
firstName = "John",
51-
lastName = "Doe",
52-
age = 30,
53-
membership = "Gold",
52+
firstName = HttpUtility.HtmlEncode("John"),
53+
lastName = HttpUtility.HtmlEncode("Doe"),
54+
age = HttpUtility.HtmlEncode(30),
55+
membership = HttpUtility.HtmlEncode("Gold"),
5456
}
5557
},
5658
{ "history", new[]
@@ -67,6 +69,14 @@ Make sure to reference the customer by name response.
6769
Template = template,
6870
TemplateFormat = "handlebars",
6971
Name = "ContosoChatPrompt",
72+
InputVariables = new()
73+
{
74+
// Set AllowDangerouslySetContent to 'true' only if arguments do not contain harmful content.
75+
// Consider encoding for each argument to prevent prompt injection attacks.
76+
// If argument value is string, encoding will be performed automatically.
77+
new() { Name = "customer", AllowDangerouslySetContent = true },
78+
new() { Name = "history", AllowDangerouslySetContent = true },
79+
}
7080
};
7181

7282
// Render the prompt
@@ -93,18 +103,26 @@ public async Task LoadingHandlebarsPromptTemplatesAsync()
93103
var handlebarsPromptYaml = EmbeddedResource.Read("HandlebarsPrompt.yaml");
94104

95105
// Create the prompt function from the YAML resource
96-
var templateFactory = new HandlebarsPromptTemplateFactory();
106+
var templateFactory = new HandlebarsPromptTemplateFactory()
107+
{
108+
// Set AllowDangerouslySetContent to 'true' only if arguments do not contain harmful content.
109+
// Consider encoding for each argument to prevent prompt injection attacks.
110+
// If argument value is string, encoding will be performed automatically.
111+
AllowDangerouslySetContent = true
112+
};
113+
97114
var function = kernel.CreateFunctionFromPromptYaml(handlebarsPromptYaml, templateFactory);
98115

99116
// Input data for the prompt rendering and execution
117+
// Performing manual encoding for each property for safe content rendering
100118
var arguments = new KernelArguments()
101119
{
102120
{ "customer", new
103121
{
104-
firstName = "John",
105-
lastName = "Doe",
106-
age = 30,
107-
membership = "Gold",
122+
firstName = HttpUtility.HtmlEncode("John"),
123+
lastName = HttpUtility.HtmlEncode("Doe"),
124+
age = HttpUtility.HtmlEncode(30),
125+
membership = HttpUtility.HtmlEncode("Gold"),
108126
}
109127
},
110128
{ "history", new[]

dotnet/samples/Concepts/PromptTemplates/LiquidPrompts.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
using System.Web;
34
using Microsoft.SemanticKernel;
45
using Microsoft.SemanticKernel.PromptTemplates.Liquid;
56
using Resources;
@@ -43,14 +44,15 @@ Make sure to reference the customer by name response.
4344
""";
4445

4546
// Input data for the prompt rendering and execution
47+
// Performing manual encoding for each property for safe content rendering
4648
var arguments = new KernelArguments()
4749
{
4850
{ "customer", new
4951
{
50-
firstName = "John",
51-
lastName = "Doe",
52+
firstName = HttpUtility.HtmlEncode("John"),
53+
lastName = HttpUtility.HtmlEncode("Doe"),
5254
age = 30,
53-
membership = "Gold",
55+
membership = HttpUtility.HtmlEncode("Gold"),
5456
}
5557
},
5658
{ "history", new[]
@@ -67,6 +69,14 @@ Make sure to reference the customer by name response.
6769
Template = template,
6870
TemplateFormat = "liquid",
6971
Name = "ContosoChatPrompt",
72+
InputVariables = new()
73+
{
74+
// Set AllowDangerouslySetContent to 'true' only if arguments do not contain harmful content.
75+
// Consider encoding for each argument to prevent prompt injection attacks.
76+
// If argument value is string, encoding will be performed automatically.
77+
new() { Name = "customer", AllowDangerouslySetContent = true },
78+
new() { Name = "history", AllowDangerouslySetContent = true },
79+
}
7080
};
7181

7282
// Render the prompt
@@ -93,18 +103,26 @@ public async Task LoadingHandlebarsPromptTemplatesAsync()
93103
var liquidPromptYaml = EmbeddedResource.Read("LiquidPrompt.yaml");
94104

95105
// Create the prompt function from the YAML resource
96-
var templateFactory = new LiquidPromptTemplateFactory();
106+
var templateFactory = new LiquidPromptTemplateFactory()
107+
{
108+
// Set AllowDangerouslySetContent to 'true' only if arguments do not contain harmful content.
109+
// Consider encoding for each argument to prevent prompt injection attacks.
110+
// If argument value is string, encoding will be performed automatically.
111+
AllowDangerouslySetContent = true
112+
};
113+
97114
var function = kernel.CreateFunctionFromPromptYaml(liquidPromptYaml, templateFactory);
98115

99116
// Input data for the prompt rendering and execution
117+
// Performing manual encoding for each property for safe content rendering
100118
var arguments = new KernelArguments()
101119
{
102120
{ "customer", new
103121
{
104-
firstName = "John",
105-
lastName = "Doe",
122+
firstName = HttpUtility.HtmlEncode("John"),
123+
lastName = HttpUtility.HtmlEncode("Doe"),
106124
age = 30,
107-
membership = "Gold",
125+
membership = HttpUtility.HtmlEncode("Gold"),
108126
}
109127
},
110128
{ "history", new[]

dotnet/samples/Demos/ProcessFrameworkWithSignalR/src/ProcessFramework.Aspire.SignalR.ReactFrontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
"globals": "^15.15.0",
3434
"typescript": "~5.7.2",
3535
"typescript-eslint": "^8.24.1",
36-
"vite": "^6.2.0"
36+
"vite": "^6.2.7"
3737
}
3838
}

dotnet/samples/Demos/ProcessFrameworkWithSignalR/src/ProcessFramework.Aspire.SignalR.ReactFrontend/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,10 +3466,10 @@ vfile@^6.0.0:
34663466
"@types/unist" "^3.0.0"
34673467
vfile-message "^4.0.0"
34683468

3469-
vite@^6.2.0:
3470-
version "6.2.5"
3471-
resolved "https://registry.yarnpkg.com/vite/-/vite-6.2.5.tgz#d093b5fe8eb96e594761584a966ab13f24457820"
3472-
integrity sha512-j023J/hCAa4pRIUH6J9HemwYfjB5llR2Ps0CWeikOtdR8+pAURAk0DoJC5/mm9kd+UgdnIy7d6HE4EAvlYhPhA==
3469+
vite@^6.2.7:
3470+
version "6.2.7"
3471+
resolved "https://registry.yarnpkg.com/vite/-/vite-6.2.7.tgz#699fb6e4b3e65d749480e0087cdbe3f3f0de00fa"
3472+
integrity sha512-qg3LkeuinTrZoJHHF94coSaTfIPyBYoywp+ys4qu20oSJFbKMYoIJo0FWJT9q6Vp49l6z9IsJRbHdcGtiKbGoQ==
34733473
dependencies:
34743474
esbuild "^0.25.0"
34753475
postcss "^8.5.3"

dotnet/samples/Demos/TelemetryWithAppInsights/Program.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Microsoft.Extensions.DependencyInjection;
1313
using Microsoft.Extensions.Logging;
1414
using Microsoft.SemanticKernel;
15+
using Microsoft.SemanticKernel.Agents;
16+
using Microsoft.SemanticKernel.ChatCompletion;
1517
using Microsoft.SemanticKernel.Connectors.AzureAIInference;
1618
using Microsoft.SemanticKernel.Connectors.Google;
1719
using Microsoft.SemanticKernel.Connectors.HuggingFace;
@@ -102,6 +104,13 @@ public static async Task Main()
102104
await RunAzureOpenAIToolCallsAsync(kernel);
103105
Console.WriteLine();
104106
}
107+
108+
Console.WriteLine("Run ChatCompletion Agent.");
109+
using (var _ = s_activitySource.StartActivity("Agent"))
110+
{
111+
await RunChatCompletionAgentAsync(kernel);
112+
Console.WriteLine();
113+
}
105114
}
106115

107116
#region Private
@@ -307,6 +316,40 @@ private static async Task RunAutoToolCallAsync(Kernel kernel)
307316
}
308317
#endregion
309318

319+
#region Agent
320+
321+
private static async Task RunChatCompletionAgentAsync(Kernel kernel)
322+
{
323+
Console.WriteLine("============= ChatCompletion Agent =============");
324+
325+
if (TestConfiguration.AzureOpenAI is null)
326+
{
327+
Console.WriteLine("Azure OpenAI is not configured. Skipping.");
328+
return;
329+
}
330+
331+
SetTargetService(kernel, AzureOpenAIServiceKey);
332+
333+
// Define the agent
334+
ChatCompletionAgent agent =
335+
new()
336+
{
337+
Name = "TestAgent",
338+
Instructions = "You are a helpful assistant.",
339+
Kernel = kernel
340+
};
341+
342+
ChatMessageContent message = new(AuthorRole.User, "Write a poem about John Doe.");
343+
Console.WriteLine($"User: {message.Content}");
344+
345+
await foreach (AgentResponseItem<ChatMessageContent> response in agent.InvokeAsync(message))
346+
{
347+
Console.WriteLine($"Agent: {response.Message.Content}");
348+
}
349+
}
350+
351+
#endregion
352+
310353
private static Kernel GetKernel(ILoggerFactory loggerFactory)
311354
{
312355
var folder = RepoFiles.SamplePluginsPath();

dotnet/samples/Demos/TelemetryWithAppInsights/TelemetryWithAppInsights.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<ProjectReference Include="..\..\..\src\Connectors\Connectors.Google\Connectors.Google.csproj" />
2626
<ProjectReference Include="..\..\..\src\Connectors\Connectors.HuggingFace\Connectors.HuggingFace.csproj" />
2727
<ProjectReference Include="..\..\..\src\SemanticKernel.Core\SemanticKernel.Core.csproj" />
28+
<ProjectReference Include="..\..\..\src\Agents\Core\Agents.Core.csproj" />
2829
<ProjectReference Include="..\..\..\src\Plugins\Plugins.Core\Plugins.Core.csproj" />
2930
<ProjectReference Include="..\..\..\src\Plugins\Plugins.Web\Plugins.Web.csproj" />
3031
</ItemGroup>

dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step01_OpenAIResponseAgent.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,33 @@ public async Task UseOpenAIResponseAgentWithThreadedConversationStreamingAsync()
111111
agentThread = await WriteAgentStreamMessageAsync(responseItems);
112112
}
113113
}
114+
115+
[Fact]
116+
public async Task UseOpenAIResponseAgentWithImageContentAsync()
117+
{
118+
// Define the agent
119+
OpenAIResponseAgent agent = new(this.Client)
120+
{
121+
Name = "ResponseAgent",
122+
Instructions = "Provide a detailed description including the weather conditions.",
123+
};
124+
125+
ICollection<ChatMessageContent> messages =
126+
[
127+
new ChatMessageContent(
128+
AuthorRole.User,
129+
items: [
130+
new TextContent("What is in this image?"),
131+
new ImageContent(new Uri("https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"))
132+
]
133+
),
134+
];
135+
136+
// Invoke the agent and output the response
137+
var responseItems = agent.InvokeAsync(messages);
138+
await foreach (ChatMessageContent responseItem in responseItems)
139+
{
140+
WriteAgentChatMessage(responseItem);
141+
}
142+
}
114143
}

dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step03_OpenAIResponseAgent_ReasoningModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.SemanticKernel;
33
using Microsoft.SemanticKernel.Agents.OpenAI;
44
using OpenAI.Responses;
5+
using Plugins;
56

67
namespace GettingStarted.OpenAIResponseAgents;
78

@@ -80,4 +81,26 @@ exceed 80 columns
8081
WriteAgentChatMessage(responseItem);
8182
}
8283
}
84+
85+
[Fact]
86+
public async Task UseOpenAIResponseAgentWithAReasoningModelAndToolsAsync()
87+
{
88+
// Define the agent
89+
OpenAIResponseAgent agent = new(this.Client)
90+
{
91+
Name = "ResponseAgent",
92+
Instructions = "Answer all queries with a detailed response.",
93+
};
94+
95+
// Create a plugin that defines the tools to be used by the agent.
96+
KernelPlugin plugin = KernelPluginFactory.CreateFromType<MenuPlugin>();
97+
agent.Kernel.Plugins.Add(plugin);
98+
99+
// Invoke the agent and output the response
100+
var responseItems = agent.InvokeAsync("What is the best value healthy meal?");
101+
await foreach (ChatMessageContent responseItem in responseItems)
102+
{
103+
WriteAgentChatMessage(responseItem);
104+
}
105+
}
83106
}

dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public Step10_MultiAgent_Declarative(ITestOutputHelper output) : base(output)
106106
this._kernel = builder.Build();
107107

108108
this._kernelAgentFactory =
109-
new AggregatorKernelAgentFactory(
109+
new AggregatorAgentFactory(
110110
new ChatCompletionAgentFactory(),
111111
new OpenAIAssistantAgentFactory(),
112112
new AzureAIAgentFactory());

0 commit comments

Comments
 (0)