Skip to content

Commit 159a661

Browse files
authored
Merge pull request #134 from microsoft/users/mbarbour/AddSkillSample
Adding in EchoAgentSkill Sample and updating EchoAgent(EmptyAgent)
2 parents d4b26c8 + 6fc5669 commit 159a661

16 files changed

+1012
-85
lines changed

samples/Samples.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.13.35818.85
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EchoBot", "basic\empty-agent\dotnet\EchoBot.csproj", "{B1FC20C1-9900-FAC4-B8E6-223888633020}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmptyAgent", "basic\empty-agent\dotnet\EmptyAgent.csproj", "{B1FC20C1-9900-FAC4-B8E6-223888633020}"
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopilotStudioClient", "basic\copilotstudio-client\dotnet\CopilotStudioClient.csproj", "{CA8B675F-CC17-A991-7AC6-7A9E3E3BB97D}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopilotStudioEchoSkill", "complex\copilotstudio-skill\dotnet\CopilotStudioEchoSkill.csproj", "{8B83539F-571B-257A-2247-035F394C4EC7}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{CA8B675F-CC17-A991-7AC6-7A9E3E3BB97D}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{CA8B675F-CC17-A991-7AC6-7A9E3E3BB97D}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{CA8B675F-CC17-A991-7AC6-7A9E3E3BB97D}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{8B83539F-571B-257A-2247-035F394C4EC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{8B83539F-571B-257A-2247-035F394C4EC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{8B83539F-571B-257A-2247-035F394C4EC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{8B83539F-571B-257A-2247-035F394C4EC7}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

samples/basic/empty-agent/dotnet/AspNetExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static class AspNetExtensions
5959
/// `OpenIdMetadataUrl` can be omitted. In which case default values in combination with `IsGov` is used.
6060
/// `AzureBotServiceTokenHandling` defaults to true and should always be true until Azure Bot Service sends Entra ID token.
6161
/// </remarks>
62-
public static void AddBotAspNetAuthentication(this IServiceCollection services, IConfiguration configuration, string tokenValidationSectionName = "TokenValidation", ILogger logger = null)
62+
public static void AddAgentAspNetAuthentication(this IServiceCollection services, IConfiguration configuration, string tokenValidationSectionName = "TokenValidation", ILogger logger = null)
6363
{
6464
IConfigurationSection tokenValidationSection = configuration.GetSection(tokenValidationSectionName);
6565
List<string> validTokenIssuers = tokenValidationSection.GetSection("ValidIssuers").Get<List<string>>();

samples/basic/empty-agent/dotnet/BotController.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

samples/basic/empty-agent/dotnet/ConversationStateExtensions.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
4-
<LangVersion>latest</LangVersion>
5-
</PropertyGroup>
6-
<ItemGroup>
7-
<PackageReference Include="Microsoft.Agents.Authentication.Msal" Version="0.2.146-alpha" />
8-
<PackageReference Include="Microsoft.Agents.Hosting.AspNetCore" Version="0.2.146-alpha" />
9-
</ItemGroup>
10-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.Agents.Authentication.Msal" Version="0.2.*-*" />
8+
<PackageReference Include="Microsoft.Agents.Hosting.AspNetCore" Version="0.2.*-*" />
9+
</ItemGroup>
10+
</Project>

samples/basic/empty-agent/dotnet/MyBot.cs renamed to samples/basic/empty-agent/dotnet/MyAgent.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using Microsoft.Agents.BotBuilder;
5-
using Microsoft.Agents.BotBuilder.App;
6-
using Microsoft.Agents.BotBuilder.State;
4+
using Microsoft.Agents.Builder;
5+
using Microsoft.Agents.Builder.App;
6+
using Microsoft.Agents.Builder.State;
77
using Microsoft.Agents.Core.Models;
88
using System.Threading.Tasks;
99
using System.Threading;
1010

1111
namespace EchoBot;
1212

13-
public class MyBot : AgentApplication
13+
public class MyAgent : AgentApplication
1414
{
15-
public MyBot(AgentApplicationOptions options) : base(options)
15+
public MyAgent(AgentApplicationOptions options) : base(options)
1616
{
1717
OnConversationUpdate(ConversationUpdateEvents.MembersAdded, WelcomeMessageAsync);
1818

@@ -33,9 +33,6 @@ protected async Task WelcomeMessageAsync(ITurnContext turnContext, ITurnState tu
3333

3434
protected async Task OnMessageAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
3535
{
36-
// Increment count state.
37-
int count = turnState.Conversation.IncrementMessageCount();
38-
39-
await turnContext.SendActivityAsync($"[{count}] you said: {turnContext.Activity.Text}", cancellationToken: cancellationToken);
36+
await turnContext.SendActivityAsync($"You said: {turnContext.Activity.Text}", cancellationToken: cancellationToken);
4037
}
4138
}

samples/basic/empty-agent/dotnet/Program.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
// Licensed under the MIT License.
33

44
using EchoBot;
5-
using Microsoft.Agents.BotBuilder.App;
6-
using Microsoft.Agents.BotBuilder.State;
5+
using Microsoft.Agents.Builder;
76
using Microsoft.Agents.Hosting.AspNetCore;
87
using Microsoft.Agents.Samples;
98
using Microsoft.Agents.Storage;
109
using Microsoft.AspNetCore.Builder;
10+
using Microsoft.AspNetCore.Http;
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Hosting;
1313
using Microsoft.Extensions.Logging;
14+
using System.Threading;
1415

1516
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
1617

@@ -19,33 +20,39 @@
1920
builder.Logging.AddConsole();
2021

2122
// Add AspNet token validation
22-
builder.Services.AddBotAspNetAuthentication(builder.Configuration);
23+
builder.Services.AddAgentAspNetAuthentication(builder.Configuration);
2324

24-
// Add ApplicationOptions
25-
builder.Services.AddTransient(sp =>
26-
{
27-
return new AgentApplicationOptions()
28-
{
29-
StartTypingTimer = false,
30-
TurnStateFactory = () => new TurnState(sp.GetService<IStorage>())
31-
};
32-
});
25+
// Register IStorage. For development, MemoryStorage is suitable.
26+
// For production Agents, persisted storage should be used so
27+
// that state survives Agent restarts, and operate correctly
28+
// in a cluster of Agent instances.
29+
builder.Services.AddSingleton<IStorage, MemoryStorage>();
30+
31+
// Add AgentApplicationOptions from config.
32+
builder.AddAgentApplicationOptions();
3333

3434
// Add the bot (which is transient)
35-
builder.AddBot<MyBot>();
35+
builder.AddAgent<MyAgent>();
3636

3737

3838
WebApplication app = builder.Build();
3939

40+
app.UseRouting();
41+
var root = app.MapPost("/api/messages", async (HttpRequest request, HttpResponse response, IAgentHttpAdapter adapter, IAgent agent, CancellationToken cancellationToken) =>
42+
{
43+
await adapter.ProcessAsync(request, response, agent, cancellationToken);
44+
});
45+
4046
if (app.Environment.IsDevelopment())
4147
{
42-
app.MapGet("/", () => "Microsoft Agents SDK Sample");
48+
root.AllowAnonymous();
4349
app.UseDeveloperExceptionPage();
44-
app.MapControllers().AllowAnonymous();
45-
}
46-
else
47-
{
48-
app.MapControllers();
50+
app.MapGet("/", () => "Microsoft Agents SDK Sample");
4951
}
52+
53+
// Hardcoded for brevity and ease of testing.
54+
// In production, this should be set in configuration.
55+
app.Urls.Add($"http://localhost:3978");
56+
5057
app.Run();
5158

samples/basic/empty-agent/dotnet/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"LogLevel": {
3737
"Default": "Information",
3838
"Microsoft.AspNetCore": "Warning",
39-
"Microsoft.Copilot": "Warning",
39+
"Microsoft.Agents": "Warning",
4040
"Microsoft.Hosting.Lifetime": "Information"
4141
}
4242
}

0 commit comments

Comments
 (0)